ExpressionMenu.hpp
1 #pragma once
2 #include <State/Expression.hpp>
3 
4 #include <QAction>
5 #include <QInputDialog>
6 #include <QMenu>
7 #include <QObject>
8 
9 #include <verdigris>
10 
11 namespace Scenario
12 {
13 // TODO use me with condition also.
14 class ExpressionMenu : public QObject
15 {
16  W_OBJECT(ExpressionMenu)
17 public:
18  // Fun should be a function that returns an expression
19  template <typename Fun>
20  ExpressionMenu(Fun f, QWidget* parent)
21  : menu{new QMenu{parent}}
22  , deleteAction{menu->addAction(QObject::tr("Disable"))}
23  , editAction{menu->addAction(QObject::tr("Edit"))}
24  {
25  connect(editAction, &QAction::triggered, this, [this, f = std::move(f)] {
26  bool ok = false;
27  auto str = QInputDialog::getText(
28  nullptr, tr("Edit expression"), tr("Edit expression"), QLineEdit::Normal,
29  f().toString(), &ok);
30  if(ok)
31  expressionChanged(std::move(str));
32  });
33  }
34 
35  QMenu* menu{};
36  QAction* deleteAction{};
37  QAction* editAction{};
38 
39 public:
40  void expressionChanged(QString arg_1) W_SIGNAL(expressionChanged, arg_1);
41 };
42 }
Definition: ExpressionMenu.hpp:15
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14