From 869e46613d2c8a5c54cfa136cacbb914bf350aa3 Mon Sep 17 00:00:00 2001 From: MohammadHossein Qanbari Date: Mon, 8 Jan 2024 16:41:56 +0100 Subject: [PATCH] Convert "Color Editor Factory" Example to snippets The color editor factory example is removed and part of the codes are used as snippets. Fixes: QTBUG-119985 Pick-to: 6.6 Change-Id: I421e473e7db09a5af7543b80b87a338d8ff2ab7e Reviewed-by: Axel Spoerl (cherry picked from commit 4e1a1f3697563124588d7d00089b15084220ca42) Reviewed-by: Qt Cherry-pick Bot --- doc/src/images/coloreditorfactoryimage.png | Bin 12209 -> 0 bytes .../widgets/doc/src/coloreditorfactory.qdoc | 132 ------------------ examples/widgets/itemviews/CMakeLists.txt | 1 - .../coloreditorfactory/CMakeLists.txt | 39 ------ .../coloreditorfactory/coloreditorfactory.pro | 12 -- .../coloreditorfactory/colorlisteditor.cpp | 39 ------ .../coloreditorfactory/colorlisteditor.h | 32 ----- .../itemviews/coloreditorfactory/main.cpp | 16 --- .../itemviews/coloreditorfactory/window.cpp | 55 -------- .../itemviews/coloreditorfactory/window.h | 20 --- examples/widgets/itemviews/itemviews.pro | 1 - .../src_gui_itemviews_qitemeditorfactory.cpp | 4 + src/widgets/itemviews/qitemdelegate.cpp | 22 ++- src/widgets/itemviews/qitemeditorfactory.cpp | 8 +- src/widgets/itemviews/qstyleditemdelegate.cpp | 19 ++- tests/auto/guiapplauncher/examples.txt | 1 - 16 files changed, 36 insertions(+), 365 deletions(-) delete mode 100644 doc/src/images/coloreditorfactoryimage.png delete mode 100644 examples/widgets/doc/src/coloreditorfactory.qdoc delete mode 100644 examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt delete mode 100644 examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro delete mode 100644 examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp delete mode 100644 examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h delete mode 100644 examples/widgets/itemviews/coloreditorfactory/main.cpp delete mode 100644 examples/widgets/itemviews/coloreditorfactory/window.cpp delete mode 100644 examples/widgets/itemviews/coloreditorfactory/window.h diff --git a/doc/src/images/coloreditorfactoryimage.png b/doc/src/images/coloreditorfactoryimage.png deleted file mode 100644 index cd839a6db605558ee6dc3a38b10b9a30dcb8c09d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12209 zcmZWvcRbbq_ctP3q{1~K5+SavWY3$7$X?edWQA+5jLeKE>t^rlO|I>dy?17AviIKn z-dCURdi?%)Kiv1*Yn}5t=Xsvzyk5btlw?VWXo#?|ut?-y$f#mrVS|B(jQ}6`Ql0UZ z5DSaTRZd1y-F0#!>1G8v^svoEv{qJYyb)3pQbup0WvazpP}5oQBJ!b1Bm<5D=^Z@g z7pf9&53wbU@N^<~$v&qt2+9Wgnml|Fd;Vhe;z%ok#@)Tf!@b#~*le+O>Ajhdy4I+p z*2SrF?|z}-#}2L@9!1uW^amOQ3I(r%Tj|}(;@>~BXNIbfO5G1eRNBl;YPsn!-o@&! zaauFEI6WwP-GV<+VG;Fiwod2!yNL&SRW>oUjTf5VZGS<8o!39>*E)A@&eWRrCyVaR zxcusD@I3p|^a0m?drs2nH%+C!oJzDGAME$wFFvyKNCY*HBz%zCW*VttdfY4U>juyC zck6^M_)=fe2jZj6nS7q7!rX#Y)pwwvcZ*_ePs;flrBdQUrEZ`f*bNgoN2+^B7!RT})0wMGFcCPOYu(yo2b z^wm9LYB6pP@7$ShA9bHuFl7yAYF z_I>qp_OWA$1qz5~&bNG#g1}wBy#xp-_I>tHY+)qjGn=vL-d+3p!J+fsiJ_X|MAoib zv7@ir5DqTTgZiRT3-_Lbkjpw##J7aWW~2W0gH_?)sx=zO7gA(=J@E{%dp&M$0ScOn z6gc22;zIgR9R>;>5xd|1y2Zoq^6DM{AMjhc#M+3;%JRb9~QZVatdH(hqz18=EVTpetk zYE>z#bhFY)Rk(_vZjubWvqMm1xYb zj3aW)j>`zmSsoHQdJjuHSz4eVFxZuE)rSiZrLE=}i}J5GYKZ+N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4+wTyGCE-c?#?`!fOqO8id;^J-;(QLK|CLC7iZPj7-&QSGMC!Ly*0@7VDsPyZpc zz-Ijg!@qPFFo{kfB)Ru@7sYgpL74w5at)NtTE#uJj*pk*x${p=2{^etf6W14u)%!w z4`F0s)W`d%>)yn-m2+un{l(|tRoc}I~b}9gTImU$G zcv}&~dWg(Y<-OvQnk)r;DO|T)*7k2Z35zXoN(p1{R6`73L_Lw^-dct9Xfs3`ezAaNk8XRVj!rFt-Q!tf_Y8s zx87){Fg%9Ki!%fW%cBlEcR0Ex(KB7BhC9siIX+5M3IyOe!V*@s zZ(&59!4Bqlj3RMBPRjnVNdY*qf(`tPP`eZ)K}ZLYvQ2z|DrA2EWNHP&(@w_uV5Ik+ zkzrWaHO~X#&jQt)Ya>#IPt<$306Y@&KY&L1Kr?O)*b=! z|Csj7`?lMx#sQ&Et9FfC!>oqCeHtk?Gz=uB{vFB5qf58DS zP0wwhIRF$B27R+{5nrdAF1LhZvTu1PRyG`dcAzE72~f!Ix&)~#%w!V zXFuaKp4%>R{)c2h#`t)FSlsChMRgr3B7e+P8-1oi)n073i?&^J1l`!Lq}603+En%* zfGw{W;j8d7e^X;#LI$Z|P*7HmIQ{)9x-unA^fsiT>14zwEl1nmIeNz62|#)W0fzDE zIR<_J3XB{u2Tb941}2&K=i?`UfC2aewEX)Kh(iCgy#6?NeiIS@$?QdEh-WlrBuWw( zpR}Udw{t1oh68JfFDBoliBcbsLzyFb(&+1mltP@ - -ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget) -{ - populateList(); -} - -//! [0] -QColor ColorListEditor::color() const -{ - return qvariant_cast(itemData(currentIndex(), Qt::DecorationRole)); -} -//! [0] - -//! [1] -void ColorListEditor::setColor(const QColor &color) -{ - setCurrentIndex(findData(color, Qt::DecorationRole)); -} -//! [1] - -//! [2] -void ColorListEditor::populateList() -{ - const QStringList colorNames = QColor::colorNames(); - - for (int i = 0; i < colorNames.size(); ++i) { - QColor color(colorNames[i]); - - insertItem(i, colorNames[i]); - setItemData(i, color, Qt::DecorationRole); - } -} -//! [2] diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h deleted file mode 100644 index 8dfa9d9f059..00000000000 --- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef COLORLISTEDITOR_H -#define COLORLISTEDITOR_H - -#include - -QT_BEGIN_NAMESPACE -class QColor; -class QWidget; -QT_END_NAMESPACE - -//! [0] -class ColorListEditor : public QComboBox -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor USER true) - -public: - ColorListEditor(QWidget *widget = nullptr); - -public: - QColor color() const; - void setColor(const QColor &color); - -private: - void populateList(); -}; -//! [0] - -#endif diff --git a/examples/widgets/itemviews/coloreditorfactory/main.cpp b/examples/widgets/itemviews/coloreditorfactory/main.cpp deleted file mode 100644 index c4339e22c17..00000000000 --- a/examples/widgets/itemviews/coloreditorfactory/main.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include - -#include "window.h" - -int main(int argv, char **args) -{ - QApplication app(argv, args); - - Window window; - window.show(); - - return app.exec(); -} diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp deleted file mode 100644 index 31c8c1ae137..00000000000 --- a/examples/widgets/itemviews/coloreditorfactory/window.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "window.h" -#include "colorlisteditor.h" - -#include - -//! [0] -Window::Window() -{ - QItemEditorFactory *factory = new QItemEditorFactory; - - QItemEditorCreatorBase *colorListCreator = - new QStandardItemEditorCreator(); - - factory->registerEditor(QMetaType::QColor, colorListCreator); - - QItemEditorFactory::setDefaultFactory(factory); - - createGUI(); -} -//! [0] - -void Window::createGUI() -{ - const QList> list = { { tr("Alice"), QColor("aliceblue") }, - { tr("Neptun"), QColor("aquamarine") }, - { tr("Ferdinand"), QColor("springgreen") } }; - - QTableWidget *table = new QTableWidget(3, 2); - table->setHorizontalHeaderLabels({ tr("Name"), tr("Hair Color") }); - table->verticalHeader()->setVisible(false); - table->resize(150, 50); - - for (int i = 0; i < 3; ++i) { - const QPair &pair = list.at(i); - - QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first); - QTableWidgetItem *colorItem = new QTableWidgetItem; - colorItem->setData(Qt::DisplayRole, pair.second); - - table->setItem(i, 0, nameItem); - table->setItem(i, 1, colorItem); - } - table->resizeColumnToContents(0); - table->horizontalHeader()->setStretchLastSection(true); - - QGridLayout *layout = new QGridLayout; - layout->addWidget(table, 0, 0); - - setLayout(layout); - - setWindowTitle(tr("Color Editor Factory")); -} diff --git a/examples/widgets/itemviews/coloreditorfactory/window.h b/examples/widgets/itemviews/coloreditorfactory/window.h deleted file mode 100644 index 4130b2d4ac2..00000000000 --- a/examples/widgets/itemviews/coloreditorfactory/window.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef WINDOW_H -#define WINDOW_H - -#include - -class Window : public QWidget -{ - Q_OBJECT - -public: - Window(); - -private: - void createGUI(); -}; - -#endif diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro index 92997782a2c..db06874ba52 100644 --- a/examples/widgets/itemviews/itemviews.pro +++ b/examples/widgets/itemviews/itemviews.pro @@ -1,7 +1,6 @@ TEMPLATE = subdirs SUBDIRS = addressbook \ basicsortfiltermodel \ - coloreditorfactory \ combowidgetmapper \ customsortfiltermodel \ editabletreemodel \ diff --git a/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp b/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp index d314c88fd90..1a311015c49 100644 --- a/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp +++ b/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp @@ -14,12 +14,16 @@ QItemEditorFactory *factory = new QItemEditorFactory; //! [1] +//! [setDefaultFactory] //! [2] QItemEditorFactory *editorFactory = new QItemEditorFactory; QItemEditorCreatorBase *creator = new QStandardItemEditorCreator(); editorFactory->registerEditor(QMetaType::QDateTime, creator); //! [2] +QItemEditorFactory::setDefaultFactory(editorFactory); +//! [setDefaultFactory] + //! [3] Q_PROPERTY(QColor color READ color WRITE setColor USER true) diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index e4a90278b49..d1c7bb3d581 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -257,15 +257,25 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const When subclassing QItemDelegate to create a delegate that displays items using a custom renderer, it is important to ensure that the delegate can - render items suitably for all the required states; e.g. selected, + render items suitably for all the required states; such as selected, disabled, checked. The documentation for the paint() function contains some hints to show how this can be achieved. - You can provide custom editors by using a QItemEditorFactory. The - \l{Color Editor Factory Example} shows how a custom editor can be - made available to delegates with the default item editor - factory. This way, there is no need to subclass QItemDelegate. An - alternative is to reimplement createEditor(), setEditorData(), + You can provide custom editors by using a QItemEditorFactory. The following + code shows how a custom editor can be made available to delegates with the + default item editor factory. + + \snippet code/src_gui_itemviews_qitemeditorfactory.cpp setDefaultFactory + + After the default factory has been set, all standard item delegates + will use it (also the delegates that were created before setting the + default factory). + + This way, you can avoid subclassing QItemDelegate, and all values of the + specified type (for example QMetaType::QDateTime) will be edited using the + provided editor (like \c{MyFancyDateTimeEdit} in the above example). + + An alternative is to reimplement createEditor(), setEditorData(), setModelData(), and updateEditorGeometry(). This process is described in the \l{A simple delegate}{Model/View Programming overview documentation}. diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index 609df364cfa..70d11e1b38f 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -120,7 +120,7 @@ Q_SIGNALS: Additional editors can be registered with the registerEditor() function. - \sa QStyledItemDelegate, {Model/View Programming}, {Color Editor Factory Example} + \sa QStyledItemDelegate, {Model/View Programming} */ /*! @@ -363,7 +363,7 @@ void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory) to register widgets without the need to subclass QItemEditorCreatorBase. \sa QStandardItemEditorCreator, QItemEditorFactory, - {Model/View Programming}, {Color Editor Factory Example} + {Model/View Programming} */ /*! @@ -432,7 +432,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase() property, you should use QStandardItemEditorCreator instead. \sa QItemEditorCreatorBase, QStandardItemEditorCreator, - QItemEditorFactory, {Color Editor Factory Example} + QItemEditorFactory */ /*! @@ -488,7 +488,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase() \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3 \sa QItemEditorCreatorBase, QItemEditorCreator, - QItemEditorFactory, QStyledItemDelegate, {Color Editor Factory Example} + QItemEditorFactory, QStyledItemDelegate */ /*! diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index 0587e8d0bea..54c1fb4f528 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -137,12 +137,17 @@ public: instance provided by QItemEditorFactory is installed on all item delegates. You can set a custom factory using setItemEditorFactory() or set a new default factory with - QItemEditorFactory::setDefaultFactory(). It is the data stored in - the item model with the \l{Qt::}{EditRole} that is edited. See the - QItemEditorFactory class for a more high-level introduction to - item editor factories. The \l{Color Editor Factory Example}{Color - Editor Factory} example shows how to create custom editors with a - factory. + QItemEditorFactory::setDefaultFactory(). + + \snippet code/src_gui_itemviews_qitemeditorfactory.cpp setDefaultFactory + + After the new factory has been set, all standard item delegates + will use it (i.e, also delegates that were created before the new + default factory was set). + + It is the data stored in the item model with the \l{Qt::}{EditRole} + that is edited. See the QItemEditorFactory class for a more + high-level introduction to item editor factories. \section1 Subclassing QStyledItemDelegate @@ -204,7 +209,7 @@ public: documentation for details. \sa {Delegate Classes}, QItemDelegate, QAbstractItemDelegate, QStyle, - {Star Delegate Example}, {Color Editor Factory Example} + {Star Delegate Example} */ diff --git a/tests/auto/guiapplauncher/examples.txt b/tests/auto/guiapplauncher/examples.txt index 4848da3f405..7aef8399250 100644 --- a/tests/auto/guiapplauncher/examples.txt +++ b/tests/auto/guiapplauncher/examples.txt @@ -23,7 +23,6 @@ "itemviews/addressbook Example", "examples/widgets/itemviews/addressbook", "addressbook", 0, -1 "itemviews/basicsortfiltermodel Example", "examples/widgets/itemviews/basicsortfiltermodel", "basicsortfiltermodel", 10, -1 "itemviews/chart Example", "examples/widgets/itemviews/chart", "chart", 0, -1 -"itemviews/coloreditorfactory Example", "examples/widgets/itemviews/coloreditorfactory", "coloreditorfactory", 10, -1 "itemviews/combowidgetmapper Example", "examples/widgets/itemviews/combowidgetmapper", "combowidgetmapper", 6, -1 "itemviews/customsortfiltermodel Example", "examples/widgets/itemviews/customsortfiltermodel", "customsortfiltermodel", 6, -1 "itemviews/dirview Example", "examples/widgets/itemviews/dirview", "dirview", 0, -1