-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsectorswidget.cpp
More file actions
81 lines (67 loc) · 1.77 KB
/
sectorswidget.cpp
File metadata and controls
81 lines (67 loc) · 1.77 KB
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 "graphicssectorswidget.h"
#include "sectorswidget.h"
#include "tablesectorswidget.h"
#include "tools.h"
#include <QTabWidget>
#include <QVBoxLayout>
SectorsWidget::SectorsWidget(QWidget *parent) :
QWidget(parent), graphicsWidget(0), tableWidget(0), pModel(0)
{
QVBoxLayout * mainLayout = new QVBoxLayout(this);
tabWidget = new QTabWidget;
mainLayout->addWidget(tabWidget);
setModel(new SectorsModel());
}
void SectorsWidget::setModel(SectorsModel *model)
{
if (!graphicsWidget)
{
graphicsWidget = new GraphicsSectorsWidget;
tabWidget->addTab(graphicsWidget, tr("graphics"));
}
graphicsWidget->setModel(model);
graphicsWidget->setSuffix(QChar(0x00B0));
if (!tableWidget)
{
tableWidget = new TableSectorsWidget;
tabWidget->addTab(tableWidget, tr("table"));
}
tableWidget->setModel(model);
if (pModel)
{
delete pModel;
pModel = model;
}
connect(model, SIGNAL(sectorIntersected(Sector, QList<Sector>)),
this, SLOT(onSectorIntersected(Sector, QList<Sector>)));
}
QList<Sector> SectorsWidget::sectors()
{
if (pModel)
{
return pModel->sectors();
}
return QList<Sector>();
}
void SectorsWidget::onSectorIntersected(Sector newSector, QList<Sector> intersectedSectors)
{
QStringList sectorsList;
int i = 1;
sectorsList.append(QString("%1)%2 - %3").arg(i).arg(newSector.begin).arg(newSector.end));
foreach (Sector sector, intersectedSectors)
{
sectorsList.append(QString("%1)%2 - %3").arg(++i).arg(sector.begin).arg(sector.end));
}
QString title = "Intersected sectors";
QString text = "You want to merge the sectors?";
if (!Tools::question(this, title, text, sectorsList.join("\n")))
{
return;
}
SectorsModel *model = qobject_cast<SectorsModel*>(sender());
if (!model)
{
return;
}
model->uniteSectors(newSector, intersectedSectors);
}