16#include <QApplication>
17#include <QDesktopWidget>
18#include <QStringListModel>
21#include "ui_categoryselector.h"
49 return (QStringListModel::flags (index) & ~Qt::ItemIsEditable) | Qt::ItemIsUserCheckable;
54 if (
role == Qt::CheckStateRole)
55 return SelectedRows_.contains (index.row ()) ? Qt::Checked : Qt::Unchecked;
57 return QStringListModel::data (index,
role);
62 if (
role != Qt::CheckStateRole)
65 if (
value.value<Qt::CheckState> () == Qt::Checked)
66 SelectedRows_ << index.row ();
68 SelectedRows_.remove (index.row ());
70 Selector_.NotifyTagsSelection ();
80 SelectedRows_.reserve (size);
81 for (
int i = 0;
i < size; ++
i)
86 Selector_.NotifyTagsSelection ();
95 SelectedRows_.clear ();
98 Selector_.NotifyTagsSelection ();
106 Header_ = std::move (
header);
121 Ui_->Tree_->setModel (&Model_);
123 const auto&
avail = QApplication::desktop ()->availableGeometry (
this);
126 const auto all =
new QAction (
tr (
"Select all"),
this);
127 all->setProperty (
"ActionIcon",
"edit-select-all");
134 none->setProperty (
"ActionIcon",
"edit-select-none");
140 Ui_->Tree_->addAction (all);
141 Ui_->Tree_->addAction (
none);
143 Ui_->Tree_->setContextMenuPolicy (Qt::ActionsContextMenu);
155 auto guard = DisableNotifications ();
159 Model_.setStringList (
tags);
165 return Model_.stringList ();
170 const auto&
allTags = Model_.stringList ();
183 const auto& rowCount = Model_.stringList ().size ();
184 for (
int i = 0;
i < rowCount; ++
i)
186 const auto state = Model_.index (
i).
data (Qt::CheckStateRole).value<Qt::CheckState> ();
187 if (
state == Qt::Checked)
196 auto guard = DisableNotifications (
false);
198 const auto&
allTags = Model_.stringList ();
199 const auto rowCount =
allTags.size ();
200 for (
int i = 0;
i < rowCount; ++
i)
205 Model_.
setData (Model_.index (
i),
state, Qt::CheckStateRole);
224 Ui_->ButtonsBox_->setVisible (
false);
227 Ui_->ButtonsBox_->setStandardButtons (QDialogButtonBox::Close);
228 Ui_->ButtonsBox_->setVisible (
true);
231 Ui_->ButtonsBox_->setStandardButtons (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
232 Ui_->ButtonsBox_->setVisible (
true);
239 QWidget::moveEvent (
e);
241 QRect avail = QApplication::desktop ()->availableGeometry (
this);
265 auto guard = DisableNotifications (
false);
269 void CategorySelector::NotifyTagsSelection ()
271 if (NotificationsEnabled_)
278 NotificationsEnabled_ =
false;
283 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.
QStringList GetPossibleSelections() const
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.
virtual 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