Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOptionCollectionWidget Class Reference

Class providing a list of widgets with some addons such as separators, orientation or individual widget visibility. More...

#include <KisOptionCollectionWidget.h>

+ Inheritance diagram for KisOptionCollectionWidget:

Classes

struct  Private
 

Public Member Functions

void appendWidget (const QString &id, QWidget *widget)
 Insert the given widget with the given id at the end of the list. The list widget takes ownership of the inserted widget.
 
bool containsWidget (const QString &id) const
 Get if the list contains a widget with the given id.
 
QWidget * findWidget (const QString &path) const
 Get the widget that is at the given path. The path must be a forward slash separated list of ids. If the list contains some other KisOptionCollectionWidget or KisOptionCollectionWidgetWithHeader, and they do as well, then they form a hierarchy tree, so the path is searched recursively through all those child widgets.
 
template<typename T >
findWidgetAs (const QString &path) const
 Get the widget that is at the given path casted to some other class.
 
void insertWidget (int index, const QString &id, QWidget *widget)
 Insert the given widget with the given id at the given position. The list widget takes ownership of the inserted widget.
 
 KisOptionCollectionWidget (QWidget *parent=nullptr)
 
int numberOfVisibleWidgets () const
 Get the number of visible widgets in the list.
 
void removeWidget (const QString &id)
 Remove the widget that has the given id from the list. This also destroys the widget.
 
void removeWidget (int index)
 Remove the widget that is at the given position from the list. This also destroys the widget.
 
void setOrientation (Qt::Orientation orientation, bool recursive=false)
 Set the orientation of the list of widgets.
 
void setSeparatorsVisible (bool visible)
 Set the visibility of the separators.
 
void setWidgetsMargin (int margin)
 Set the margins of the widgets. This allows to indent the widgets with respect to the separators. The separators themselves are not changed.
 
void setWidgetVisible (const QString &id, bool visible)
 Set the visibility of the widget that has the given id. Use this function instead of the widget's one directly to get better visual results.
 
void setWidgetVisible (int index, bool visible)
 Set the visibility of the widget that is at the given position. Use this function instead of the widget's one directly to get better visual results.
 
int size () const
 Get the number of widgets in the list.
 
QWidget * takeWidget (const QString &id)
 Remove the widget that has the given id from the list. The widget is returned instead of being destroyed.
 
QWidget * takeWidget (int index)
 Remove the widget that is at the given position from the list. The widget is returned instead of being destroyed.
 
QWidget * widget (const QString &id) const
 Get the widget with the given id.
 
QWidget * widget (int index) const
 Get the widget that is at the given position.
 
template<typename T >
widgetAs (const QString &id) const
 Get the widget with the given id casted to some other class.
 
template<typename T >
widgetAs (int index) const
 Get the widget that is at the given position casted to some other class.
 
int widgetIndexFromId (const QString &id) const
 Get the index of the widget that has the given id.
 
 ~KisOptionCollectionWidget () override
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

Class providing a list of widgets with some addons such as separators, orientation or individual widget visibility.

Definition at line 19 of file KisOptionCollectionWidget.h.

Constructor & Destructor Documentation

◆ KisOptionCollectionWidget()

KisOptionCollectionWidget::KisOptionCollectionWidget ( QWidget * parent = nullptr)

Definition at line 304 of file KisOptionCollectionWidget.cpp.

305 : QWidget(parent)
306 , m_d(new Private(this))
307{
308 QBoxLayout *layoutMain = new QBoxLayout(QBoxLayout::TopToBottom);
309 layoutMain->setSpacing(5);
310 layoutMain->setContentsMargins(0, 0, 0, 0);
311 setLayout(layoutMain);
312}

◆ ~KisOptionCollectionWidget()

KisOptionCollectionWidget::~KisOptionCollectionWidget ( )
override

Definition at line 314 of file KisOptionCollectionWidget.cpp.

315{}

Member Function Documentation

◆ appendWidget()

void KisOptionCollectionWidget::appendWidget ( const QString & id,
QWidget * widget )

Insert the given widget with the given id at the end of the list. The list widget takes ownership of the inserted widget.

Definition at line 350 of file KisOptionCollectionWidget.cpp.

351{
352 insertWidget(m_d->widgetWrappers.size(), id, widget);
353}
void insertWidget(int index, const QString &id, QWidget *widget)
Insert the given widget with the given id at the given position. The list widget takes ownership of t...
QWidget * widget(int index) const
Get the widget that is at the given position.

References insertWidget(), m_d, and widget().

◆ containsWidget()

bool KisOptionCollectionWidget::containsWidget ( const QString & id) const

Get if the list contains a widget with the given id.

Definition at line 322 of file KisOptionCollectionWidget.cpp.

323{
324 return m_d->containsWidget(&id);
325}

References m_d.

◆ findWidget()

QWidget * KisOptionCollectionWidget::findWidget ( const QString & path) const

Get the widget that is at the given path. The path must be a forward slash separated list of ids. If the list contains some other KisOptionCollectionWidget or KisOptionCollectionWidgetWithHeader, and they do as well, then they form a hierarchy tree, so the path is searched recursively through all those child widgets.

Definition at line 337 of file KisOptionCollectionWidget.cpp.

338{
339 return m_d->findWidget(&path);
340}

References m_d.

◆ findWidgetAs()

template<typename T >
T KisOptionCollectionWidget::findWidgetAs ( const QString & path) const
inline

Get the widget that is at the given path casted to some other class.

See also
findWidget

Definition at line 76 of file KisOptionCollectionWidget.h.

77 {
78 return qobject_cast<T>(findWidget(path));
79 }
QWidget * findWidget(const QString &path) const
Get the widget that is at the given path. The path must be a forward slash separated list of ids....

◆ insertWidget()

void KisOptionCollectionWidget::insertWidget ( int index,
const QString & id,
QWidget * widget )

Insert the given widget with the given id at the given position. The list widget takes ownership of the inserted widget.

Definition at line 342 of file KisOptionCollectionWidget.cpp.

343{
344 if (containsWidget(id)) {
345 return;
346 }
347 m_d->insertWidget(index, id, widget);
348}
bool containsWidget(const QString &id) const
Get if the list contains a widget with the given id.

References containsWidget(), m_d, and widget().

◆ numberOfVisibleWidgets()

int KisOptionCollectionWidget::numberOfVisibleWidgets ( ) const

Get the number of visible widgets in the list.

Definition at line 469 of file KisOptionCollectionWidget.cpp.

470{
471 return layout()->count();
472}

◆ removeWidget() [1/2]

void KisOptionCollectionWidget::removeWidget ( const QString & id)

Remove the widget that has the given id from the list. This also destroys the widget.

Definition at line 360 of file KisOptionCollectionWidget.cpp.

361{
363}
void removeWidget(int index)
Remove the widget that is at the given position from the list. This also destroys the widget.
int widgetIndexFromId(const QString &id) const
Get the index of the widget that has the given id.

References removeWidget(), and widgetIndexFromId().

◆ removeWidget() [2/2]

void KisOptionCollectionWidget::removeWidget ( int index)

Remove the widget that is at the given position from the list. This also destroys the widget.

Definition at line 355 of file KisOptionCollectionWidget.cpp.

356{
357 delete takeWidget(index);
358}
QWidget * takeWidget(int index)
Remove the widget that is at the given position from the list. The widget is returned instead of bein...

References takeWidget().

◆ setOrientation()

void KisOptionCollectionWidget::setOrientation ( Qt::Orientation orientation,
bool recursive = false )

Set the orientation of the list of widgets.

Parameters
recursiveIf set to true and the list contains some KisOptionCollectionWidget or KisOptionCollectionWidgetWithHeader, then the orientation of those child widgets is also set, with the same recursive value

Definition at line 438 of file KisOptionCollectionWidget.cpp.

