KWidgetsAddons

kselectaction.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org>
4 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
5 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org>
6 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
7 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org>
8 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
9 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org>
10 SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org>
11 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org>
12 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
13 SPDX-FileCopyrightText: 2006 Albert Astals Cid <aacid@kde.org>
14 SPDX-FileCopyrightText: 2006 Clarence Dang <dang@kde.org>
15 SPDX-FileCopyrightText: 2006 Michel Hermier <michel.hermier@gmail.com>
16 SPDX-FileCopyrightText: 2007 Nick Shaforostoff <shafff@ukr.net>
17
18 SPDX-License-Identifier: LGPL-2.0-only
19*/
20
21#include "kselectaction.h"
22#include "kselectaction_p.h"
23
24#include "loggingcategory.h"
25
26#include <QActionEvent>
27#include <QEvent>
28#include <QMenu>
29#include <QStandardItem>
30#include <QToolBar>
31
32// QAction::setText("Hi") and then KPopupAccelManager exec'ing, causes
33// QAction::text() to return "&Hi" :( Comboboxes don't have accels and
34// display ampersands literally.
35static QString DropAmpersands(const QString &text)
36{
37 QString label = text;
38
39 int p = label.indexOf(QLatin1Char('&'));
40 while (p >= 0 && p < label.length() - 1) {
41 if (label[p + 1].isLetterOrNumber() // Valid accelerator.
42 || label[p + 1] == QLatin1Char('&')) { // Escaped accelerator marker.
43 label.remove(p, 1);
44 }
45
46 p = label.indexOf(QLatin1Char('&'), p + 1);
47 }
48
49 return label;
50}
51
53 : KSelectAction(*new KSelectActionPrivate(this), parent)
54{
55}
56
58 : KSelectAction(*new KSelectActionPrivate(this), parent)
59{
61}
62
64 : KSelectAction(*new KSelectActionPrivate(this), parent)
65{
68}
69
70KSelectAction::KSelectAction(KSelectActionPrivate &dd, QObject *parent)
72 , d_ptr(&dd)
73{
75 d->init();
76}
77
82
83void KSelectActionPrivate::init()
84{
85 QObject::connect(q_ptr->selectableActionGroup(), &QActionGroup::triggered, q_ptr, &KSelectAction::slotActionTriggered);
87 q_ptr->setMenu(new QMenu());
88 q_ptr->setEnabled(false);
89}
90
92{
93 Q_D(const KSelectAction);
94 return d->m_actionGroup;
95}
96
101
102QAction *KSelectAction::currentAction() const
103{
105}
106
107int KSelectAction::currentItem() const
108{
109 return selectableActionGroup()->actions().indexOf(currentAction());
110}
111
112QString KSelectAction::currentText() const
113{
114 if (QAction *a = currentAction()) {
115 return ::DropAmpersands(a->text());
116 }
117
118 return QString();
119}
120
122{
123 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::setCurrentAction(" << action << ")";
124 if (action) {
125 if (actions().contains(action)) {
126 if (action->isVisible() && action->isEnabled() && action->isCheckable()) {
127 action->setChecked(true);
128 if (isCheckable()) {
129 setChecked(true);
130 }
131 return true;
132 } else {
133 qCWarning(KWidgetsAddonsLog) << "Action does not have the correct properties to be current:" << action->text();
134 }
135 } else {
136 qCWarning(KWidgetsAddonsLog) << "Action does not belong to group:" << action->text();
137 }
138 return false;
139 }
140
141 if (currentAction()) {
142 currentAction()->setChecked(false);
143 }
144
145 return false;
146}
147
149{
150 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::setCurrentIndex(" << index << ")";
151 return setCurrentAction(action(index));
152}
153
155{
156 if (index >= 0 && index < selectableActionGroup()->actions().count()) {
157 return selectableActionGroup()->actions().at(index);
158 }
159
160 return nullptr;
161}
162
164{
165 QString compare;
166 if (cs == Qt::CaseSensitive) {
167 compare = text;
168 } else {
169 compare = text.toLower();
170 }
171
172 const auto selectableActions = selectableActionGroup()->actions();
173 for (QAction *action : selectableActions) {
174 const QString text = ::DropAmpersands(action->text());
175 if (cs == Qt::CaseSensitive) {
176 if (text == compare) {
177 return action;
178 }
179
180 } else if (cs == Qt::CaseInsensitive) {
181 if (text.toLower() == compare) {
182 return action;
183 }
184 }
185 }
186
187 return nullptr;
188}
189
191{
192 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::setCurrentAction(" << text << ",cs=" << cs << ")";
193 return setCurrentAction(action(text, cs));
194}
195
197{
199 if (width < 0) {
200 return;
201 }
202
203 d->m_comboWidth = width;
204
205 for (QComboBox *box : std::as_const(d->m_comboBoxes)) {
206 box->setMaximumWidth(d->m_comboWidth);
207 }
208
209 Q_EMIT changed();
210}
211
213{
215 d->m_maxComboViewCount = n;
216
217 for (QComboBox *box : std::as_const(d->m_comboBoxes)) {
218 if (d->m_maxComboViewCount != -1) {
219 box->setMaxVisibleItems(d->m_maxComboViewCount);
220 } else
221 // hardcoded qt default
222 {
223 box->setMaxVisibleItems(10);
224 }
225 }
226
227 Q_EMIT changed();
228}
229
234
236{
238 QAction *newAction = new QAction(parent());
239 newAction->setText(text);
240 newAction->setCheckable(true);
241 newAction->setProperty("isShortcutConfigurable", false);
242
243 if (!d->m_menuAccelsEnabled) {
244 newAction->setText(text);
245 newAction->setShortcut(QKeySequence());
246 }
247
248 addAction(newAction);
249 return newAction;
250}
251
253{
254 QAction *newAction = addAction(text);
255 newAction->setIcon(icon);
256 return newAction;
257}
258
260{
262 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::removeAction(" << action << ")";
263 // int index = selectableActionGroup()->actions().indexOf(action);
264 // qCDebug(KWidgetsAddonsLog) << "\tindex=" << index;
265
266 // Removes the action from the group and sets its parent to null.
267 d->m_actionGroup->removeAction(action);
268
269 // Disable when no action is in the group
270 bool hasActions = selectableActionGroup()->actions().isEmpty();
271 setEnabled(!hasActions);
272
273 for (QToolButton *button : std::as_const(d->m_buttons)) {
274 button->setEnabled(!hasActions);
275 button->removeAction(action);
276 }
277
278 for (QComboBox *comboBox : std::as_const(d->m_comboBoxes)) {
279 comboBox->setEnabled(!hasActions);
280 comboBox->removeAction(action);
281 }
282
284
285 return action;
286}
287
289{
291 action->setActionGroup(selectableActionGroup());
292
293 // Re-Enable when an action is added
294 setEnabled(true);
295
296 // Keep in sync with createToolBarWidget()
297 for (QToolButton *button : std::as_const(d->m_buttons)) {
298 button->setEnabled(true);
299 button->insertAction(before, action);
300 }
301
302 for (QComboBox *comboBox : std::as_const(d->m_comboBoxes)) {
303 comboBox->setEnabled(true);
304 comboBox->insertAction(before, action);
305 }
306
307 menu()->insertAction(before, action);
308}
309
311{
312 // cache values so we don't need access to members in the action
313 // after we've done an emit()
314 const QString text = ::DropAmpersands(action->text());
315 const int index = selectableActionGroup()->actions().indexOf(action);
316 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::slotActionTriggered(" << action << ") text=" << text
317 // << " index=" << index << " emitting triggered()" << endl;
318
319 if (isCheckable()) { // if this is subsidiary of other KSelectAction-derived class
320 trigger(); // then imitate usual QAction behaviour so that other submenus (and their items) become unchecked
321 }
322
324 Q_EMIT indexTriggered(index);
326}
327
328QStringList KSelectAction::items() const
329{
330 Q_D(const KSelectAction);
331 QStringList ret;
332
333 const auto actions = d->m_actionGroup->actions();
334 ret.reserve(actions.size());
335 for (QAction *action : actions) {
336 ret << ::DropAmpersands(action->text());
337 }
338
339 return ret;
340}
341
343{
345 if (index < 0 || index >= actions().count()) {
346 qCWarning(KWidgetsAddonsLog) << "KSelectAction::changeItem Index out of scope";
347 return;
348 }
349
350 actions()[index]->setText(d->makeMenuText(text));
351}
352
354{
356 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::setItems(" << lst << ")";
357
358 clear();
359
360 for (const QString &string : lst) {
361 if (!string.isEmpty()) {
362 addAction(string);
363 } else {
364 QAction *action = new QAction(this);
365 action->setSeparator(true);
367 }
368 }
369
370 // Disable if empty and not editable
371 setEnabled(lst.count() > 0 || d->m_edit);
372}
373
374int KSelectAction::comboWidth() const
375{
376 Q_D(const KSelectAction);
377 return d->m_comboWidth;
378}
379
381{
383 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::clear()";
384
385 // we need to delete the actions later since we may get a call to clear()
386 // from a method called due to a triggered(...) signal
387 const QList<QAction *> actions = d->m_actionGroup->actions();
388 for (int i = 0; i < actions.count(); ++i) {
389 // deleteLater() only removes us from the actions() list (among
390 // other things) on the next entry into the event loop. Until then,
391 // e.g. action() and setCurrentItem() will be working on items
392 // that are supposed to have been deleted. So detach the action to
393 // prevent this from happening.
395
396 actions[i]->deleteLater();
397 }
398}
399
401{
403 while (d->m_actionGroup->actions().count()) {
404 removeAction(d->m_actionGroup->actions().first());
405 }
406}
407
409{
411 d->m_edit = edit;
412
413 for (QComboBox *comboBox : std::as_const(d->m_comboBoxes)) {
414 comboBox->setEditable(edit);
415 }
416
417 Q_EMIT changed();
418}
419
421{
422 Q_D(const KSelectAction);
423 return d->m_edit;
424}
425
427{
428 // if (checked && selectableActionGroup()->checkedAction())
429 if (!checked && currentAction()) { // other's submenu item has been selected
430 currentAction()->setChecked(false);
431 }
432}
433
434KSelectAction::ToolBarMode KSelectAction::toolBarMode() const
435{
436 Q_D(const KSelectAction);
437 return d->m_toolBarMode;
438}
439
441{
443 d->m_toolBarMode = mode;
444}
445
446QToolButton::ToolButtonPopupMode KSelectAction::toolButtonPopupMode() const
447{
448 Q_D(const KSelectAction);
449 return d->m_toolButtonPopupMode;
450}
451
453{
455 d->m_toolButtonPopupMode = mode;
456}
457
458void KSelectActionPrivate::comboBoxDeleted(QComboBox *combo)
459{
460 m_comboBoxes.removeAll(combo);
461}
462
463void KSelectActionPrivate::comboBoxCurrentIndexChanged(int index)
464{
465 Q_Q(KSelectAction);
466 // qCDebug(KWidgetsAddonsLog) << "KSelectActionPrivate::comboBoxCurrentIndexChanged(" << index << ")";
467
468 QComboBox *triggeringCombo = qobject_cast<QComboBox *>(q->sender());
469
470 QAction *a = q->action(index);
471 // qCDebug(KWidgetsAddonsLog) << "\ta=" << a;
472 if (a) {
473 // qCDebug(KWidgetsAddonsLog) << "\t\tsetting as current action";
474 a->trigger();
475
476 } else if (q->isEditable() && triggeringCombo && triggeringCombo->count() > 0 && index == triggeringCombo->count() - 1) {
477 // User must have added a new item by typing and pressing enter.
478 const QString newItemText = triggeringCombo->currentText();
479 // qCDebug(KWidgetsAddonsLog) << "\t\tuser typed new item '" << newItemText << "'";
480
481 // Only 1 combobox contains this and it's not a proper action.
482 bool blocked = triggeringCombo->blockSignals(true);
483 triggeringCombo->removeItem(index);
484 triggeringCombo->blockSignals(blocked);
485
486 QAction *newAction = q->addAction(newItemText);
487
488 newAction->trigger();
489 } else {
490 if (q->selectableActionGroup()->checkedAction()) {
491 q->selectableActionGroup()->checkedAction()->setChecked(false);
492 }
493 }
494}
495
496// TODO: DropAmpersands() certainly makes sure this doesn't work. But I don't
497// think it did anyway esp. in the presence KCheckAccelerator - Clarence.
499{
501 d->m_menuAccelsEnabled = b;
502}
503
505{
506 Q_D(const KSelectAction);
507 return d->m_menuAccelsEnabled;
508}
509
511{
514 if (menu) { // If used in a menu want to return 0 and use only the text, not a widget
515 return nullptr;
516 }
517 ToolBarMode mode = toolBarMode();
519 if (!toolBar && mode != ComboBoxMode) { // we can return a combobox just fine.
520 return nullptr;
521 }
522 switch (mode) {
523 case MenuMode: {
524 QToolButton *button = new QToolButton(toolBar);
525 button->setToolTip(toolTip());
526 button->setWhatsThis(whatsThis());
527 button->setStatusTip(statusTip());
528 button->setAutoRaise(true);
530 button->setIconSize(toolBar->iconSize());
531 button->setToolButtonStyle(toolBar->toolButtonStyle());
534 button->setDefaultAction(this);
536
537 button->setPopupMode(toolButtonPopupMode());
538
540
541 d->m_buttons.append(button);
542 return button;
543 }
544
545 case ComboBoxMode: {
546 QComboBox *comboBox = new QComboBox(parent);
547 comboBox->installEventFilter(this);
548
549 if (d->m_maxComboViewCount != -1) {
550 comboBox->setMaxVisibleItems(d->m_maxComboViewCount);
551 }
552
553 if (d->m_comboWidth > 0) {
554 comboBox->setMaximumWidth(d->m_comboWidth);
555 }
556
557 comboBox->setEditable(isEditable());
558 comboBox->setToolTip(toolTip());
559 comboBox->setWhatsThis(whatsThis());
560 comboBox->setStatusTip(statusTip());
561 comboBox->setPlaceholderText(text());
562
563 const auto selectableActions = selectableActionGroup()->actions();
564 for (QAction *action : selectableActions) {
565 comboBox->addAction(action);
566 }
567
568 if (selectableActions.isEmpty()) {
569 comboBox->setEnabled(false);
570 }
571
572 connect(comboBox, &QComboBox::destroyed, this, [d, comboBox]() {
573 d->comboBoxDeleted(comboBox);
574 });
575
576 connect(comboBox, &QComboBox::currentIndexChanged, this, [d](int value) {
577 d->comboBoxCurrentIndexChanged(value);
578 });
579
580 d->m_comboBoxes.append(comboBox);
581
582 return comboBox;
583 }
584 }
585
586 return nullptr;
587}
588
590{
592 if (QToolButton *toolButton = qobject_cast<QToolButton *>(widget)) {
593 d->m_buttons.removeAll(toolButton);
594 } else if (QComboBox *comboBox = qobject_cast<QComboBox *>(widget)) {
595 d->m_comboBoxes.removeAll(comboBox);
596 }
598}
599
600bool KSelectAction::event(QEvent *event)
601{
603 if (event->type() == QEvent::ActionChanged) {
604 for (QComboBox *comboBox : std::as_const(d->m_comboBoxes)) {
605 comboBox->setToolTip(toolTip());
606 comboBox->setWhatsThis(whatsThis());
607 comboBox->setStatusTip(statusTip());
608 }
609 for (QToolButton *toolButton : std::as_const(d->m_buttons)) {
610 toolButton->setToolTip(toolTip());
611 toolButton->setWhatsThis(whatsThis());
612 toolButton->setStatusTip(statusTip());
613 }
614 }
615 return QWidgetAction::event(event);
616}
617
618// KSelectAction::eventFilter() is called before action->setChecked()
619// invokes the signal to update QActionGroup so KSelectAction::currentItem()
620// returns an old value. There are 3 possibilities, where n actions will
621// report QAction::isChecked() where n is:
622//
623// 0: the checked action was unchecked
624// 1: the checked action did not change
625// 2: another action was checked but QActionGroup has not been invoked yet
626// to uncheck the one that was checked before
627//
628// TODO: we might want to cache this since QEvent::ActionChanged is fired
629// often.
630static int TrueCurrentItem(KSelectAction *sa)
631{
632 QAction *curAction = sa->currentAction();
633 // qCDebug(KWidgetsAddonsLog) << "\tTrueCurrentItem(" << sa << ") curAction=" << curAction;
634
635 const auto actions = sa->actions();
636 int i = 0;
637 for (QAction *action : actions) {
638 if (action->isChecked()) {
639 // qCDebug(KWidgetsAddonsLog) << "\t\taction " << action << " (text=" << action->text () << ") isChecked";
640
641 // 2 actions checked case?
642 if (action != curAction) {
643 // qCDebug(KWidgetsAddonsLog) << "\t\t\tmust be newly selected one";
644 return i;
645 }
646 }
647 ++i;
648 }
649
650 // qCDebug(KWidgetsAddonsLog) << "\t\tcurrent action still selected? " << (curAction && curAction->isChecked ());
651 // 1 or 0 actions checked case (in that order)?
652 return (curAction && curAction->isChecked()) ? sa->actions().indexOf(curAction) : -1;
653}
654
655bool KSelectAction::eventFilter(QObject *watched, QEvent *event)
656{
657 QComboBox *comboBox = qobject_cast<QComboBox *>(watched);
658 if (!comboBox) {
659 return false /*propagate event*/;
660 }
661
662 // If focus is lost, replace any edited text with the currently selected
663 // item.
664 if (event->type() == QEvent::FocusOut) {
665 QFocusEvent *const e = static_cast<QFocusEvent *>(event);
666 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::eventFilter(FocusOut)"
667 // << " comboBox: ptr=" << comboBox
668 // << " reason=" << e->reason ()
669 // << endl;
670
671 if (e->reason() != Qt::ActiveWindowFocusReason // switch window
672 && e->reason() != Qt::PopupFocusReason // menu
673 && e->reason() != Qt::OtherFocusReason // inconsistently reproduceable actions...
674 ) {
675 // qCDebug(KWidgetsAddonsLog) << "\tkilling text";
676 comboBox->setEditText(comboBox->itemText(comboBox->currentIndex()));
677 }
678
679 return false /*propagate event*/;
680 }
681
682 bool blocked = comboBox->blockSignals(true);
683
684 if (event->type() == QEvent::ActionAdded) {
685 QActionEvent *const e = static_cast<QActionEvent *>(event);
686
687 const int index = e->before() ? comboBox->findData(QVariant::fromValue(e->before())) : comboBox->count();
688 const int newItem = ::TrueCurrentItem(this);
689 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::eventFilter(ActionAdded)"
690 // << " comboBox: ptr=" << comboBox
691 // << " currentItem=" << comboBox->currentIndex ()
692 // << " add index=" << index
693 // << " action new: e->before=" << e->before ()
694 // << " ptr=" << e->action ()
695 // << " icon=" << e->action ()->icon ()
696 // << " text=" << e->action ()->text ()
697 // << " currentItem=" << newItem
698 // << endl;
699 comboBox->insertItem(index, e->action()->icon(), ::DropAmpersands(e->action()->text()), QVariant::fromValue(e->action()));
700 if (QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboBox->model())) {
701 QStandardItem *item = model->item(index);
702 item->setEnabled(e->action()->isEnabled());
703 }
704
705 // Inserting an item into a combobox can change the current item so
706 // make sure the item corresponding to the checked action is selected.
707 comboBox->setCurrentIndex(newItem);
708 } else if (event->type() == QEvent::ActionChanged) {
709 QActionEvent *const e = static_cast<QActionEvent *>(event);
710
711 const int index = comboBox->findData(QVariant::fromValue(e->action()));
712 const int newItem = ::TrueCurrentItem(this);
713 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::eventFilter(ActionChanged)"
714 // << " comboBox: ptr=" << comboBox
715 // << " currentItem=" << comboBox->currentIndex ()
716 // << " changed action's index=" << index
717 // << " action new: ptr=" << e->action ()
718 // << " icon=" << e->action ()->icon ()
719 // << " text=" << e->action ()->text ()
720 // << " currentItem=" << newItem
721 // << endl;
722 comboBox->setItemIcon(index, e->action()->icon());
723 comboBox->setItemText(index, ::DropAmpersands(e->action()->text()));
724 if (QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboBox->model())) {
725 QStandardItem *item = model->item(index);
726 item->setEnabled(e->action()->isEnabled());
727 }
728
729 // The checked action may have become unchecked so
730 // make sure the item corresponding to the checked action is selected.
731 comboBox->setCurrentIndex(newItem);
732 } else if (event->type() == QEvent::ActionRemoved) {
733 QActionEvent *const e = static_cast<QActionEvent *>(event);
734
735 const int index = comboBox->findData(QVariant::fromValue(e->action()));
736 const int newItem = ::TrueCurrentItem(this);
737 // qCDebug(KWidgetsAddonsLog) << "KSelectAction::eventFilter(ActionRemoved)"
738 // << " comboBox: ptr=" << comboBox
739 // << " currentItem=" << comboBox->currentIndex ()
740 // << " delete action index=" << index
741 // << " new: currentItem=" << newItem
742 // << endl;
743 comboBox->removeItem(index);
744
745 // Removing an item from a combobox can change the current item so
746 // make sure the item corresponding to the checked action is selected.
747 comboBox->setCurrentIndex(newItem);
748 }
749
750 comboBox->blockSignals(blocked);
751
752 return false /*propagate event*/;
753}
754
755// END
756
757#include "moc_kselectaction.cpp"
Action for selecting one of several items.
bool isEditable() const
When this action is plugged into a toolbar, it creates a combobox.
bool setCurrentAction(QAction *action)
Sets the currently checked item.
KSelectAction(QObject *parent)
Constructs a selection action with the specified parent.
void setItems(const QStringList &lst)
Convenience function to create the list of selectable items.
void setToolButtonPopupMode(QToolButton::ToolButtonPopupMode mode)
Set how this list of actions should behave when in popup mode and plugged into a toolbar.
void deleteWidget(QWidget *widget) override
Reimplemented from QWidgetAction.
bool menuAccelsEnabled() const
Returns whether ampersands passed to methods using QStrings are interpreted as keyboard accelerator i...
virtual QAction * removeAction(QAction *action)
Remove the specified action from this action selector.
void slotToggled(bool)
For structured menu building.
void setComboWidth(int width)
When this action is plugged into a toolbar, it creates a combobox.
void changeItem(int index, const QString &text)
Changes the text of item.
virtual void slotActionTriggered(QAction *action)
This function is called whenever an action from the selections is triggered.
void clear()
Remove and delete all the items in this action.
@ MenuMode
Creates a button which pops up a menu when interacted with, as defined by toolButtonPopupMode().
@ ComboBoxMode
Creates a combo box which contains the actions.
QList< QAction * > actions() const
Returns the list of selectable actions.
void setToolBarMode(ToolBarMode mode)
Set the type of widget to be inserted in a toolbar to mode.
QActionGroup * selectableActionGroup() const
The action group used to create exclusivity between the actions associated with this action.
void setMaxComboViewCount(int n)
Sets the maximum items that are visible at once if the action is a combobox, that is the number of it...
virtual void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget's list of actions, before the action before.
void indexTriggered(int index)
This signal is emitted when an item is selected.
void textTriggered(const QString &text)
This signal is emitted when an item is selected.
void actionTriggered(QAction *action)
This signal is emitted when an item is selected.
void addAction(QAction *action)
Add action to the list of selectable actions.
void setMenuAccelsEnabled(bool b)
Sets whether any occurrence of the ampersand character ( & ) in items should be interpreted as keyboa...
void removeAllActions()
Remove all the items in this action.
~KSelectAction() override
Destructor.
QAction * action(int index) const
Returns the action at index, if one exists.
QWidget * createWidget(QWidget *parent) override
Reimplemented from QWidgetAction.
void setEditable(bool)
When this action is plugged into a toolbar, it creates a combobox.
bool setCurrentItem(int index)
Convenience function to set the currently checked action to be the action at index index.
QString label(StandardShortcut id)
void setIconSize(const QSize &size)
QAction(QObject *parent)
void changed()
bool isCheckable() const const
void setChecked(bool)
void setEnabled(bool)
QMenu * menu() const const
void setShortcut(const QKeySequence &shortcut)
void toggled(bool checked)
void trigger()
QAction * action() const const
QAction * before() const const
QList< QAction * > actions() const const
QAction * checkedAction() const const
void currentIndexChanged(int index)
void setEditable(bool editable)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
void insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)
QString itemText(int index) const const
void setMaxVisibleItems(int maxItems)
QAbstractItemModel * model() const const
void setPlaceholderText(const QString &placeholderText)
void removeItem(int index)
void setEditText(const QString &text)
void setItemIcon(int index, const QIcon &icon)
void setItemText(int index, const QString &text)
Qt::FocusReason reason() const const
const_reference at(qsizetype i) const const
qsizetype count() const const
qsizetype indexOf(const AT &value, qsizetype from) const const
bool isEmpty() const const
void reserve(qsizetype size)
QObject(QObject *parent)
Q_EMITQ_EMIT
bool blockSignals(bool block)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
void destroyed(QObject *obj)
void installEventFilter(QObject *filterObj)
QObject * parent() const const
T qobject_cast(QObject *object)
bool setProperty(const char *name, QVariant &&value)
void setEnabled(bool enabled)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
CaseSensitivity
ActiveWindowFocusReason
void actionTriggered(QAction *action)
void iconSizeChanged(const QSize &iconSize)
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
void setAutoRaise(bool enable)
void setPopupMode(ToolButtonPopupMode mode)
void setDefaultAction(QAction *action)
void setToolButtonStyle(Qt::ToolButtonStyle style)
void triggered(QAction *action)
QVariant fromValue(T &&value)
QAction * addAction(const QIcon &icon, const QString &text)
void addActions(const QList< QAction * > &actions)
void setEnabled(bool)
void setFocusPolicy(Qt::FocusPolicy policy)
void insertAction(QAction *before, QAction *action)
void setMaximumWidth(int maxw)
void removeAction(QAction *action)
void setStatusTip(const QString &)
void setToolTip(const QString &)
void setWhatsThis(const QString &)
QWidgetAction(QObject *parent)
virtual void deleteWidget(QWidget *widget)
virtual bool event(QEvent *event) override
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:02:04 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.