mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
proxy model with first 4 items used as favorites
This commit is contained in:
parent
5730bae979
commit
5d4061efcf
6 changed files with 103 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ project(satellitecomponents)
|
||||||
set(satellitecomponents_SRCS
|
set(satellitecomponents_SRCS
|
||||||
satellitecomponentsplugin.cpp
|
satellitecomponentsplugin.cpp
|
||||||
applicationlistmodel.cpp
|
applicationlistmodel.cpp
|
||||||
|
favoritesmodel.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(satellitecomponentsplugin SHARED ${satellitecomponents_SRCS})
|
add_library(satellitecomponentsplugin SHARED ${satellitecomponents_SRCS})
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
// Self
|
// Self
|
||||||
#include "applicationlistmodel.h"
|
#include "applicationlistmodel.h"
|
||||||
|
#include "favoritesmodel.h"
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
@ -37,6 +38,9 @@
|
||||||
ApplicationListModel::ApplicationListModel(QObject *parent)
|
ApplicationListModel::ApplicationListModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
m_favoritesModel = new FavoritesModel(this);
|
||||||
|
m_favoritesModel->setSourceModel(this);
|
||||||
|
|
||||||
//can't use the new syntax as this signal is overloaded
|
//can't use the new syntax as this signal is overloaded
|
||||||
connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)),
|
connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)),
|
||||||
this, SLOT(sycocaDbChanged(const QStringList &)));
|
this, SLOT(sycocaDbChanged(const QStringList &)));
|
||||||
|
|
@ -46,6 +50,11 @@ ApplicationListModel::~ApplicationListModel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FavoritesModel *ApplicationListModel::favoritesModel()
|
||||||
|
{
|
||||||
|
return m_favoritesModel;
|
||||||
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> ApplicationListModel::roleNames() const
|
QHash<int, QByteArray> ApplicationListModel::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roleNames;
|
QHash<int, QByteArray> roleNames;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
|
class FavoritesModel;
|
||||||
|
|
||||||
struct ApplicationData {
|
struct ApplicationData {
|
||||||
QString name;
|
QString name;
|
||||||
QString icon;
|
QString icon;
|
||||||
|
|
@ -39,11 +41,13 @@ class ApplicationListModel : public QAbstractListModel {
|
||||||
|
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||||
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
|
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
|
||||||
|
Q_PROPERTY(FavoritesModel *favoritesModel READ favoritesModel CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ApplicationListModel(QObject *parent = 0);
|
ApplicationListModel(QObject *parent = 0);
|
||||||
virtual ~ApplicationListModel();
|
virtual ~ApplicationListModel();
|
||||||
|
|
||||||
|
FavoritesModel *favoritesModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
int count() { return m_applicationList.count(); }
|
int count() { return m_applicationList.count(); }
|
||||||
|
|
@ -81,6 +85,7 @@ private:
|
||||||
|
|
||||||
QStringList m_appOrder;
|
QStringList m_appOrder;
|
||||||
QHash<QString, int> m_appPositions;
|
QHash<QString, int> m_appPositions;
|
||||||
|
FavoritesModel *m_favoritesModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATIONLISTMODEL_H
|
#endif // APPLICATIONLISTMODEL_H
|
||||||
|
|
|
||||||
38
qmlcomponents/favoritesmodel.cpp
Normal file
38
qmlcomponents/favoritesmodel.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 by Marco Martin <mart@kde.org>
|
||||||
|
|
||||||
|
* 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 <QDebug>
|
||||||
|
|
||||||
|
FavoritesModel::FavoritesModel(QObject *parent)
|
||||||
|
: QIdentityProxyModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FavoritesModel::~FavoritesModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> FavoritesModel::roleNames() const
|
||||||
|
{
|
||||||
|
return sourceModel()->roleNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_favoritesmodel.cpp"
|
||||||
48
qmlcomponents/favoritesmodel.h
Normal file
48
qmlcomponents/favoritesmodel.h
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 by Marco MArtin <mart@kde.org>
|
||||||
|
|
||||||
|
* 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 <QIdentityProxyModel>
|
||||||
|
|
||||||
|
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
|
|
||||||
|
class FavoritesModel : public QIdentityProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FavoritesModel(QObject *parent = 0);
|
||||||
|
~FavoritesModel();
|
||||||
|
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
|
int count() const
|
||||||
|
{
|
||||||
|
return qMin(rowCount(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <kdeclarative/kdeclarative.h>
|
#include <kdeclarative/kdeclarative.h>
|
||||||
|
|
||||||
#include "applicationlistmodel.h"
|
#include "applicationlistmodel.h"
|
||||||
|
#include "favoritesmodel.h"
|
||||||
|
|
||||||
void SatelliteComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
|
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"));
|
Q_ASSERT(uri == QLatin1String("org.kde.satellite.components"));
|
||||||
|
|
||||||
qmlRegisterType<ApplicationListModel>(uri, 0, 1, "ApplicationListModel");
|
qmlRegisterType<ApplicationListModel>(uri, 0, 1, "ApplicationListModel");
|
||||||
|
qmlRegisterType<FavoritesModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue