ctkPluginTableModel.cpp

Go to the documentation of this file.
00001 /*=============================================================================
00002 
00003   Library: CTK
00004 
00005   Copyright (c) 2010 German Cancer Research Center,
00006     Division of Medical and Biological Informatics
00007 
00008   Licensed under the Apache License, Version 2.0 (the "License");
00009   you may not use this file except in compliance with the License.
00010   You may obtain a copy of the License at
00011 
00012     http://www.apache.org/licenses/LICENSE-2.0
00013 
00014   Unless required by applicable law or agreed to in writing, software
00015   distributed under the License is distributed on an "AS IS" BASIS,
00016   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017   See the License for the specific language governing permissions and
00018   limitations under the License.
00019 
00020 =============================================================================*/
00021 
00022 #include "ctkPluginTableModel.h"
00023 
00024 #include <ctkPlugin.h>
00025 #include <ctkPluginContext.h>
00026 
00027 ctkPluginTableModel::ctkPluginTableModel(ctkPluginContext* pc, QObject* parent)
00028   : QAbstractTableModel(parent)
00029 {
00030   plugins = pc->getPlugins();
00031 }
00032 
00033 QVariant ctkPluginTableModel::data(const QModelIndex& index, int role) const
00034 {
00035   if (!index.isValid()) return QVariant();
00036 
00037   ctkPlugin* plugin = plugins.at(index.row());
00038   if (role == Qt::DisplayRole)
00039   {
00040     int col = index.column();
00041     if (col == 0)
00042     {
00043       return QVariant(plugin->getSymbolicName());
00044     }
00045     else if (col == 1)
00046     {
00047       return QVariant(plugin->getVersion().toString());
00048     }
00049     else if (col == 2)
00050     {
00051       return QVariant(getStringForState(plugin->getState()));
00052     }
00053   }
00054   else if (role == Qt::UserRole)
00055   {
00056     return QVariant::fromValue<qlonglong>(plugin->getPluginId());
00057   }
00058 
00059   return QVariant();
00060 }
00061 
00062 QVariant ctkPluginTableModel::headerData(int section, Qt::Orientation orientation, int role) const
00063 {
00064   if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
00065   {
00066     if (section == 0)
00067     {
00068       return QVariant("Plugin");
00069     }
00070     else if (section == 1)
00071     {
00072       return QVariant("Version");
00073     }
00074     else if (section == 2)
00075     {
00076       return QVariant("State");
00077     }
00078   }
00079 
00080   return QVariant();
00081 }
00082 
00083 int ctkPluginTableModel::columnCount(const QModelIndex& parent) const
00084 {
00085   return 3;
00086 }
00087 
00088 int ctkPluginTableModel::rowCount(const QModelIndex& parent) const
00089 {
00090   return plugins.size();
00091 }
00092 
00093 QString ctkPluginTableModel::getStringForState(const ctkPlugin::State state) const
00094 {
00095   static const QString uninstalled("UNINSTALLED");
00096   static const QString installed("INSTALLED");
00097   static const QString resolved("RESOLVED");
00098   static const QString starting("STARTING");
00099   static const QString stopping("STOPPING");
00100   static const QString active("ACTIVE");
00101 
00102   switch(state)
00103   {
00104   case ctkPlugin::UNINSTALLED: return uninstalled;
00105   case ctkPlugin::INSTALLED: return installed;
00106   case ctkPlugin::RESOLVED: return resolved;
00107   case ctkPlugin::STARTING: return starting;
00108   case ctkPlugin::STOPPING: return stopping;
00109   case ctkPlugin::ACTIVE: return active;
00110   default: return QString("unknown");
00111   }
00112 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines