diff options
author | Frerich Raabe <raabe@froglogic.com> | 2016-06-03 16:07:52 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2016-06-15 09:48:16 +0000 |
commit | 86c218e7fa619864112abba5fa607f847fc114f3 (patch) | |
tree | d181721919542754fd3445150a49754cba5e6a59 /src/libs/installer/packagemanagergui.cpp | |
parent | b4a1a89e306367feaec56ce9902d15234ece5f84 (diff) |
Introduced gui.setTextItems() method
This utility function can be used to populate a Qt control which is
backed by some QAbstractItemModel with a list of strings. E.g. this can
be used to populate a QComboBox or any QAbstractItemView with some
items.
This is very useful since in many cases, the methods for adding elements
to such controls are neither slots, nor marked with Q_INVOKABLE and such
unreachable from the script code.
Change-Id: I2195f41e53765ef3a798477ed08d8f09ab5c4379
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/packagemanagergui.cpp')
-rw-r--r-- | src/libs/installer/packagemanagergui.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index 408ef0cbc..ec558a7ab 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -54,7 +54,9 @@ #include <QtCore/QProcess> #include <QtCore/QTimer> +#include <QAbstractItemView> #include <QCheckBox> +#include <QComboBox> #include <QDesktopServices> #include <QFileDialog> #include <QGridLayout> @@ -68,6 +70,7 @@ #include <QProgressBar> #include <QPushButton> #include <QRadioButton> +#include <QStringListModel> #include <QTextBrowser> #include <QTreeView> #include <QVBoxLayout> @@ -436,6 +439,26 @@ bool PackageManagerGui::isSilent() const } /*! + Updates the model of \a object (which must be a QComboBox or + QAbstractItemView) such that it contains the given \a items. +*/ +void PackageManagerGui::setTextItems(QObject *object, const QStringList &items) +{ + if (QComboBox *comboBox = qobject_cast<QComboBox*>(object)) { + comboBox->setModel(new QStringListModel(items)); + return; + } + + if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(object)) { + view->setModel(new QStringListModel(items)); + return; + } + + qDebug() << "Cannot set text items on object of type" + << object->metaObject()->className() << "."; +} + +/*! Enables automatic page switching when \a request is \c true. */ void PackageManagerGui::setAutomatedPageSwitchEnabled(bool request) |