-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphinspector.cpp
147 lines (121 loc) · 4.3 KB
/
graphinspector.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/******************************
graphInspector
Инспектор графиков
Позволяет изменять лист из графиков.
Особенности:
-В листе должен быть как минимум 1 график
-Следит за распределением памяти
-Довавление/удаление графиков
-Взаимодействует с внешним миром при помощи:
1)сигнала needToRedraw(перерисовать графики)
2)функции getCurrentIndex(чтобы узнать текущий
график)
+удаление всех графиков при выходе сделать из вне
(mainWindow).
******************************/
#include "graphinspector.h"
graphInspector::graphInspector(QWidget *parent, QList<graphObject*>* list) : QWidget(parent)
{
int i;
setupUi(this);
styleEdit->addItem(QString::fromUtf8("Сплошной"));
styleEdit->addItem(QString::fromUtf8("Штрих"));
styleEdit->addItem(QString::fromUtf8("Точка"));
styleEdit->addItem(QString::fromUtf8("Штрих-точка"));
graphs = list;
for(i=0;i<graphs->count();i++) graphBox->addItem(graphs->at(i)->description );
QObject::connect(graphBox, SIGNAL(activated(int)), this, SLOT(changeSelection(int)));
QObject::connect(widthEdit, SIGNAL(valueChanged(int)), this, SLOT(changeWidth(int)));
QObject::connect(colorEdit, SIGNAL(clicked()), this, SLOT(changeColor()));
QObject::connect(descriptionEdit, SIGNAL(textEdited(QString)),this, SLOT(changeDescription(QString)));
QObject::connect(drawableEdit, SIGNAL(stateChanged(int)), this, SLOT(changeDrawable(int)));
QObject::connect(addEdit, SIGNAL(clicked()), this, SLOT(add()));
QObject::connect(removeEdit, SIGNAL(clicked()), this, SLOT(remove()));
QObject::connect(styleEdit, SIGNAL(activated(int)), this, SLOT(changeStyle(int)));
graphBox->setCurrentIndex(0);
changeSelection(0);
}
void graphInspector::changeSelection(int a)
{
descriptionEdit->setText(graphs->at(a)->description);
widthEdit->setValue(graphs->at(a)->pen.width());
drawableEdit->setCheckState(graphs->at(a)->drawable? Qt::Checked : Qt::Unchecked);
colorEdit->setPalette(QPalette(graphs->at(a)->pen.color()));
styleEdit->setCurrentIndex(graphs->at(a)->pen.style()-1);
}
void graphInspector::changeWidth(int width)
{
graphs->at(graphBox->currentIndex())->pen.setWidth(width);
emit needToRedraw();
}
void graphInspector::changeColor()
{
QPen* pen = &(graphs->at(graphBox->currentIndex())->pen);
pen->setColor(QColorDialog::getColor(pen->color(),parentWidget()));
colorEdit->setPalette(pen->color());
emit needToRedraw();
}
void graphInspector::changeDescription(QString string)
{
graphs->at(graphBox->currentIndex())->description = string;
graphBox->setItemText(graphBox->currentIndex(), string);
emit needToRedraw();
}
void graphInspector::changeDrawable(int a)
{
graphs->at(graphBox->currentIndex())->drawable = !a ? false : true;
emit needToRedraw();
}
void graphInspector::changeStyle(int a)
{
Qt::PenStyle b = Qt::SolidLine;
switch(a)
{
case 0:
b = Qt::SolidLine;
break;
case 1:
b = Qt::DashLine;
break;
case 2:
b = Qt::DotLine;
break;
case 3:
b = Qt::DashDotLine;
break;
}
graphs->at(graphBox->currentIndex())->pen.setStyle(b);
emit needToRedraw();
}
void graphInspector::add()
{
int i = graphs->count();
graphObject* obj = new graphObject;
obj->description = QString::fromUtf8("Новая кривая ") + QString::number(i+1);
/*Небольшой бонус ;)*/
if(graphs->count() < 12) obj->pen.setColor(Qt::GlobalColor(graphs->count()+6)); /*Автоматически устанавливается цвет*/
/*Конец*/
graphs->append(obj);
graphBox->addItem(graphs->at(i)->description);
graphBox->setCurrentIndex(i);
changeSelection(i);
descriptionEdit->setFocus();
}
void graphInspector::remove()
{
int i = graphBox->currentIndex();
/*Чтобы не удалили все*/
if(graphs->count() == 1) return;
if(graphs->at(i)->data != NULL) free(graphs->at(i)->data);
delete graphs->at(i);
graphs->removeAt(i);
graphBox->removeItem(i);
if(i == graphs->count()) i--;
graphBox->setCurrentIndex(i);
changeSelection(i);
emit needToRedraw();
}
int graphInspector::getCurrentIndex()
{
return graphBox->currentIndex();
}