-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plug-in management dialog, delete plug-in map
- Loading branch information
Showing
8 changed files
with
255 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#include "PluginsManagerDlg.hpp" | ||
|
||
#include <QTableView> | ||
#include <QPushButton> | ||
#include <QGridLayout> | ||
#include <QHeaderView> | ||
#include <QDir> | ||
#include <QFileDialog> | ||
#include <QDesktopServices> | ||
|
||
#include <QtNodes/NodeDelegateModelRegistry> | ||
#include <QtNodes/PluginInterface> | ||
|
||
using QtNodes::NodeDelegateModelRegistry; | ||
using QtNodes::PluginInterface; | ||
|
||
PluginsManagerDlg:: | ||
PluginsManagerDlg(QWidget* parent) | ||
: QDialog(parent) | ||
, _pluginsFolderPath(R"(./nodes)") | ||
{ | ||
QGridLayout *layout = new QGridLayout(); | ||
setLayout(layout); | ||
|
||
QTableView *pluginTable = new QTableView(); | ||
pluginTable->setSelectionBehavior(QAbstractItemView::SelectRows); | ||
pluginTable->setEditTriggers(QAbstractItemView::NoEditTriggers); | ||
pluginTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | ||
layout->addWidget(pluginTable, 0, 0, 1, 2); | ||
|
||
_model = new QStandardItemModel(pluginTable); | ||
|
||
_model->setColumnCount(2); | ||
_model->setHeaderData(0, Qt::Horizontal, "name"); | ||
_model->setHeaderData(1, Qt::Horizontal, "version"); | ||
pluginTable->setModel(_model); | ||
|
||
loadPluginsFromFolder(); | ||
|
||
// add button | ||
QPushButton *addButton = new QPushButton("+"); | ||
layout->addWidget(addButton, 1, 0); | ||
connect(addButton, &QPushButton::clicked, this, | ||
[this]() | ||
{ | ||
// TODO: How to switch different suffixes according to different os | ||
QString fileName = | ||
QFileDialog::getOpenFileName(this, | ||
tr("Load Plugin"), | ||
QDir::currentPath(), | ||
tr("*.dll;*.so;*.dylib")); | ||
|
||
if (!QFileInfo::exists(fileName)) | ||
return; | ||
|
||
// Copy to the plug-in directory | ||
QFileInfo f(fileName); | ||
QString newPath = _pluginsFolderPath + "/" + f.fileName(); | ||
QFile::copy(fileName, newPath); | ||
|
||
PluginsManager* pluginsManager = PluginsManager::instance(); | ||
auto plugin = pluginsManager->loadPluginFromPath(newPath); | ||
if (plugin == nullptr) | ||
{ | ||
QFile::remove(newPath); | ||
return; | ||
} | ||
|
||
QStandardItem *item = new QStandardItem(plugin->name()); | ||
item->setCheckable(true); | ||
item->setCheckState(Qt::Unchecked); | ||
_model->appendRow(item); | ||
|
||
item->setData(newPath); | ||
|
||
std::shared_ptr<NodeDelegateModelRegistry> reg = pluginsManager->registry(); | ||
plugin->registerDataModels(reg); | ||
}); | ||
|
||
// // delete button | ||
// QPushButton *deleteButton = new QPushButton("-", this); | ||
// layout->addWidget(deleteButton, 1, 1); | ||
// connect(deleteButton, &QPushButton::clicked, this, | ||
// [this]() | ||
// { | ||
// for (int i = 0; i < _model->rowCount(); ++i) | ||
// { | ||
// QStandardItem* item = _model->item(i); | ||
// if(item->checkState() == Qt::Checked) | ||
// { | ||
// PluginsManager* pluginsManager = PluginsManager::instance(); | ||
|
||
// if (pluginsManager->unloadPluginFromName(item->text())) | ||
// { | ||
// qDebug() << item->data().toString(); | ||
// if (QFile::remove(item->data().toString())) | ||
// { | ||
// _model->removeRow(i); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// }); | ||
} | ||
|
||
PluginsManagerDlg:: | ||
~PluginsManagerDlg() | ||
{ | ||
// | ||
} | ||
|
||
void | ||
PluginsManagerDlg:: | ||
openPluginsFolder() | ||
{ | ||
QDesktopServices::openUrl(QUrl::fromLocalFile(_pluginsFolderPath)); | ||
} | ||
|
||
QString | ||
PluginsManagerDlg:: | ||
pluginsFolderPath() const | ||
{ | ||
return _pluginsFolderPath; | ||
} | ||
|
||
void | ||
PluginsManagerDlg:: | ||
loadPluginsFromFolder() | ||
{ | ||
PluginsManager* pluginsManager = PluginsManager::instance(); | ||
std::shared_ptr<NodeDelegateModelRegistry> registry = pluginsManager->registry(); | ||
pluginsManager->loadPlugins(_pluginsFolderPath); | ||
|
||
for(auto l : pluginsManager->loaders()) | ||
{ | ||
PluginInterface* plugin = qobject_cast<PluginInterface*>(l.second->instance()); | ||
if (plugin == nullptr) | ||
continue; | ||
|
||
QStandardItem *item = new QStandardItem(plugin->name()); | ||
item->setCheckable(true); | ||
item->setCheckState(Qt::Unchecked); | ||
_model->appendRow(item); | ||
|
||
item->setData(l.second->fileName()); | ||
|
||
plugin->registerDataModels(registry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <QDialog> | ||
#include <QStandardItemModel> | ||
|
||
#include <QtNodes/PluginsManager> | ||
|
||
using QtNodes::PluginsManager; | ||
|
||
class PluginsManagerDlg : public QDialog | ||
{ | ||
public: | ||
PluginsManagerDlg(QWidget* parent = nullptr); | ||
|
||
virtual | ||
~PluginsManagerDlg(); | ||
|
||
public: | ||
void | ||
openPluginsFolder(); | ||
|
||
QString | ||
pluginsFolderPath() const; | ||
|
||
private: | ||
void | ||
loadPluginsFromFolder(); | ||
|
||
private: | ||
QString _pluginsFolderPath; | ||
|
||
QStandardItemModel* _model = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.