[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kde-runtime] /: Some RunnerModel work to make it fit in my KRunner implementation in QML.
From: Aleix Pol <aleixpol () kde ! org>
Date: 2012-05-02 18:39:24
Message-ID: 20120502183924.BA34A580CA () git ! kde ! org
[Download RAW message or body]
Git commit f9284f591317de1fd0742f54f5162c2c77b04df4 by Aleix Pol.
Committed on 16/02/2012 at 21:29.
Pushed by sreich into branch 'master'.
Some RunnerModel work to make it fit in my KRunner implementation in QML.
Changed from QAbstractItemModel -> QAbstractListModel
Expose new roles such as the runnerId, runnerName and the query's actions
M +18 -22 runnermodel.cpp
M +8 -7 runnermodel.h
http://commits.kde.org/kde-runtime/f9284f591317de1fd0742f54f5162c2c77b04df4
diff --git a/runnermodel.cpp b/runnermodel.cpp
index a226f8e..40e90f2 100644
--- a/runnermodel.cpp
+++ b/runnermodel.cpp
@@ -20,6 +20,7 @@
#include "runnermodel.h"
#include <QIcon>
+#include <QAction>
#include <QTimer>
#include <KDebug>
@@ -27,7 +28,7 @@
#include <Plasma/RunnerManager>
RunnerModel::RunnerModel(QObject *parent)
- : QAbstractItemModel(parent),
+ : QAbstractListModel(parent),
m_manager(0),
m_startQueryTimer(new QTimer(this))
{
@@ -40,6 +41,9 @@ RunnerModel::RunnerModel(QObject *parent)
roles.insert(Id, "id");
roles.insert(SubText, "description");
roles.insert(Enabled, "enabled");
+ roles.insert(RunnerId, "runnerid");
+ roles.insert(RunnerName, "runnerName");
+ roles.insert(Actions, "actions");
setRoleNames(roles);
m_startQueryTimer->setSingleShot(true);
@@ -47,22 +51,6 @@ RunnerModel::RunnerModel(QObject *parent)
connect(m_startQueryTimer, SIGNAL(timeout()), this, SLOT(startQuery()));
}
-QModelIndex RunnerModel::index(int row, int column, const QModelIndex &index) const
-{
- //kDebug() << "request for" << row << column << !index.isValid();
- if (!index.isValid() && row >= 0 && row < m_matches.count() && column >= 0 && column < 1) {
- return createIndex(row, column);
- }
-
- //kDebug() << "IIIIIIIIIIIIIINVALID!";
- return QModelIndex();
-}
-
-QModelIndex RunnerModel::parent(const QModelIndex&) const
-{
- return QModelIndex();
-}
-
int RunnerModel::rowCount(const QModelIndex& index) const
{
return index.isValid() ? 0 : m_matches.count();
@@ -73,11 +61,6 @@ int RunnerModel::count() const
return m_matches.count();
}
-int RunnerModel::columnCount(const QModelIndex&) const
-{
- return 1;
-}
-
QStringList RunnerModel::runners() const
{
return m_manager ? m_manager->allowedRunners() : QStringList();
@@ -87,6 +70,7 @@ void RunnerModel::setRunners(const QStringList &allowedRunners)
{
if (m_manager) {
m_manager->setAllowedRunners(allowedRunners);
+ emit runnersChanged();
} else {
m_pendingRunnersList = allowedRunners;
}
@@ -124,6 +108,18 @@ QVariant RunnerModel::data(const QModelIndex &index, int role) const
return m_matches.at(index.row()).subtext();
} else if (role == Enabled) {
return m_matches.at(index.row()).isEnabled();
+ } else if (role == RunnerId) {
+ return m_matches.at(index.row()).runner()->id();
+ } else if (role == RunnerName) {
+ return m_matches.at(index.row()).runner()->name();
+ } else if (role == Actions) {
+ QVariantList actions;
+ Plasma::QueryMatch amatch = m_matches.at(index.row());
+ QList<QAction*> theactions = m_manager->actionsForMatch(amatch);
+ foreach(QAction* action, theactions) {
+ actions += qVariantFromValue<QObject*>(action);
+ }
+ return actions;
}
return QVariant();
diff --git a/runnermodel.h b/runnermodel.h
index 899bf1f..cfef12e 100644
--- a/runnermodel.h
+++ b/runnermodel.h
@@ -20,7 +20,7 @@
#ifndef RUNNERMODEL_H
#define RUNNERMODEL_H
-#include <QAbstractItemModel>
+#include <QAbstractListModel>
#include <QStringList>
namespace Plasma
@@ -31,11 +31,11 @@ namespace Plasma
class QTimer;
-class RunnerModel : public QAbstractItemModel
+class RunnerModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QString query WRITE scheduleQuery READ currentQuery NOTIFY queryChanged)
- Q_PROPERTY(QStringList runners WRITE setRunners READ runners)
+ Q_PROPERTY(QStringList runners WRITE setRunners READ runners NOTIFY runnersChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
@@ -45,7 +45,10 @@ public:
Data,
Id,
SubText,
- Enabled
+ Enabled,
+ RunnerId,
+ RunnerName,
+ Actions
};
RunnerModel(QObject *parent = 0);
@@ -57,11 +60,8 @@ public:
Q_SCRIPTABLE void run(int row);
- QModelIndex index(int, int, const QModelIndex&) const;
- QModelIndex parent(const QModelIndex&) const;
int rowCount(const QModelIndex&) const;
int count() const;
- int columnCount(const QModelIndex&) const;
QVariant data(const QModelIndex&, int) const;
public Q_SLOTS:
@@ -70,6 +70,7 @@ public Q_SLOTS:
Q_SIGNALS:
void queryChanged();
void countChanged();
+ void runnersChanged();
private Q_SLOTS:
void startQuery();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic