MEPP2 Project
PluginDialog.inl
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 
13 #include <QPluginLoader>
14 #include <QStringList>
15 #include <QDir>
16 
17 #include <QLabel>
18 #include <QGridLayout>
19 #include <QPushButton>
20 #include <QTreeWidget>
21 #include <QTreeWidgetItem>
22 #include <QHeaderView>
23 
24 #include <iostream>
25 
26 inline
28  const QStringList &fileNames,
29  QWidget *parent)
30  : QDialog(parent), label(new QLabel), treeWidget(new QTreeWidget),
31  okButton(new QPushButton(tr("OK")))
32 {
33  treeWidget->setAlternatingRowColors(false);
34  treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
35  treeWidget->setColumnCount(1);
36  treeWidget->header()->hide();
37 
38  okButton->setDefault(true);
39 
40  connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
41 
42  QGridLayout *mainLayout = new QGridLayout;
43  mainLayout->setColumnStretch(0, 1);
44  mainLayout->setColumnStretch(2, 1);
45  mainLayout->addWidget(label, 0, 0, 1, 3);
46  mainLayout->addWidget(treeWidget, 1, 0, 1, 3);
47  mainLayout->addWidget(okButton, 2, 1);
48  setLayout(mainLayout);
49 
50  interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
51  QIcon::Normal,
52  QIcon::On);
53  interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
54  QIcon::Normal,
55  QIcon::Off);
56  featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
57 
58  setWindowTitle(tr("Plugins information"));
59  findPlugins(path, fileNames);
60 }
61 
62 inline
63 void
64 FEVV::PluginDialog::findPlugins(const QString &path,
65  const QStringList &fileNames)
66 {
67  label->setText(tr("Found the following plugins\n"
68  "(looked in %1):")
69  .arg(QDir::toNativeSeparators(path)));
70 
71  const QDir dir(path);
72  foreach(QObject *plugin, QPluginLoader::staticInstances())
73  populateTreeWidget(
74  plugin,
75  tr("%1 (Static Plugin)").arg(plugin->metaObject()->className()));
76 
77  foreach(QString fileName, fileNames)
78  {
79  std::cout << fileName.toStdString() << std::endl;
80  QPluginLoader loader(dir.absoluteFilePath(fileName));
81  QObject *plugin = loader.instance();
82  if(plugin)
83  populateTreeWidget(plugin, fileName);
84  }
85 }
86 
87 inline
88 void
89 FEVV::PluginDialog::populateTreeWidget(QObject *plugin, const QString &text)
90 {
91  QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget);
92  pluginItem->setText(0, text);
93  //treeWidget->setItemExpanded(pluginItem, true); // deprecated !!!
94  pluginItem->setExpanded(true);
95 
96  QFont boldFont = pluginItem->font(0);
97  boldFont.setBold(true);
98  pluginItem->setFont(0, boldFont);
99 
100  if(plugin)
101  {
102  Generic_PluginInterface *iGeneric_Filter =
103  qobject_cast< Generic_PluginInterface * >(plugin);
104  if(iGeneric_Filter)
105  addItems(pluginItem,
106  "Generic_PluginInterface",
107  iGeneric_Filter->Generic_plugins());
108  }
109 }
110 
111 inline
112 void
113 FEVV::PluginDialog::addItems(QTreeWidgetItem *pluginItem,
114  const char *interfaceName,
115  const QStringList &features)
116 {
117  QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem);
118  interfaceItem->setText(0, interfaceName);
119  interfaceItem->setIcon(0, interfaceIcon);
120 
121  foreach(QString feature, features)
122  {
123  if(feature.endsWith("..."))
124  feature.chop(3);
125  QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem);
126  featureItem->setText(0, feature);
127  featureItem->setIcon(0, featureIcon);
128  }
129 }
tr
double tr(double &n)
Truncate a number to 1/1000 (only if BOOLEAN_OPERATIONS_DEBUG is enable)
Definition: boolops_definitions.hpp:127
FEVV::PluginDialog::okButton
QPushButton * okButton
Definition: PluginDialog.hpp:51
FEVV::PluginDialog::interfaceIcon
QIcon interfaceIcon
Definition: PluginDialog.hpp:52
FEVV::PluginDialog::findPlugins
void findPlugins(const QString &path, const QStringList &fileNames)
Definition: PluginDialog.inl:64
FEVV::PluginDialog::PluginDialog
PluginDialog(const QString &path, const QStringList &fileNames, QWidget *parent=0)
Definition: PluginDialog.inl:27
FEVV::PluginDialog::addItems
void addItems(QTreeWidgetItem *pluginItem, const char *interfaceName, const QStringList &features)
Definition: PluginDialog.inl:113
FEVV::PluginDialog::treeWidget
QTreeWidget * treeWidget
Definition: PluginDialog.hpp:50
FEVV::PluginDialog::label
QLabel * label
Definition: PluginDialog.hpp:49
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::PluginDialog::featureIcon
QIcon featureIcon
Definition: PluginDialog.hpp:53
PluginInterface.h
FEVV::Generic_PluginInterface::Generic_plugins
virtual QStringList Generic_plugins() const =0
FEVV::PluginDialog::populateTreeWidget
void populateTreeWidget(QObject *plugin, const QString &text)
Definition: PluginDialog.inl:89