16#include <QApplication>
17#include <QDesktopWidget>
20#include "ui_categoryselector.h"
37 Ui_->Tree_->setRootIsDecorated (
false);
38 Ui_->Tree_->setUniformRowHeights (
true);
40 QRect avail = QApplication::desktop ()->availableGeometry (
this);
44 &QTreeWidget::itemChanged,
46 &CategorySelector::NotifyTagsSelection);
48 const auto all =
new QAction (
tr (
"Select all"),
this);
60 Ui_->Tree_->addAction (all);
61 Ui_->Tree_->addAction (
none);
63 Ui_->Tree_->setContextMenuPolicy (Qt::ActionsContextMenu);
70 Ui_->Tree_->setHeaderLabel (
caption);
76 auto guard = DisableNotifications ();
90 item->setCheckState (0, Qt::Unchecked);
94 Ui_->Tree_->addTopLevelItems (
items);
96 Ui_->Tree_->setHeaderLabel (Caption_);
103 for (
int i = 0, size = Ui_->Tree_->topLevelItemCount ();
i < size; ++
i)
105 const auto item = Ui_->Tree_->topLevelItem (
i);
106 if (
item->checkState (0) == Qt::Checked)
117 for (
int i = 0, size = Ui_->Tree_->topLevelItemCount ();
i < size; ++
i)
119 const auto item = Ui_->Tree_->topLevelItem (
i);
120 if (
item->checkState (0) == Qt::Checked)
129 auto guard = DisableNotifications (
false);
131 for (
int i = 0;
i < Ui_->Tree_->topLevelItemCount (); ++
i)
133 const auto&
tagVar = Ui_->Tree_->topLevelItem (
i)->data (0,
RoleTag);
137 Ui_->Tree_->topLevelItem (
i)->setCheckState (0,
state);
156 Ui_->ButtonsBox_->setVisible (
false);
159 Ui_->ButtonsBox_->setStandardButtons (QDialogButtonBox::Close);
160 Ui_->ButtonsBox_->setVisible (
true);
163 Ui_->ButtonsBox_->setStandardButtons (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
164 Ui_->ButtonsBox_->setVisible (
true);
171 QWidget::moveEvent (
e);
173 QRect avail = QApplication::desktop ()->availableGeometry (
this);
187 auto guard = DisableNotifications ();
189 for (
int i = 0, size = Ui_->Tree_->topLevelItemCount ();
i < size; ++
i)
190 Ui_->Tree_->topLevelItem (
i)->setCheckState (0, Qt::Checked);
195 auto guard = DisableNotifications ();
197 for (
int i = 0;
i < Ui_->Tree_->topLevelItemCount (); ++
i)
198 Ui_->Tree_->topLevelItem (
i)->setCheckState (0, Qt::Unchecked);
203 auto guard = DisableNotifications (
false);
207 void CategorySelector::NotifyTagsSelection ()
209 if (NotificationsEnabled_)
216 NotificationsEnabled_ =
false;
221 NotifyTagsSelection ();
The CategorySelector widget provides a way to select amongst a group of items.
void SetSelections(const QStringList &subset)
Selects some of the items.
void SetButtonsMode(ButtonsMode)
Sets the buttons mode.
QList< int > GetSelectedIndexes() const
Gets the indexes of the selected items.
QStringList GetSelections() const
Gets selected items.
CategorySelector(QWidget *parent=nullptr)
Constructor.
QString GetSeparator() const
Returns the separator for the tags.
void moveEvent(QMoveEvent *) override
Checks whether after the move event the selector won't be beoynd the screen. if it would,...
void SelectNone()
Deselects all variants.
void SetCaption(const QString &caption)
Sets the caption of this selector.
void SetSeparator(const QString &)
Sets the separator for the tags.
void SetPossibleSelections(QStringList selections, bool sort=true)
Sets possible selections.
void SetSelectionsFromString(const QString &newText)
Notifies CategorySelector about logical selection changes.
void SelectAll()
Selects all variants.
void tagsSelectionChanged(const QStringList &newSelections)
Indicates that selections have changed.
Container< T > Filter(const Container< T > &c, F f)
detail::ScopeGuard< F > MakeScopeGuard(const F &f)
Returns an object performing passed function on scope exit.
QString GetDefaultTagsSeparator()
detail::ScopeGuard< detail::DefaultScopeGuardDeleter > DefaultScopeGuard