KPIM::KWidgetLister Class

Widget that manages a list of other widgets (incl. 'more', 'fewer' and 'clear' buttons). More...

Header: #include <KPIM/KWidgetLister>
CMake: find_package(KPim6Libkdepim REQUIRED)
target_link_libraries(mytarget PRIVATE KPim6::Libkdepim)

Public Functions

KWidgetLister(bool fewerMoreButton, int minWidgets = 1, int maxWidgets = 8, QWidget *parent = nullptr)
virtual ~KWidgetLister() override

Signals

void clearWidgets()
void widgetAdded()
void widgetAdded(QWidget *widget)
void widgetRemoved()
void widgetRemoved(QWidget *widget)

Protected Functions

virtual void addWidgetAfterThisWidget(QWidget *currentWidget, QWidget *widget = nullptr)
virtual void addWidgetAtEnd(QWidget *widget = nullptr)
virtual void clearWidget(QWidget *w)
virtual QWidget *createWidget(QWidget *parent)
virtual void removeLastWidget()
virtual void removeWidget(QWidget *widget)
virtual void setNumberOfShownWidgetsTo(int count)
QList<QWidget *> widgets() const
int widgetsMaximum() const
int widgetsMinimum() const

Protected Slots

virtual void slotClear()
virtual void slotFewer()
virtual void slotMore()

Detailed Description

Simple widget that nonetheless does a lot of the dirty work for the filter edit widgets (KMSearchPatternEdit and KMFilterActionEdit). It provides a growable and shrinkable area where widget may be displayed in rows. Widgets can be added by hitting the provided 'More' button, removed by the 'Fewer' button and cleared (e.g. reset, if an derived class implements that and removed for all but mMinWidgets).

To use this widget, derive from it with the template changed to the type of widgets this class should list. Then reimplement addWidgetAtEnd, removeLastWidget, calling the original implementation as necessary. Instantiate an object of the class and put it in your dialog.

Author: Marc Mutz <Marc@Mutz.com>

See also KMSearchPatternEdit::WidgetLister and KMFilterActionEdit::WidgetLister.

Member Function Documentation

[explicit] KWidgetLister::KWidgetLister(bool fewerMoreButton, int minWidgets = 1, int maxWidgets = 8, QWidget *parent = nullptr)

Constructor for KWidgetLister. fewerMoreButton if true, shows 'more' and 'fewer' buttons minWidgets the minimum number of widgets to keep visible maxWidgets the maximum number of widgets to show parent the parent widget

[override virtual noexcept] KWidgetLister::~KWidgetLister()

Destructor for KWidgetLister.

[virtual protected] void KWidgetLister::addWidgetAfterThisWidget(QWidget *currentWidget, QWidget *widget = nullptr)

Adds a widget after a specific existing widget. currentWidget the widget after which to insert widget the widget to add, or nullptr to create a default widget

[virtual protected] void KWidgetLister::addWidgetAtEnd(QWidget *widget = nullptr)

Adds a single widget to the lister. Override this method to initialize the new widget when it appears on screen. Make sure to call the parent implementation. widget the widget to add, or nullptr to create a default widget

[virtual protected] void KWidgetLister::clearWidget(QWidget *w)

Clears the contents of a widget. Default implementation does nothing. Override to reset widget to default state. w the widget to clear

[signal] void KWidgetLister::clearWidgets()

Signal emitted when the clear button is clicked.

[virtual protected] QWidget *KWidgetLister::createWidget(QWidget *parent)

Creates a new widget for the lister. Override this method to create and return your custom widget. parent the parent widget for the new widget Returns the newly created widget

[virtual protected] void KWidgetLister::removeLastWidget()

Removes the last widget from the lister. Override this method to save the state of the removed widget before removal. Make sure to call the parent implementation.

[virtual protected] void KWidgetLister::removeWidget(QWidget *widget)

Removes a specific widget from the lister. widget the widget to remove

[virtual protected] void KWidgetLister::setNumberOfShownWidgetsTo(int count)

Sets the exact number of widgets visible on screen. count the desired number of widgets

[virtual protected slot] void KWidgetLister::slotClear()

Slot called when the 'clear' button is clicked. This removes all widgets except the minimum number. Subclasses should override to reset widgets to their default state.

[virtual protected slot] void KWidgetLister::slotFewer()

Slot called when the 'fewer' button is clicked. This removes the last widget from the lister. Subclasses should override this to save the state of the removed widget.

[virtual protected slot] void KWidgetLister::slotMore()

Slot called when the 'more' button is clicked. This adds a new widget to the lister. Subclasses should override this to perform initialization on the new widget.

[signal] void KWidgetLister::widgetAdded()

Signal emitted when a widget is added.

Note: This signal is overloaded. To connect to this signal:

// Connect using qOverload:
connect(kWidgetLister, qOverload<>(&KWidgetLister::widgetAdded),
        receiver, &ReceiverClass::slot);

// Or using a lambda:
connect(kWidgetLister, qOverload<>(&KWidgetLister::widgetAdded),
        this, []() { /* handle widgetAdded */ });
For more examples and approaches, see connecting to overloaded signals.

[signal] void KWidgetLister::widgetAdded(QWidget *widget)

Signal emitted when a widget is added. widget the widget that was added

Note: This signal is overloaded. To connect to this signal:

// Connect using qOverload:
connect(kWidgetLister, qOverload(&KWidgetLister::widgetAdded),
        receiver, &ReceiverClass::slot);

// Or using a lambda:
connect(kWidgetLister, qOverload(&KWidgetLister::widgetAdded),
        this, [](QWidget *widget) { /* handle widgetAdded */ });
For more examples and approaches, see connecting to overloaded signals.

[signal] void KWidgetLister::widgetRemoved()

Signal emitted when a widget is removed.

Note: This signal is overloaded. To connect to this signal:

// Connect using qOverload:
connect(kWidgetLister, qOverload<>(&KWidgetLister::widgetRemoved),
        receiver, &ReceiverClass::slot);

// Or using a lambda:
connect(kWidgetLister, qOverload<>(&KWidgetLister::widgetRemoved),
        this, []() { /* handle widgetRemoved */ });
For more examples and approaches, see connecting to overloaded signals.

[signal] void KWidgetLister::widgetRemoved(QWidget *widget)

Signal emitted when a widget is removed. widget the widget that was removed

Note: This signal is overloaded. To connect to this signal:

// Connect using qOverload:
connect(kWidgetLister, qOverload(&KWidgetLister::widgetRemoved),
        receiver, &ReceiverClass::slot);

// Or using a lambda:
connect(kWidgetLister, qOverload(&KWidgetLister::widgetRemoved),
        this, [](QWidget *widget) { /* handle widgetRemoved */ });
For more examples and approaches, see connecting to overloaded signals.

[protected] QList<QWidget *> KWidgetLister::widgets() const

Returns the list of all widgets in the lister. Returns list of QWidget pointers

[protected] int KWidgetLister::widgetsMaximum() const

Returns the maximum number of widgets that can be shown. Returns the maximum widget count

[protected] int KWidgetLister::widgetsMinimum() const

Returns the minimum number of widgets that must stay visible. Returns the minimum widget count