diff --git a/qmlcomponents/CMakeLists.txt b/qmlcomponents/CMakeLists.txt index b25c4777..e4a4b561 100644 --- a/qmlcomponents/CMakeLists.txt +++ b/qmlcomponents/CMakeLists.txt @@ -3,6 +3,7 @@ project(satellitecomponents) set(satellitecomponents_SRCS satellitecomponentsplugin.cpp applicationlistmodel.cpp + favoritesmodel.cpp ) add_library(satellitecomponentsplugin SHARED ${satellitecomponents_SRCS}) diff --git a/qmlcomponents/applicationlistmodel.cpp b/qmlcomponents/applicationlistmodel.cpp index 639a30f2..8866ecb8 100644 --- a/qmlcomponents/applicationlistmodel.cpp +++ b/qmlcomponents/applicationlistmodel.cpp @@ -19,6 +19,7 @@ // Self #include "applicationlistmodel.h" +#include "favoritesmodel.h" // Qt #include @@ -37,6 +38,9 @@ ApplicationListModel::ApplicationListModel(QObject *parent) : QAbstractListModel(parent) { + m_favoritesModel = new FavoritesModel(this); + m_favoritesModel->setSourceModel(this); + //can't use the new syntax as this signal is overloaded connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)), this, SLOT(sycocaDbChanged(const QStringList &))); @@ -46,6 +50,11 @@ ApplicationListModel::~ApplicationListModel() { } +FavoritesModel *ApplicationListModel::favoritesModel() +{ + return m_favoritesModel; +} + QHash ApplicationListModel::roleNames() const { QHash roleNames; diff --git a/qmlcomponents/applicationlistmodel.h b/qmlcomponents/applicationlistmodel.h index 15cc5272..95b0b45e 100644 --- a/qmlcomponents/applicationlistmodel.h +++ b/qmlcomponents/applicationlistmodel.h @@ -27,6 +27,8 @@ class QString; +class FavoritesModel; + struct ApplicationData { QString name; QString icon; @@ -39,11 +41,13 @@ class ApplicationListModel : public QAbstractListModel { Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged) + Q_PROPERTY(FavoritesModel *favoritesModel READ favoritesModel CONSTANT) public: ApplicationListModel(QObject *parent = 0); virtual ~ApplicationListModel(); + FavoritesModel *favoritesModel(); int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int count() { return m_applicationList.count(); } @@ -81,6 +85,7 @@ private: QStringList m_appOrder; QHash m_appPositions; + FavoritesModel *m_favoritesModel; }; #endif // APPLICATIONLISTMODEL_H diff --git a/qmlcomponents/favoritesmodel.cpp b/qmlcomponents/favoritesmodel.cpp new file mode 100644 index 00000000..be4c2fab --- /dev/null +++ b/qmlcomponents/favoritesmodel.cpp @@ -0,0 +1,38 @@ +/* + * Copyright 2015 by Marco Martin + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "favoritesmodel.h" + +#include + +FavoritesModel::FavoritesModel(QObject *parent) + : QIdentityProxyModel(parent) +{ +} + +FavoritesModel::~FavoritesModel() +{ +} + +QHash FavoritesModel::roleNames() const +{ + return sourceModel()->roleNames(); +} + +#include "moc_favoritesmodel.cpp" diff --git a/qmlcomponents/favoritesmodel.h b/qmlcomponents/favoritesmodel.h new file mode 100644 index 00000000..606ad1eb --- /dev/null +++ b/qmlcomponents/favoritesmodel.h @@ -0,0 +1,48 @@ +/* + * Copyright 2015 by Marco MArtin + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef FAVORITESMODEL_H +#define FAVORITESMODEL_H + +#include + + +class QTimer; + + +class FavoritesModel : public QIdentityProxyModel +{ + Q_OBJECT + +public: + FavoritesModel(QObject *parent = 0); + ~FavoritesModel(); + + QHash roleNames() const; + + int count() const + { + return qMin(rowCount(), 4); + } + +private: + +}; + +#endif diff --git a/qmlcomponents/satellitecomponentsplugin.cpp b/qmlcomponents/satellitecomponentsplugin.cpp index df97eab3..8ca7311c 100644 --- a/qmlcomponents/satellitecomponentsplugin.cpp +++ b/qmlcomponents/satellitecomponentsplugin.cpp @@ -28,6 +28,7 @@ #include #include "applicationlistmodel.h" +#include "favoritesmodel.h" void SatelliteComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) { @@ -45,6 +46,7 @@ void SatelliteComponentsPlugin::registerTypes(const char *uri) Q_ASSERT(uri == QLatin1String("org.kde.satellite.components")); qmlRegisterType(uri, 0, 1, "ApplicationListModel"); + qmlRegisterType(); }