ctkPluginTableModel.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkPluginTableModel.h"
  16. #include <ctkPlugin.h>
  17. #include <ctkPluginContext.h>
  18. ctkPluginTableModel::ctkPluginTableModel(ctkPluginContext* pc, QObject* parent)
  19. : QAbstractTableModel(parent)
  20. {
  21. plugins = pc->getPlugins();
  22. }
  23. QVariant ctkPluginTableModel::data(const QModelIndex& index, int role) const
  24. {
  25. if (!index.isValid()) return QVariant();
  26. ctkPlugin* plugin = plugins.at(index.row());
  27. if (role == Qt::DisplayRole)
  28. {
  29. int col = index.column();
  30. if (col == 0)
  31. {
  32. return QVariant(plugin->getSymbolicName());
  33. }
  34. else if (col == 1)
  35. {
  36. return QVariant(plugin->getVersion().toString());
  37. }
  38. else if (col == 2)
  39. {
  40. return QVariant(getStringForState(plugin->getState()));
  41. }
  42. }
  43. else if (role == Qt::UserRole)
  44. {
  45. return QVariant::fromValue<qlonglong>(plugin->getPluginId());
  46. }
  47. return QVariant();
  48. }
  49. QVariant ctkPluginTableModel::headerData(int section, Qt::Orientation orientation, int role) const
  50. {
  51. if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
  52. {
  53. if (section == 0)
  54. {
  55. return QVariant("Plugin");
  56. }
  57. else if (section == 1)
  58. {
  59. return QVariant("Version");
  60. }
  61. else if (section == 2)
  62. {
  63. return QVariant("State");
  64. }
  65. }
  66. return QVariant();
  67. }
  68. int ctkPluginTableModel::columnCount(const QModelIndex& parent) const
  69. {
  70. return 3;
  71. }
  72. int ctkPluginTableModel::rowCount(const QModelIndex& parent) const
  73. {
  74. return plugins.size();
  75. }
  76. QString ctkPluginTableModel::getStringForState(const ctkPlugin::State state) const
  77. {
  78. static const QString uninstalled("UNINSTALLED");
  79. static const QString installed("INSTALLED");
  80. static const QString resolved("RESOLVED");
  81. static const QString starting("STARTING");
  82. static const QString stopping("STOPPING");
  83. static const QString active("ACTIVE");
  84. switch(state)
  85. {
  86. case ctkPlugin::UNINSTALLED: return uninstalled;
  87. case ctkPlugin::INSTALLED: return installed;
  88. case ctkPlugin::RESOLVED: return resolved;
  89. case ctkPlugin::STARTING: return starting;
  90. case ctkPlugin::STOPPING: return stopping;
  91. case ctkPlugin::ACTIVE: return active;
  92. default: return QString("unknown");
  93. }
  94. }