Commit a6c8628c authored by Thomas Hartmann's avatar Thomas Hartmann

WelcomePage: add combox to filer Qt versions

Task-number: QTCREATORBUG-8377

Change-Id: I6693d4ed9cf3791e4cd791463a1b00a23dc4ffff
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@digia.com>
parent fa3b69d7
......@@ -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 {
......
......@@ -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
}
......
......@@ -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;
}
}
}
/****************************************************************************
**
** 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 {
}
......@@ -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
......@@ -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"
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment