summaryrefslogtreecommitdiffstats
path: root/sigtools/PluginTreeModel.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-03-26 04:48:40 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-03-26 04:51:01 -0400
commit1d09c9f3bba82ae2a918765f645c7829027b4ac1 (patch)
treee56941fdff3e1064cd9c8eb8422e1371dc6d200c /sigtools/PluginTreeModel.cpp
parent0d642f3374d9be46fb49f7a3fa5e3707935aa0d9 (diff)
Emulate KPluginSelector, but we can't use it directly due to the factory nature of the plugin classes
Diffstat (limited to 'sigtools/PluginTreeModel.cpp')
-rw-r--r--sigtools/PluginTreeModel.cpp115
1 files changed, 58 insertions, 57 deletions
diff --git a/sigtools/PluginTreeModel.cpp b/sigtools/PluginTreeModel.cpp
index ce2443ba..ae6af390 100644
--- a/sigtools/PluginTreeModel.cpp
+++ b/sigtools/PluginTreeModel.cpp
@@ -19,82 +19,83 @@
#include "PluginTreeModel.h"
// Sigtools includes
-#include "BaseModel.h"
#include "PluginTree.h"
-#include "RootPluginModel.h"
+#include "PluginLoader.h"
+
+// Sigencore plugin includes
+#include <sigencore/plugins/ArenaPlugin.h>
+#include <sigencore/plugins/CanvasPlugin.h>
+
+// KDE includes
+#include <KCategorizedSortFilterProxyModel>
// Qt includes
#include <QtGui/QIcon>
+using namespace Sigencore::Interfaces;
using namespace Sigtools;
-PluginTreeModel::PluginTreeModel(PluginTree* browser) :
- QAbstractItemModel(browser),
- m_root(new RootPluginModel)
+PluginTreeModel::PluginTreeModel(const QStringList& types, PluginTree* tree) :
+ QAbstractListModel(tree)
{
-}
-
-PluginTreeModel::~PluginTreeModel()
-{
- delete m_root;
+ foreach (const QString& type, types)
+ {
+ const QStringList names = PluginLoader::availablePlugins(type);
+ foreach (const QString& name, names)
+ {
+ ClassData data;
+ data.m_type = type;
+ data.m_name = name;
+ if (type == "Arena")
+ {
+ ArenaPlugin* plugin = PluginLoader::pluginForArena(name);
+ data.m_description = plugin->description(name);
+ data.m_icon = plugin->icon(name);
+ }
+ else if (type == "Canvas")
+ {
+ CanvasPlugin* plugin = PluginLoader::pluginForCanvas(name);
+ data.m_description = plugin->description(name);
+ data.m_icon = plugin->icon(name);
+ }
+ beginInsertRows(QModelIndex(), m_entries.size(), 1);
+ m_entries.append(data);
+ endInsertRows();
+ }
+ }
}
QModelIndex PluginTreeModel::index(const int row, const int column, const QModelIndex& parent) const
{
- if ((row < -1) || (column < -1))
- return QModelIndex();
- if (row == -1)
- return createIndex(row, 0, m_root);
- BaseModel* model = getItem(parent);
- if ((model->rowCount() <= row) || (1 <= column))
+ Q_UNUSED(parent)
+ Q_UNUSED(column)
+ if ((row <= -1) || (m_entries.size() <= row))
return QModelIndex();
- return createIndex(row, 0, model->childItem(row));
+ return createIndex(row, 0, (void*)&m_entries[row]);
}
QVariant PluginTreeModel::data(const QModelIndex& index, const int role) const
{
- Q_UNUSED(index)
- Q_UNUSED(role)
- return QVariant();
-}
-
-QModelIndex PluginTreeModel::parent(const QModelIndex& index) const
-{
- if (!index.isValid())
- return QModelIndex();
- BaseModel* parent = static_cast<BaseModel*>(index.internalPointer())->parent();
- if (!parent || (parent == m_root))
- return QModelIndex();
- return createIndex(parent->indexNumber(), 0, parent);
+ if (!index.isValid() || !index.internalPointer())
+ return QVariant();
+ ClassData* data = static_cast<ClassData*>(index.internalPointer());
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ return data->m_name;
+ case Qt::DecorationRole:
+ return data->m_icon;
+ case KCategorizedSortFilterProxyModel::CategoryDisplayRole:
+ case KCategorizedSortFilterProxyModel::CategorySortRole:
+ return data->m_type;
+ default:
+ return QVariant();
+ }
}
int PluginTreeModel::rowCount(const QModelIndex& parent) const
{
- return getItem(parent)->rowCount();
-}
-
-int PluginTreeModel::columnCount(const QModelIndex& parent) const
-{
- Q_UNUSED(parent)
- return 1;
-}
-
-Qt::ItemFlags PluginTreeModel::flags(const QModelIndex& index) const
-{
- Qt::ItemFlags flags = QAbstractItemModel::flags(index);
- if (index.isValid())
- flags |= static_cast<BaseModel*>(index.internalPointer())->flags();
- return flags;
-}
-
-BaseModel* PluginTreeModel::getItem(const QModelIndex& index) const
-{
- if (index.isValid())
- return static_cast<BaseModel*>(index.internalPointer());
- return m_root;
-}
-
-void PluginTreeModel::addPlugin(const QString& type, KService::Ptr service)
-{
- m_root->addPlugin(type, service);
+ if (parent.isValid())
+ return 0;
+ return m_entries.size();
}