summaryrefslogtreecommitdiffstats
path: root/tests/manual/examples/widgets/widgets/icons/imagedelegate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/examples/widgets/widgets/icons/imagedelegate.cpp')
-rw-r--r--tests/manual/examples/widgets/widgets/icons/imagedelegate.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/manual/examples/widgets/widgets/icons/imagedelegate.cpp b/tests/manual/examples/widgets/widgets/icons/imagedelegate.cpp
new file mode 100644
index 0000000000..ec3c227c71
--- /dev/null
+++ b/tests/manual/examples/widgets/widgets/icons/imagedelegate.cpp
@@ -0,0 +1,64 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "imagedelegate.h"
+#include "iconpreviewarea.h"
+
+#include <QComboBox>
+
+//! [0]
+ImageDelegate::ImageDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{}
+//! [0]
+
+//! [1]
+QWidget *ImageDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem & /* option */,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = new QComboBox(parent);
+ if (index.column() == 1)
+ comboBox->addItems(IconPreviewArea::iconModeNames());
+ else if (index.column() == 2)
+ comboBox->addItems(IconPreviewArea::iconStateNames());
+
+ connect(comboBox, &QComboBox::activated,
+ this, &ImageDelegate::emitCommitData);
+
+ return comboBox;
+}
+//! [1]
+
+//! [2]
+void ImageDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
+ if (!comboBox)
+ return;
+
+ int pos = comboBox->findText(index.model()->data(index).toString(),
+ Qt::MatchExactly);
+ comboBox->setCurrentIndex(pos);
+}
+//! [2]
+
+//! [3]
+void ImageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
+ if (!comboBox)
+ return;
+
+ model->setData(index, comboBox->currentText());
+}
+//! [3]
+
+//! [4]
+void ImageDelegate::emitCommitData()
+{
+ emit commitData(qobject_cast<QWidget *>(sender()));
+}
+//! [4]