-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidget.cpp
81 lines (70 loc) · 2.18 KB
/
widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "widget.hpp"
#include "mainscene.hpp"
#include "ndaalgorithm.hpp"
#include <QGridLayout>
#include <QGraphicsView>
#include <QTableView>
#include <QToolBar>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QHeaderView>
Widget::Widget(QWidget *parent)
: QMainWindow(parent)
{
mToolBar = new QToolBar("Instrument bar");
mToolBar->setAllowedAreas(Qt::TopToolBarArea);
addToolBar(mToolBar);
mScene = new MainScene;
mGraphicsView = new QGraphicsView(mScene, this);
mTableView = new QTableView;
mTableView->verticalHeader()->hide();
QWidget *mainWidget = new QWidget(this);
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(mGraphicsView, 0, 0);
mainLayout->addWidget(mTableView, 0, 2);
mainLayout->setColumnStretch(0, 50);
mainLayout->setColumnStretch(2, 25);
mainWidget->setLayout(mainLayout);
setCentralWidget(mainWidget);
QMenu *menu = menuBar()->addMenu(tr("Edit"));
menu->addAction(tr("Clear"), this, SLOT(clearScene()));
registerAlgorithm(new NDAAlgorithm(mScene));
}
Widget::~Widget()
{
delete mToolBar;
delete mScene;
delete mGraphicsView;
delete mTableView;
}
void Widget::registerAlgorithm(AlgorithmInterface *algorithm)
{
QAction *action = mToolBar->addAction(algorithm->icon(), algorithm->name());
action->setToolTip(algorithm->name());
connect(action, SIGNAL(triggered()), algorithm, SLOT(activate()));
connect(algorithm, SIGNAL(algorithmActivated()), this, SLOT(algorithmChanged()));
mRegisteredAlg2Action[algorithm] = action;
}
void Widget::unregisterAlgorithm(AlgorithmInterface *algorithm)
{
if (!mRegisteredAlg2Action.contains(algorithm))
return;
QAction *action = mRegisteredAlg2Action.value(algorithm);
action->setCheckable(true);
mToolBar->removeAction(action);
disconnect(action, SIGNAL(triggered()));
disconnect(algorithm, SIGNAL(algorithmActivated()));
}
void Widget::clearScene()
{
mScene->clear();
mScene->createNet();
}
void Widget::algorithmChanged()
{
AlgorithmInterface *alg = static_cast<AlgorithmInterface*>(sender());
if (!alg)
return;
mTableView->setModel(alg->calculationTable());
}