-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplaygroup.cpp
More file actions
136 lines (111 loc) · 3.43 KB
/
displaygroup.cpp
File metadata and controls
136 lines (111 loc) · 3.43 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
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
#include "displaygroup.h"
using namespace Mildred;
/*
* Targets
*/
// Add target data entity to group
void DisplayGroup::addTarget(Mildred::DataEntity *entity)
{
auto it = std::find(targets_.begin(), targets_.end(), entity);
if (it != targets_.end())
return;
targets_.emplace_back(entity);
applyToEntity(entity, targets_.size() - 1);
}
// Remove data entity from group
void DisplayGroup::removeTarget(DataEntity *entity)
{
auto it = std::remove(targets_.begin(), targets_.end(), entity);
if (it != targets_.end())
targets_.erase(it);
// TODO update all entities
}
/*
* Colouring
*/
// Stock Colours
QColor StockColours[] = {
QColor(0, 0, 0), /* BlackStockColour */
QColor(200, 0, 0), /* RedStockColour */
QColor(0, 200, 0), /* GreenStockColour */
QColor(0, 0, 200), /* BlueStockColour */
QColor(200, 0, 200), /* PurpleStockColour */
QColor(0, 200, 200), /* CyanStockColour */
QColor(255, 128, 0), /* OrangeStockColour */
QColor(255, 100, 255), /* PinkStockColour */
QColor(255, 100, 100), /* LightRedStockColour */
QColor(100, 255, 100), /* LightGreenStockColour */
QColor(100, 100, 255), /* LightBlueStockColour */
QColor(128, 128, 128), /* SilverStockColour */
QColor(128, 128, 50) /* GoldStockColour */
};
// Set colour policy for the group
void DisplayGroup::setColourPolicy(DisplayGroup::ColourPolicy policy)
{
if (colourPolicy_ == policy)
return;
colourPolicy_ = policy;
apply();
}
// Return colour policy for the group
DisplayGroup::ColourPolicy DisplayGroup::colourPolicy() const { return colourPolicy_; }
// Set single colour
void DisplayGroup::setSingleColour(QColor colour)
{
singleColour_ = colour;
if (colourPolicy_ == ColourPolicy::Single)
apply();
}
// Return single colour
QColor DisplayGroup::singleColour() const { return singleColour_; }
// Set stock colour
void DisplayGroup::setStockColour(StockColour colour)
{
stockColour_ = colour;
if (colourPolicy_ == ColourPolicy::Stock)
apply();
}
// Return stock colour
DisplayGroup::StockColour DisplayGroup::stockColour() const { return stockColour_; }
// Set gradient to apply
void DisplayGroup::setGradient(const ColourDefinition &gradient)
{
gradient_ = gradient;
if (colourPolicy_ == ColourPolicy::Gradient)
apply();
}
// Return gradient to apply
const ColourDefinition &DisplayGroup::gradient() const { return gradient_; }
/*
* Update
*/
// Apply colours and transforms to specified entity
void DisplayGroup::applyToEntity(DataEntity *entity, int groupIndex)
{
// Colour
switch (colourPolicy_)
{
case (ColourPolicy::None):
entity->removeColourOverride();
break;
case (ColourPolicy::Stock):
entity->setColourOverride(ColourDefinition(StockColours[stockColour_]));
break;
case (ColourPolicy::Single):
entity->setColourOverride(ColourDefinition(singleColour_));
break;
case (ColourPolicy::Varying):
entity->setColourOverride(ColourDefinition(StockColours[groupIndex % nStockColours]));
break;
case (ColourPolicy::Gradient):
entity->setColourOverride(gradient_);
break;
}
}
// Apply colours and transforms to all targeted entities
void DisplayGroup::apply()
{
auto index = 0;
for (auto &entity : targets_)
applyToEntity(entity, index++);
}