-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeMapWindow.cpp
More file actions
231 lines (186 loc) · 6.71 KB
/
TreeMapWindow.cpp
File metadata and controls
231 lines (186 loc) · 6.71 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//This is the hacked up version
/*
* Copyright (c) 2010 Mark Liversedge (liversedge@gmail.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "DataManager.h"
#include "DataMgrVect.h"
#include "TreeMapWindow.h"
#include "TreeMapPlot.h"
#include <qscrollarea.h>
#include <QtGui>
#include <QString>
#include <QVBoxLayout>
#include <qformlayout.h>
#include <iostream>
//Constructor
TreeMapWindow::TreeMapWindow(DataManager * dataManager, AppSettings * appSettings, bool useTreeMapLabels)
{
this->dataManager = dataManager;
this->appSettings = appSettings;
scrollArea = new MyScrollArea;
// the plot
mainLayout = new QHBoxLayout; //Lines widgets up horizontally
ltmPlot = new TreeMapPlot(this, dataManager, appSettings, useTreeMapLabels);
ltmPlot->resize(800, 800);
scrollArea->setWidget(ltmPlot);
scrollArea->setFrameStyle(QFrame::NoFrame);
placeholder = new QWidget();
colorBar = new QFrame();
QSizePolicy plotPolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
plotPolicy.setHorizontalStretch(90);
scrollArea->setSizePolicy(plotPolicy);
QSizePolicy placeholderPolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
placeholderPolicy.setHorizontalStretch(4);
placeholder->setSizePolicy(placeholderPolicy);
placeholder->setMaximumWidth(50);
QSizePolicy colorBarPolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
colorBarPolicy.setHorizontalStretch(6);
colorBar->setSizePolicy(colorBarPolicy);
colorBar->setFrameStyle(QFrame::Box);
colorBar->setMinimumWidth(30);
colorBar->setMaximumWidth(50);
mainLayout->addWidget(scrollArea);
mainLayout->addWidget(placeholder);
mainLayout->addWidget(colorBar);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
setLayout(mainLayout);
QPalette myPalette(palette());
myPalette.setColor(QPalette::Background, QColor(255, 255, 255, 255));
this->setPalette(myPalette);
this->setAutoFillBackground(true);
placeholder->setPalette(myPalette);
placeholder->setAutoFillBackground(true);
rebuildGradient();
// user clicked on a cell in the plot
connect(ltmPlot, SIGNAL(clicked(QString, QString)), this, SLOT(cellClicked(QString, QString)));
}
//This function builds/rebuilds the color map gradient
void TreeMapWindow::rebuildGradient()
{
QLinearGradient gradient(0, 0, 0, this->rect().height());
const double INCREMENT = 0.01;
double color[3];
if (appSettings->useEntropyForTreeMapColor) {
double minEntropy = ((DataMgrVect *)dataManager)->getMinEntropy();
double maxEntropy = ((DataMgrVect *)dataManager)->getMaxEntropy();
//Build the gradient for the color bar
const int NUM_ITERATIONS = 100;
for (double i = minEntropy; i <= maxEntropy; i += (maxEntropy - minEntropy) / NUM_ITERATIONS) {
((DataMgrVect *)dataManager)->getEntropyColor(i, color);
gradient.setColorAt(1.0 - (i - minEntropy) / (maxEntropy - minEntropy), QColor(255 * color[0], 255 * color[1], 255 * color[2], 255));
}
}
else {
double minVolume = ((DataMgrVect *)dataManager)->getMinVolume();
double maxVolume = ((DataMgrVect *)dataManager)->getMaxVolume();
//Build the gradient for the color bar
const int NUM_ITERATIONS = 100;
for (double i = minVolume; i <= maxVolume; i += (maxVolume - minVolume) / NUM_ITERATIONS) {
((DataMgrVect *)dataManager)->getVolumeColor(i, color);
gradient.setColorAt(1.0 - (i - minVolume) / (maxVolume - minVolume), QColor(255 * color[0], 255 * color[1], 255 * color[2], 255));
}
}
QPalette palette;
palette.setBrush(QPalette::Background, QBrush(gradient));
colorBar->setPalette(palette);
colorBar->setAutoFillBackground(true);
}
TreeMapWindow::~TreeMapWindow()
{
delete placeholder;
delete colorBar;
delete ltmPlot;
}
void
TreeMapWindow::refreshPlot(NodeBi * root)
{
ltmPlot->setData(root);
}
void
TreeMapWindow::cellClicked(QString f1, QString f2)
{
//This appears to be code from Golden Cheetah for generating a popup with information from the click. We will probably just strip this out after verifying it is useless to us.
/*
QStringList match;
// create a list of activities in this cell
int count = 0;
foreach(RideItem *item, context->athlete->rideCache->rides()) {
// honour the settings
if (!settings.specification.pass(item)) continue;
// text may either not exists, then "unknown" or just be "" but f1, f2 don't know ""
QString x1 = item->getText(settings.field1, tr("(unknown)"));
QString x2 = item->getText(settings.field2, tr("(unknown)"));
if (x1 == "") x1 = tr("(unknown)");
if (x2 == "") x2 = tr("(unknown)");
// match !
if (x1 == f1 && x2 == f2) {
match << item->fileName;
count++;
}
}
// create a specification for ours
Specification spec;
spec.setDateRange(settings.specification.dateRange());
FilterSet fs = settings.specification.filterSet();
fs.addFilter(true, match);
spec.setFilterSet(fs);
// and the metric to display
const RideMetricFactory &factory = RideMetricFactory::instance();
const RideMetric *metric = factory.rideMetric(settings.symbol);
ltmPopup->setData(spec, metric, QString(tr("%1 activities")).arg(count));
popup->show();
*/
std::cout << "Clicked in the tree map window " << std::endl;
}
const double EPSILON2 = 1e-02;
#ifndef QT_NO_WHEELEVENT
void TreeMapWindow::wheelEvent(QWheelEvent *event)
{
//cout << "Scroll wheel event " << << endl;
double factor = 1;
if (abs(event->delta()) < EPSILON2) {
factor = 1;
}
else if (event->delta() > 0) {
factor = event->delta() / 100.0;
}
else if (event->delta() < 0) {
factor = 1 / (fabs(event->delta() / 100.0));
}
QPoint point = event->pos();
int x = point.x();
int y = point.y();
zoom(factor, x, y);
}
void TreeMapWindow::zoom(double factor, int x, int y)
{
int width = ltmPlot->width();
int height = ltmPlot->height();
//cout << "Zoom method called. Factor: " << factor << " Width: " << width << " Height: " << height << endl;
ltmPlot->setFixedSize(width * factor, height*factor);
}
#endif
//This method responds to resize events, rebuilding the color map gradient according to the window height
void TreeMapWindow::resizeEvent(QResizeEvent * event)
{
rebuildGradient();
}
void TreeMapWindow::updateChildren()
{
ltmPlot->update();
}