diff options
Diffstat (limited to 'examples/widgets/itemviews')
10 files changed, 4 insertions, 216 deletions
diff --git a/examples/widgets/itemviews/CMakeLists.txt b/examples/widgets/itemviews/CMakeLists.txt index 0c2912178f..e80d90160b 100644 --- a/examples/widgets/itemviews/CMakeLists.txt +++ b/examples/widgets/itemviews/CMakeLists.txt @@ -3,7 +3,6 @@ qt_internal_add_example(addressbook) qt_internal_add_example(basicsortfiltermodel) -qt_internal_add_example(coloreditorfactory) qt_internal_add_example(combowidgetmapper) qt_internal_add_example(customsortfiltermodel) qt_internal_add_example(editabletreemodel) diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp index bde1cdc334..5b226793e4 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.cpp +++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp @@ -34,7 +34,10 @@ void AddressWidget::showAddEntryDialog() //! [3] void AddressWidget::addEntry(const QString &name, const QString &address) { - if (!table->getContacts().contains({ name, address })) { + if (!name.front().isLetter()) { + QMessageBox::information(this, tr("Invalid name"), + tr("The name must start with a letter.")); + } else if (!table->getContacts().contains({ name, address })) { table->insertRows(0, 1, QModelIndex()); QModelIndex index = table->index(0, 0, QModelIndex()); diff --git a/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt b/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt deleted file mode 100644 index 5dbc780027..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(coloreditorfactory LANGUAGES CXX) - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) - -qt_standard_project_setup() - -qt_add_executable(coloreditorfactory - colorlisteditor.cpp colorlisteditor.h - main.cpp - window.cpp window.h -) - -set_target_properties(coloreditorfactory PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(coloreditorfactory PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets -) - -install(TARGETS coloreditorfactory - BUNDLE DESTINATION . - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} -) - -qt_generate_deploy_app_script( - TARGET coloreditorfactory - OUTPUT_SCRIPT deploy_script - NO_UNSUPPORTED_PLATFORM_ERROR -) -install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro deleted file mode 100644 index 2d16ab5e2b..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro +++ /dev/null @@ -1,12 +0,0 @@ -QT += widgets -requires(qtConfig(combobox)) - -HEADERS = colorlisteditor.h \ - window.h -SOURCES = colorlisteditor.cpp \ - window.cpp \ - main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/coloreditorfactory -INSTALLS += target diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp deleted file mode 100644 index 44ce168c93..0000000000 --- a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "colorlisteditor.h" - -#include <QtWidgets> - -ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget) -{ - populateList(); -} - -//! [0] -QColor ColorListEditor::color() const -{ - return qvariant_cast<QColor>(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 8dfa9d9f05..0000000000 --- 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 <QComboBox> - -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 c4339e22c1..0000000000 --- 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 <QtWidgets> - -#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 31c8c1ae13..0000000000 --- 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 <QtWidgets> - -//! [0] -Window::Window() -{ - QItemEditorFactory *factory = new QItemEditorFactory; - - QItemEditorCreatorBase *colorListCreator = - new QStandardItemEditorCreator<ColorListEditor>(); - - factory->registerEditor(QMetaType::QColor, colorListCreator); - - QItemEditorFactory::setDefaultFactory(factory); - - createGUI(); -} -//! [0] - -void Window::createGUI() -{ - const QList<QPair<QString, QColor>> 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<QString, QColor> &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 4130b2d4ac..0000000000 --- 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 <QWidget> - -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 92997782a2..db06874ba5 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 \ |