more QString-ization
parent
12fcaa427c
commit
91d7d1d695
|
@ -6,6 +6,7 @@ using namespace Xybrid::Config;
|
|||
#include <unordered_map>
|
||||
|
||||
#include <QMenu>
|
||||
#include <QHash>
|
||||
|
||||
#include "data/graph.h"
|
||||
using namespace Xybrid::Data;
|
||||
|
@ -23,9 +24,9 @@ namespace {
|
|||
}
|
||||
bool& initialized() { static bool b = false; return b; }
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<PluginInfo>> plugins;
|
||||
QHash<QString, std::shared_ptr<PluginInfo>> plugins;
|
||||
|
||||
std::string priorityCategories[] {
|
||||
QString priorityCategories[] {
|
||||
"Gadget", "Instrument", "Effect"
|
||||
};
|
||||
}
|
||||
|
@ -45,29 +46,29 @@ void PluginRegistry::init() {
|
|||
}
|
||||
|
||||
void PluginRegistry::registerPlugin(std::shared_ptr<PluginInfo> pi) {
|
||||
if (pi->id.empty()) return;
|
||||
if (pi->id.isEmpty()) return;
|
||||
if (plugins.find(pi->id) != plugins.end()) return;
|
||||
plugins[pi->id] = pi;
|
||||
// there might be a better way to do this?
|
||||
for (auto& id : pi->oldIds) plugins[id] = pi;
|
||||
}
|
||||
|
||||
std::shared_ptr<Node> PluginRegistry::createInstance(const std::string& id) {
|
||||
std::shared_ptr<Node> PluginRegistry::createInstance(const QString& id) {
|
||||
auto f = plugins.find(id);
|
||||
if (f == plugins.end()) return nullptr;
|
||||
auto n = f->second->createInstance();
|
||||
n->plugin = f->second;
|
||||
auto n = f.value()->createInstance();
|
||||
n->plugin = f.value();
|
||||
n->init();
|
||||
return n;
|
||||
}
|
||||
|
||||
void PluginRegistry::populatePluginMenu(QMenu* m, std::function<void (std::shared_ptr<Node>)> f, Graph* g) {
|
||||
std::map<std::string, std::map<std::string, std::shared_ptr<PluginInfo>>> cm; // category map
|
||||
std::map<QString, std::map<QString, std::shared_ptr<PluginInfo>>> cm; // category map
|
||||
cm.try_emplace(""); // force empty category
|
||||
for (auto& i : plugins) {
|
||||
if (i.second->hidden) continue;
|
||||
cm.try_emplace(i.second->category);
|
||||
cm[i.second->category][i.second->displayName] = i.second;
|
||||
for (auto i : plugins) {
|
||||
if (i->hidden) continue;
|
||||
cm.try_emplace(i->category);
|
||||
cm[i->category][i->displayName] = i;
|
||||
}
|
||||
|
||||
// I/O ports
|
||||
|
@ -112,9 +113,9 @@ void PluginRegistry::populatePluginMenu(QMenu* m, std::function<void (std::share
|
|||
// populate priorities into menu
|
||||
for (auto& pc : priorityCategories) {
|
||||
if (auto c = cm.find(pc); c != cm.end()) {
|
||||
auto* ccm = m->addMenu(QString::fromStdString(c->first));
|
||||
auto* ccm = m->addMenu(c->first);
|
||||
for (auto& i : c->second) {
|
||||
ccm->addAction(QString::fromStdString(i.second->displayName), [f, pi = i.second] {
|
||||
ccm->addAction(i.second->displayName, [f, pi = i.second] {
|
||||
auto n = pi->createInstance();
|
||||
n->plugin = pi;
|
||||
n->init();
|
||||
|
@ -127,10 +128,10 @@ void PluginRegistry::populatePluginMenu(QMenu* m, std::function<void (std::share
|
|||
|
||||
// then any other category
|
||||
for (auto& c : cm) {
|
||||
if (c.first.empty() || c.second.empty()) continue;
|
||||
auto* ccm = m->addMenu(QString::fromStdString(c.first));
|
||||
if (c.first.isEmpty() || c.second.empty()) continue;
|
||||
auto* ccm = m->addMenu(c.first);
|
||||
for (auto& i : c.second) {
|
||||
ccm->addAction(QString::fromStdString(i.second->displayName), [f, pi = i.second] {
|
||||
ccm->addAction(i.second->displayName, [f, pi = i.second] {
|
||||
auto n = pi->createInstance();
|
||||
n->plugin = pi;
|
||||
n->init();
|
||||
|
@ -141,7 +142,7 @@ void PluginRegistry::populatePluginMenu(QMenu* m, std::function<void (std::share
|
|||
|
||||
m->addSeparator();
|
||||
|
||||
for (auto& i : cm[""]) m->addAction(QString::fromStdString(i.second->displayName), [f, pi = i.second] {
|
||||
for (auto& i : cm[""]) m->addAction(i.second->displayName, [f, pi = i.second] {
|
||||
auto n = pi->createInstance();
|
||||
n->plugin = pi;
|
||||
n->init();
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
#include <QString>
|
||||
|
||||
class QMenu;
|
||||
|
||||
namespace Xybrid::Data {
|
||||
|
@ -15,10 +17,10 @@ namespace Xybrid::Data {
|
|||
namespace Xybrid::Config {
|
||||
class PluginInfo {
|
||||
public:
|
||||
std::string id;
|
||||
std::vector<std::string> oldIds;
|
||||
std::string displayName;
|
||||
std::string category;
|
||||
QString id;
|
||||
std::vector<QString> oldIds;
|
||||
QString displayName;
|
||||
QString category;
|
||||
std::function<std::shared_ptr<Data::Node>()> createInstance;
|
||||
bool hidden = false;
|
||||
|
||||
|
@ -31,7 +33,7 @@ namespace Xybrid::Config {
|
|||
void registerPlugin(std::shared_ptr<PluginInfo>);
|
||||
void init();
|
||||
|
||||
std::shared_ptr<Data::Node> createInstance(const std::string& id);
|
||||
std::shared_ptr<Data::Node> createInstance(const QString& id);
|
||||
void populatePluginMenu(QMenu*, std::function<void(std::shared_ptr<Data::Node>)>, Data::Graph* = nullptr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ std::shared_ptr<Port> Port::makePort(DataType dt) {
|
|||
QCborMap Node::toCbor() const {
|
||||
QCborMap m;
|
||||
|
||||
if (plugin) m[qs("id")] = QString::fromStdString(plugin->id);
|
||||
if (!name.empty()) m[qs("name")] = QString::fromStdString(name);
|
||||
if (plugin) m[qs("id")] = plugin->id;
|
||||
if (!name.isEmpty()) m[qs("name")] = name;
|
||||
m[qs("x")] = x;
|
||||
m[qs("y")] = y;
|
||||
saveData(m);
|
||||
|
@ -95,9 +95,9 @@ QCborMap Node::toCbor() const {
|
|||
}
|
||||
|
||||
std::shared_ptr<Node> Node::fromCbor(const QCborMap& m, std::shared_ptr<Graph> parent) {
|
||||
auto ch = PluginRegistry::createInstance(m.value("id").toString().toStdString());
|
||||
auto ch = PluginRegistry::createInstance(m.value("id").toString());
|
||||
ch->parentTo(parent);
|
||||
ch->name = m.value("name").toString().toStdString();
|
||||
ch->name = m.value("name").toString();
|
||||
ch->x = static_cast<int>(m.value("x").toInteger());
|
||||
ch->y = static_cast<int>(m.value("y").toInteger());
|
||||
ch->loadData(m);
|
||||
|
@ -363,4 +363,4 @@ bool Node::try_process(bool checkDependencies) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string Node::pluginName() const { if (!plugin) return "(unknown plugin)"; return plugin->displayName; }
|
||||
QString Node::pluginName() const { if (!plugin) return qs("(unknown plugin)"); return plugin->displayName; }
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <string>
|
||||
#include <atomic>
|
||||
|
||||
#include <QString>
|
||||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
#include <QObject>
|
||||
|
@ -60,7 +61,7 @@ namespace Xybrid::Data {
|
|||
|
||||
QPointer<UI::PortObject> obj;
|
||||
|
||||
std::string name;
|
||||
QString name;
|
||||
|
||||
virtual ~Port();
|
||||
Port() = default;
|
||||
|
@ -88,7 +89,7 @@ namespace Xybrid::Data {
|
|||
Project* project;
|
||||
std::weak_ptr<Graph> parent;
|
||||
int x{}, y{};
|
||||
std::string name;
|
||||
QString name;
|
||||
|
||||
std::map<Port::DataType, std::map<uint8_t, std::shared_ptr<Port>>> inputs, outputs;
|
||||
|
||||
|
@ -125,7 +126,7 @@ namespace Xybrid::Data {
|
|||
virtual void saveData(QCborMap&) const { }
|
||||
virtual void loadData(const QCborMap&) { }
|
||||
|
||||
virtual std::string pluginName() const;
|
||||
virtual QString pluginName() const;
|
||||
/// If true, excluded from copy/paste operations.
|
||||
virtual bool isVolatile() const { return false; }
|
||||
|
||||
|
|
|
@ -338,8 +338,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(socket, &UISocket::openGraph, this, [this](Graph* g) {
|
||||
if (!g) return;
|
||||
auto gg = std::static_pointer_cast<Graph>(g->shared_from_this());
|
||||
QString name = QString::fromStdString(gg->name);
|
||||
if (name.isEmpty()) name = QString::fromStdString(gg->pluginName());
|
||||
QString name = gg->name;
|
||||
if (name.isEmpty()) name = gg->pluginName();
|
||||
ui->patchboardBreadcrumbs->push(name, this, [this, gg] {
|
||||
openGraph(gg);
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@ void PortObject::setHighlighted(bool h, bool hideLabel) {
|
|||
return f;
|
||||
}();
|
||||
QString txt = QString("%1 %2").arg(Util::enumName(port->dataType()).toLower()).arg(Util::hex(port->index));
|
||||
if (!port->name.empty()) txt = QString("%1 (%2)").arg(QString::fromStdString(port->name)).arg(txt);
|
||||
if (!port->name.isEmpty()) txt = QString("%1 (%2)").arg(port->name).arg(txt);
|
||||
QColor c = tcolor[port->dataType()];
|
||||
label->setFont(f);
|
||||
label->setText(txt);
|
||||
|
@ -243,12 +243,12 @@ void NodeObject::contextMenuEvent(QGraphicsSceneContextMenuEvent* e) {
|
|||
if (canRename) {
|
||||
m->addAction("Rename...", this, [this] {
|
||||
bool ok = false;
|
||||
auto cn = node->name.empty() ? QString::fromStdString(node->pluginName()) : QString("\"%1\"").arg(QString::fromStdString(node->name));
|
||||
auto cn = node->name.isEmpty() ? node->pluginName() : QString("\"%1\"").arg(node->name);
|
||||
auto capt = QString("Rename %1:").arg(cn);
|
||||
auto n = QInputDialog::getText(nullptr, "Rename...", capt, QLineEdit::Normal, QString::fromStdString(node->name), &ok);
|
||||
auto n = QInputDialog::getText(nullptr, "Rename...", capt, QLineEdit::Normal, node->name, &ok);
|
||||
if (!ok) return; // canceled
|
||||
//setToolTip(n);
|
||||
node->name = n.toStdString();
|
||||
node->name = n;
|
||||
node->onRename();
|
||||
updateGeometry();
|
||||
update();
|
||||
|
@ -324,7 +324,7 @@ qreal NodeObject::nameSize() const {
|
|||
qreal n = 0;
|
||||
if (showName) {
|
||||
if (showPluginName) n++;
|
||||
if (!node->name.empty()) n++;
|
||||
if (!node->name.isEmpty()) n++;
|
||||
}
|
||||
if (n > 0) {
|
||||
n *= QFontMetrics(QFont()).height();
|
||||
|
@ -382,14 +382,14 @@ void NodeObject::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, Q
|
|||
|
||||
painter->setFont(f);
|
||||
QRectF tr = r - QMarginsF(edgePad, edgePad - 1, edgePad, 0);
|
||||
if (!node->name.empty()) {
|
||||
if (!node->name.isEmpty()) {
|
||||
painter->setPen(QColor(222, 222, 222));
|
||||
painter->drawText(tr, Qt::AlignLeft, QString::fromStdString(node->name));
|
||||
painter->drawText(tr, Qt::AlignLeft, node->name);
|
||||
tr -= QMarginsF(0, painter->fontMetrics().height(), 0, 0);
|
||||
}
|
||||
if (showPluginName) {
|
||||
painter->setPen(QColor(171, 171, 171));
|
||||
painter->drawText(tr, Qt::AlignLeft, QString::fromStdString(node->pluginName()));
|
||||
painter->drawText(tr, Qt::AlignLeft, node->pluginName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue