summaryrefslogtreecommitdiff
path: root/widgets/CheckableItemComboBox.cpp
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2022-08-23 10:23:16 +0200
committerChristoph Berg <christoph.berg@credativ.de>2022-08-23 10:23:16 +0200
commit2d1068e60bce7ae1fff11623454900e8cee956b1 (patch)
treeacebe276e30466ef0ab91bc3da5e379bec0d7dc5 /widgets/CheckableItemComboBox.cpp
parent43bebfbad6e7ba026bd3d55720c7d9e12a7ef8ef (diff)
New upstream version 2.6.0~rc3+repackupstream/2.6.0_rc3+repack
Diffstat (limited to 'widgets/CheckableItemComboBox.cpp')
-rwxr-xr-xwidgets/CheckableItemComboBox.cpp186
1 files changed, 93 insertions, 93 deletions
diff --git a/widgets/CheckableItemComboBox.cpp b/widgets/CheckableItemComboBox.cpp
index 13115c99..d3af4f49 100755
--- a/widgets/CheckableItemComboBox.cpp
+++ b/widgets/CheckableItemComboBox.cpp
@@ -1,93 +1,93 @@
-#include "CheckableItemComboBox.hpp"
-
-#include <QStyledItemDelegate>
-#include <QStandardItemModel>
-#include <QStandardItem>
-#include <QLineEdit>
-#include <QEvent>
-#include <QListView>
-
-class CheckableItemComboBoxStyledItemDelegate
- : public QStyledItemDelegate
-{
-public:
- explicit CheckableItemComboBoxStyledItemDelegate (QObject * parent = nullptr)
- : QStyledItemDelegate {parent}
- {
- }
-
- void paint (QPainter * painter, QStyleOptionViewItem const& option, QModelIndex const& index) const override
- {
- QStyleOptionViewItem& mutable_option = const_cast<QStyleOptionViewItem&> (option);
- mutable_option.showDecorationSelected = false;
- QStyledItemDelegate::paint (painter, mutable_option, index);
- }
-};
-
-CheckableItemComboBox::CheckableItemComboBox (QWidget * parent)
- : LazyFillComboBox {parent}
- , model_ {new QStandardItemModel()}
-{
- setModel (model_.data ());
-
- setEditable (true);
- lineEdit ()->setReadOnly (true);
- lineEdit ()->installEventFilter (this);
- setItemDelegate (new CheckableItemComboBoxStyledItemDelegate {this});
-
- connect (lineEdit(), &QLineEdit::selectionChanged, lineEdit(), &QLineEdit::deselect);
- connect (static_cast<QListView *> (view ()), &QListView::pressed, this, &CheckableItemComboBox::item_pressed);
- connect (model_.data (), &QStandardItemModel::dataChanged, this, &CheckableItemComboBox::model_data_changed);
-}
-
-QStandardItem * CheckableItemComboBox::addCheckItem (QString const& label, QVariant const& data
- , Qt::CheckState checkState)
-{
- auto * item = new QStandardItem {label};
- item->setCheckState (checkState);
- item->setData (data);
- item->setFlags (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- model_->appendRow (item);
- update_text ();
- return item;
-}
-
-bool CheckableItemComboBox::eventFilter (QObject * object, QEvent * event)
-{
- if (object == lineEdit() && event->type () == QEvent::MouseButtonPress)
- {
- showPopup();
- return true;
- }
- return false;
-}
-
-void CheckableItemComboBox::update_text()
-{
- QString text;
- for (int i = 0; i < model_->rowCount (); ++i)
- {
- if (model_->item (i)->checkState () == Qt::Checked)
- {
- if (text.size ())
- {
- text+= ", ";
- }
- text += model_->item (i)->data ().toString ();
- }
- }
- lineEdit ()->setText (text);
-}
-
-void CheckableItemComboBox::model_data_changed ()
-{
- update_text ();
-}
-
-void CheckableItemComboBox::item_pressed (QModelIndex const& index)
-{
- QStandardItem * item = model_->itemFromIndex (index);
- item->setCheckState (item->checkState () == Qt::Checked ? Qt::Unchecked : Qt::Checked);
-}
-
-#include "widgets/moc_CheckableItemComboBox.cpp"
+#include "CheckableItemComboBox.hpp"
+
+#include <QStyledItemDelegate>
+#include <QStandardItemModel>
+#include <QStandardItem>
+#include <QLineEdit>
+#include <QEvent>
+#include <QListView>
+
+class CheckableItemComboBoxStyledItemDelegate
+ : public QStyledItemDelegate
+{
+public:
+ explicit CheckableItemComboBoxStyledItemDelegate (QObject * parent = nullptr)
+ : QStyledItemDelegate {parent}
+ {
+ }
+
+ void paint (QPainter * painter, QStyleOptionViewItem const& option, QModelIndex const& index) const override
+ {
+ QStyleOptionViewItem& mutable_option = const_cast<QStyleOptionViewItem&> (option);
+ mutable_option.showDecorationSelected = false;
+ QStyledItemDelegate::paint (painter, mutable_option, index);
+ }
+};
+
+CheckableItemComboBox::CheckableItemComboBox (QWidget * parent)
+ : LazyFillComboBox {parent}
+ , model_ {new QStandardItemModel()}
+{
+ setModel (model_.data ());
+
+ setEditable (true);
+ lineEdit ()->setReadOnly (true);
+ lineEdit ()->installEventFilter (this);
+ setItemDelegate (new CheckableItemComboBoxStyledItemDelegate {this});
+
+ connect (lineEdit(), &QLineEdit::selectionChanged, lineEdit(), &QLineEdit::deselect);
+ connect (static_cast<QListView *> (view ()), &QListView::pressed, this, &CheckableItemComboBox::item_pressed);
+ connect (model_.data (), &QStandardItemModel::dataChanged, this, &CheckableItemComboBox::model_data_changed);
+}
+
+QStandardItem * CheckableItemComboBox::addCheckItem (QString const& label, QVariant const& data
+ , Qt::CheckState checkState)
+{
+ auto * item = new QStandardItem {label};
+ item->setCheckState (checkState);
+ item->setData (data);
+ item->setFlags (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ model_->appendRow (item);
+ update_text ();
+ return item;
+}
+
+bool CheckableItemComboBox::eventFilter (QObject * object, QEvent * event)
+{
+ if (object == lineEdit() && event->type () == QEvent::MouseButtonPress)
+ {
+ showPopup();
+ return true;
+ }
+ return false;
+}
+
+void CheckableItemComboBox::update_text()
+{
+ QString text;
+ for (int i = 0; i < model_->rowCount (); ++i)
+ {
+ if (model_->item (i)->checkState () == Qt::Checked)
+ {
+ if (text.size ())
+ {
+ text+= ", ";
+ }
+ text += model_->item (i)->data ().toString ();
+ }
+ }
+ lineEdit ()->setText (text);
+}
+
+void CheckableItemComboBox::model_data_changed ()
+{
+ update_text ();
+}
+
+void CheckableItemComboBox::item_pressed (QModelIndex const& index)
+{
+ QStandardItem * item = model_->itemFromIndex (index);
+ item->setCheckState (item->checkState () == Qt::Checked ? Qt::Unchecked : Qt::Checked);
+}
+
+#include "widgets/moc_CheckableItemComboBox.cpp"