diff --git a/lib/qtcreator/qtcomponents/custom/ChoiceList.qml b/lib/qtcreator/qtcomponents/custom/ChoiceList.qml index dcb7416dc12e491095df0d9fb8beedf9a9250f63..571ce5fc7062b1871777022956c646b029a90e9e 100644 --- a/lib/qtcreator/qtcomponents/custom/ChoiceList.qml +++ b/lib/qtcreator/qtcomponents/custom/ChoiceList.qml @@ -61,7 +61,7 @@ Item { property alias styledItem: choiceList sourceComponent: background anchors.fill: parent - property string currentItemText: model.get(currentIndex).text + property string currentItemText: model.get(currentIndex) } Private.ChoiceListPopup { diff --git a/lib/qtcreator/qtcomponents/custom/private/ChoiceListPopup.qml b/lib/qtcreator/qtcomponents/custom/private/ChoiceListPopup.qml index c8b66e3552049354ee2d21e6ef148c4c554f7f2f..ec0d2567c1e18468ed11fc5aaded38cc2d0e20d0 100644 --- a/lib/qtcreator/qtcomponents/custom/private/ChoiceListPopup.qml +++ b/lib/qtcreator/qtcomponents/custom/private/ChoiceListPopup.qml @@ -55,7 +55,7 @@ MouseArea { property int previousCurrentIndex: -1 property alias model: listView.model property alias currentIndex: listView.currentIndex - property string currentText: model && currentIndex >= 0 ? model.get(currentIndex).text : "" + property string currentText: model && currentIndex >= 0 ? model.get(currentIndex) : "" // buttonPressed will be true when the mouse press starts // while the popup is closed. At that point, this component can be @@ -241,7 +241,7 @@ MouseArea { property alias index: itemDelegate.theIndex property Item styledItem: choiceList property bool highlighted: theIndex == listView.highlightedIndex - property string itemText: popup.model.get(theIndex).text + property string itemText: text sourceComponent: listItem } diff --git a/share/qtcreator/welcomescreen/examples.qml b/share/qtcreator/welcomescreen/examples.qml index eadb44f36c10f1d361f4011fcdfd62369289cf65..584f7c7bb09032d5d047c4041173630ac7af03b5 100644 --- a/share/qtcreator/welcomescreen/examples.qml +++ b/share/qtcreator/welcomescreen/examples.qml @@ -65,7 +65,7 @@ Rectangle { y: 60 anchors.right: parent.right - anchors.rightMargin: 60 + anchors.rightMargin: 240 anchors.left: parent.left anchors.leftMargin: 60 @@ -73,4 +73,34 @@ Rectangle { onTextChanged: examplesModel.parseSearchString(text) } + ComboBox { + id: comboBox + + anchors.verticalCenter: searchBar.verticalCenter + + anchors.left: searchBar.right + anchors.rightMargin: 80 + anchors.right: parent.right + anchors.leftMargin: 20 + model: examplesModel.qtVersionModel + + onCurrentIndexChanged: { + print("currentIndex" + currentIndex); + + if (comboBox.model === undefined) + return; + + examplesModel.filterForQtById(comboBox.model.getId(currentIndex)) + } + + property int qtIndex: examplesModel.qtVersionIndex + + onQtIndexChanged: { + if (comboBox.model === undefined) + return; + if (qtIndex != currentIndex) + currentIndex = qtIndex; + } + } + } diff --git a/share/qtcreator/welcomescreen/widgets/ComboBox.qml b/share/qtcreator/welcomescreen/widgets/ComboBox.qml new file mode 100644 index 0000000000000000000000000000000000000000..c68d3ff286e3e2ce03a87248beca800ab2dd516c --- /dev/null +++ b/share/qtcreator/welcomescreen/widgets/ComboBox.qml @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 1.0 +import qtcomponents 1.0 + +ChoiceList { +} diff --git a/share/qtcreator/welcomescreen/widgets/qmldir b/share/qtcreator/welcomescreen/widgets/qmldir index d84eb6de47e2070e677c54bf054bf6b1e89c7564..8a5712d00958d4d41d3390d289c118dd8985ae94 100644 --- a/share/qtcreator/welcomescreen/widgets/qmldir +++ b/share/qtcreator/welcomescreen/widgets/qmldir @@ -17,4 +17,5 @@ Feedback 1.0 Feedback.qml PageLoader 1.0 PageLoader.qml ToolTip 1.0 ToolTip.qml IconAndLink 1.0 IconAndLink.qml +ComboBox 1.0 ComboBox.qml diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp index 2c0f7a3468f3c9be1853500d47263dab26dd429f..dbfab3107229f3366bed57b9c5d3630508a1fe38 100644 --- a/src/plugins/qtsupport/exampleslistmodel.cpp +++ b/src/plugins/qtsupport/exampleslistmodel.cpp @@ -34,6 +34,7 @@ #include <QFile> #include <QUrl> #include <QXmlStreamReader> +#include <QStandardItemModel> #include <coreplugin/helpmanager.h> #include <coreplugin/icore.h> @@ -48,11 +49,107 @@ namespace QtSupport { namespace Internal { +const int allQtVersionsId = -0xff; +static const char currentQtVersionFilterSettingsKeyC[] = "WelcomePageQtVersionFilter"; + +int uniqueQtVersionIdSetting() +{ + QSettings *settings = Core::ICore::settings(); + int id = settings->value(QLatin1String(currentQtVersionFilterSettingsKeyC), allQtVersionsId).toInt(); + return id; +} + +void setUniqueQtVersionIdSetting(int id) +{ + QSettings *settings = Core::ICore::settings(); + settings->setValue(QLatin1String(currentQtVersionFilterSettingsKeyC), id); +} + +class QtVersionsModel : public QStandardItemModel +{ + Q_OBJECT + +public: + QtVersionsModel(QObject *parent) : QStandardItemModel(parent) + { + QHash<int, QByteArray> roleNames; + roleNames[Qt::UserRole + 1] = "text"; + roleNames[Qt::UserRole + 2] = "QtId"; + setRoleNames(roleNames); + } + + void setupQtVersions() + { + beginResetModel(); + clear(); + + // prioritize default qt version + QtVersionManager *versionManager = QtVersionManager::instance(); + QList <BaseQtVersion *> qtVersions = versionManager->validVersions(); + ProjectExplorer::Kit *defaultKit = ProjectExplorer::KitManager::instance()->defaultKit(); + BaseQtVersion *defaultVersion = QtKitInformation::qtVersion(defaultKit); + if (defaultVersion && qtVersions.contains(defaultVersion)) + qtVersions.move(qtVersions.indexOf(defaultVersion), 0); + + QStandardItem *newItem = new QStandardItem(); + newItem->setData(tr("All Versions"), Qt::UserRole + 1); + newItem->setData(allQtVersionsId, Qt::UserRole + 2); + appendRow(newItem); + + int qtVersionSetting = uniqueQtVersionIdSetting(); + if (qtVersionSetting != allQtVersionsId) { + //ensure that the unique Qt id is valid + int newQtVersionSetting = allQtVersionsId; + foreach (BaseQtVersion *version, qtVersions) { + if (version->uniqueId() == qtVersionSetting) + newQtVersionSetting = qtVersionSetting; + } + + if (newQtVersionSetting != qtVersionSetting) { + setUniqueQtVersionIdSetting(newQtVersionSetting); + } + } + + foreach (BaseQtVersion *version, qtVersions) { + QStandardItem *newItem = new QStandardItem(); + newItem->setData(QString::fromLatin1("Qt %1 (%2)").arg(version->qtVersionString()).arg(version->platformDisplayName()), + Qt::UserRole + 1); + newItem->setData(version->uniqueId(), Qt::UserRole + 2); + appendRow(newItem); + } + endResetModel(); + } + +int indexForUniqueId(int uniqueId) { + for (int i=0; i < rowCount(); i++) { + if (uniqueId == getId(i).toInt()) + return i; + } + return 0; +} + +public slots: + QVariant get(int i) + { + QModelIndex modelIndex = index(i,0); + QVariant variant = data(modelIndex, Qt::UserRole + 1); + return variant; + } + + QVariant getId(int i) + { + QModelIndex modelIndex = index(i,0); + QVariant variant = data(modelIndex, Qt::UserRole + 2); + return variant; + } +}; + ExamplesListModel::ExamplesListModel(QObject *parent) : QAbstractListModel(parent), m_updateOnQtVersionsChanged(false), m_initialized(false), - m_helpInitialized(false) + m_helpInitialized(false), + m_uniqueQtId(allQtVersionsId) { QHash<int, QByteArray> roleNames; roleNames[Name] = "name"; @@ -285,8 +382,10 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString & void ExamplesListModel::handleQtVersionsChanged() { - if (m_updateOnQtVersionsChanged) + if (m_updateOnQtVersionsChanged) { + emit qtVersionsChanged(); updateExamples(); + } } void ExamplesListModel::updateExamples() @@ -409,6 +508,11 @@ QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QStr qtVersions.move(qtVersions.indexOf(defaultVersion), 0); foreach (BaseQtVersion *version, qtVersions) { + + //filter for qt versions + if (version->uniqueId() != m_uniqueQtId && m_uniqueQtId != allQtVersionsId) + continue; + // qt5 with examples OR demos manifest if (version->qtVersion().majorVersion == 5 && (version->hasExamples() || version->hasDemos())) { // examples directory in Qt5 is under the qtbase submodule, @@ -543,12 +647,26 @@ void ExamplesListModel::ensureInitialized() const ExamplesListModel *that = const_cast<ExamplesListModel *>(this); that->m_initialized = true; that->updateExamples(); + emit that->qtVersionsChanged(); +} + +void ExamplesListModel::filterForQtById(int id) +{ + m_uniqueQtId = id; + setUniqueQtVersionIdSetting(id); + updateExamples(); } ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) : - QSortFilterProxyModel(parent), m_showTutorialsOnly(true), m_sourceModel(sourceModel), m_timerId(0) + QSortFilterProxyModel(parent), + m_showTutorialsOnly(true), + m_sourceModel(sourceModel), + m_timerId(0), + m_qtVersionModel(new QtVersionsModel(this)), + m_blockIndexUpdate(false) { connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter())); + connect(sourceModel, SIGNAL(qtVersionsChanged()), SLOT(handleQtVersionsChanged())); setSourceModel(m_sourceModel); } @@ -627,12 +745,25 @@ QVariant ExamplesListModelFilter::data(const QModelIndex &index, int role) const return QSortFilterProxyModel::data(index, role); } +QAbstractItemModel* ExamplesListModelFilter::qtVersionModel() +{ + return m_qtVersionModel; +} + void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly) { m_showTutorialsOnly = showTutorialsOnly; emit showTutorialsOnlyChanged(); } +void ExamplesListModelFilter::handleQtVersionsChanged() +{ + m_blockIndexUpdate = true; + m_qtVersionModel->setupQtVersions(); + emit qtVersionIndexChanged(); + m_blockIndexUpdate = false; +} + void ExamplesListModelFilter::delayedUpdateFilter() { if (m_timerId != 0) @@ -641,6 +772,13 @@ void ExamplesListModelFilter::delayedUpdateFilter() m_timerId = startTimer(320); } +int ExamplesListModelFilter::qtVersionIndex() const +{ + int id = uniqueQtVersionIdSetting(); + int index = m_qtVersionModel->indexForUniqueId(id); + return index; +} + void ExamplesListModelFilter::timerEvent(QTimerEvent *timerEvent) { if (m_timerId == timerEvent->timerId()) { @@ -761,3 +899,5 @@ void ExamplesListModelFilter::parseSearchString(const QString &arg) } // namespace Internal } // namespace QtSupport + +#include "exampleslistmodel.moc" diff --git a/src/plugins/qtsupport/exampleslistmodel.h b/src/plugins/qtsupport/exampleslistmodel.h index 061121208229895d580c129e64e94fba346bbbc5..978612af1b267eeb86d156bef4bb66ec49dc52aa 100644 --- a/src/plugins/qtsupport/exampleslistmodel.h +++ b/src/plugins/qtsupport/exampleslistmodel.h @@ -38,6 +38,8 @@ namespace QtSupport { namespace Internal { +class QtVersionsModel; + enum ExampleRoles { Name = Qt::UserRole, ProjectPath, Description, ImageUrl, @@ -86,8 +88,11 @@ public: void beginReset() { beginResetModel(); } void endReset() { endResetModel(); } + void filterForQtById(int id); + signals: void tagsUpdated(); + void qtVersionsChanged(); public slots: void handleQtVersionsChanged(); @@ -109,6 +114,7 @@ private: bool m_updateOnQtVersionsChanged; bool m_initialized; bool m_helpInitialized; + int m_uniqueQtId; }; class ExamplesListModelFilter : public QSortFilterProxyModel @@ -120,6 +126,9 @@ public: Q_PROPERTY(QStringList filterTags READ filterTags WRITE setFilterTags NOTIFY filterTagsChanged) Q_PROPERTY(QStringList searchStrings READ searchStrings WRITE setSearchStrings NOTIFY searchStrings) + Q_PROPERTY(QAbstractItemModel* qtVersionModel READ qtVersionModel) + Q_PROPERTY(int qtVersionIndex READ qtVersionIndex NOTIFY qtVersionIndexChanged) + explicit ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; @@ -130,6 +139,15 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QAbstractItemModel* qtVersionModel(); + + Q_INVOKABLE void filterForQtById(int id) + { + if (m_blockIndexUpdate) + return; + + m_sourceModel->filterForQtById(id); + } public slots: void setFilterTags(const QStringList &arg) @@ -152,21 +170,26 @@ public slots: void parseSearchString(const QString &arg); void setShowTutorialsOnly(bool showTutorialsOnly); + void handleQtVersionsChanged(); signals: void showTutorialsOnlyChanged(); void filterTagsChanged(const QStringList &arg); void searchStrings(const QStringList &arg); + void qtVersionIndexChanged(); private: void timerEvent(QTimerEvent *event); void delayedUpdateFilter(); + int qtVersionIndex() const; bool m_showTutorialsOnly; QStringList m_filterTags; QStringList m_searchString; ExamplesListModel *m_sourceModel; int m_timerId; + QtVersionsModel* m_qtVersionModel; + bool m_blockIndexUpdate; }; } // namespace Internal