439{
440 if (orientation == m_d->orientation) {
441 return;
442 }
443 m_d->orientation = orientation;
444 for (KisOptionCollectionWidgetWrapper *widgetWrapper : m_d->widgetWrappers) {
445 widgetWrapper->setOrientation(orientation);
446 if (recursive) {
447 KisOptionCollectionWidget *optionCollectionWidget =
448 qobject_cast<KisOptionCollectionWidget*>(widgetWrapper->widget());
449 if (optionCollectionWidget) {
450 optionCollectionWidget->setOrientation(orientation, true);
451 continue;
452 }
453 KisOptionCollectionWidgetWithHeader *optionCollectionWidgetWithHeader =
454 qobject_cast<KisOptionCollectionWidgetWithHeader*>(widgetWrapper->widget());
455 if (optionCollectionWidgetWithHeader) {
456 optionCollectionWidgetWithHeader->setOrientation(orientation, true);
457 }
458 }
459 }
460 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
461 layoutMain->setDirection(orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
462}
Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an...
void setOrientation(Qt::Orientation orientation, bool recursive=false)
Set the orientation of the list of widgets.
Class providing a list of widgets with some addons such as separators, orientation or individual widg...
void setOrientation(Qt::Orientation orientation, bool recursive=false)
Set the orientation of the list of widgets.

References m_d, setOrientation(), and KisOptionCollectionWidgetWithHeader::setOrientation().

◆ setSeparatorsVisible()

void KisOptionCollectionWidget::setSeparatorsVisible ( bool visible)

Set the visibility of the separators.

Definition at line 427 of file KisOptionCollectionWidget.cpp.

428{
429 if (visible == m_d->showSeparators) {
430 return;
431 }
432 m_d->showSeparators = visible;
433 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
434 layoutMain->setSpacing(visible ? 0 : 5);
435 m_d->adjustSeparators();
436}

References m_d.

◆ setWidgetsMargin()

void KisOptionCollectionWidget::setWidgetsMargin ( int margin)

Set the margins of the widgets. This allows to indent the widgets with respect to the separators. The separators themselves are not changed.

Definition at line 416 of file KisOptionCollectionWidget.cpp.

417{
418 if (margin == m_d->widgetsMargin) {
419 return;
420 }
421 m_d->widgetsMargin = margin;
422 for (KisOptionCollectionWidgetWrapper *widgetWrapper : m_d->widgetWrappers) {
423 widgetWrapper->setWidgetMargin(margin);
424 }
425}

References m_d.

◆ setWidgetVisible() [1/2]

void KisOptionCollectionWidget::setWidgetVisible ( const QString & id,
bool visible )

Set the visibility of the widget that has the given id. Use this function instead of the widget's one directly to get better visual results.

Definition at line 411 of file KisOptionCollectionWidget.cpp.

412{
414}
void setWidgetVisible(int index, bool visible)
Set the visibility of the widget that is at the given position. Use this function instead of the widg...

References setWidgetVisible(), and widgetIndexFromId().

◆ setWidgetVisible() [2/2]

void KisOptionCollectionWidget::setWidgetVisible ( int index,
bool visible )

Set the visibility of the widget that is at the given position. Use this function instead of the widget's one directly to get better visual results.

Definition at line 379 of file KisOptionCollectionWidget.cpp.

380{
381 KisOptionCollectionWidgetWrapper *widgetWrapper = m_d->widgetWrappers[index];
382
383 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
385
386 if (visible) {
387 if (layoutMain->indexOf(widgetWrapper) != -1) {
388 return;
389 }
390 int indexLayout;
391 for (indexLayout = 0; indexLayout < layoutMain->count(); ++indexLayout) {
392 const QWidget *prevWidget = layoutMain->itemAt(indexLayout)->widget();
393 const int prevIndex = widgetIndexFromId(prevWidget->property("id").toString());
394 if (prevIndex >= index) {
395 break;
396 }
397 }
398 layoutMain->insertWidget(indexLayout, widgetWrapper);
399 widgetWrapper->setVisible(true);
400 } else {
401 if (layoutMain->indexOf(widgetWrapper) == -1) {
402 return;
403 }
404 layoutMain->takeAt(layoutMain->indexOf(widgetWrapper));
405 widgetWrapper->setVisible(false);
406 }
407
408 m_d->adjustSeparators();
409}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, and widgetIndexFromId().

◆ size()

int KisOptionCollectionWidget::size ( ) const

Get the number of widgets in the list.

Definition at line 464 of file KisOptionCollectionWidget.cpp.

465{
466 return m_d->widgetWrappers.size();
467}

References m_d.

◆ takeWidget() [1/2]

QWidget * KisOptionCollectionWidget::takeWidget ( const QString & id)

Remove the widget that has the given id from the list. The widget is returned instead of being destroyed.

Definition at line 374 of file KisOptionCollectionWidget.cpp.

375{
376 return takeWidget(widgetIndexFromId(id));
377}

References takeWidget(), and widgetIndexFromId().

◆ takeWidget() [2/2]

QWidget * KisOptionCollectionWidget::takeWidget ( int index)

Remove the widget that is at the given position from the list. The widget is returned instead of being destroyed.

Definition at line 365 of file KisOptionCollectionWidget.cpp.

366{
367 QWidget* widget = m_d->widgetWrappers[index]->widget();
368 widget->setParent(nullptr);
369 m_d->widgetWrappers.removeAt(index);
370 m_d->adjustSeparators();
371 return widget;
372}

References m_d, and widget().

◆ widget() [1/2]

QWidget * KisOptionCollectionWidget::widget ( const QString & id) const

Get the widget with the given id.

Definition at line 332 of file KisOptionCollectionWidget.cpp.

333{
334 return m_d->widget(&id);
335}

References m_d.

◆ widget() [2/2]

QWidget * KisOptionCollectionWidget::widget ( int index) const

Get the widget that is at the given position.

Definition at line 327 of file KisOptionCollectionWidget.cpp.

328{
329 return m_d->widget(index);
330}

References m_d.

◆ widgetAs() [1/2]

template<typename T >
T KisOptionCollectionWidget::widgetAs ( const QString & id) const
inline

Get the widget with the given id casted to some other class.

Definition at line 57 of file KisOptionCollectionWidget.h.

58 {
59 return qobject_cast<T>(widget(id));
60 }

◆ widgetAs() [2/2]

template<typename T >
T KisOptionCollectionWidget::widgetAs ( int index) const
inline

Get the widget that is at the given position casted to some other class.

Definition at line 44 of file KisOptionCollectionWidget.h.

45 {
46 return qobject_cast<T>(widget(index));
47 }

◆ widgetIndexFromId()

int KisOptionCollectionWidget::widgetIndexFromId ( const QString & id) const

Get the index of the widget that has the given id.

Definition at line 317 of file KisOptionCollectionWidget.cpp.

318{
319 return m_d->widgetIndexFromId(&id);
320}

References m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisOptionCollectionWidget::m_d
private

Definition at line 157 of file KisOptionCollectionWidget.h.


The documentation for this class was generated from the following files: