3
* TOra - An Oracle Toolkit for DBA's and developers
4
* Copyright (C) 2003-2005 Quest Software, Inc
5
* Portions Copyright (C) 2005 Other Contributors
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; only version 2 of
10
* the License is valid for this program.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* As a special exception, you have permission to link this program
22
* with the Oracle Client libraries and distribute executables, as long
23
* as you follow the requirements of the GNU GPL in regard to all of the
24
* software in the executable aside from Oracle client libraries.
26
* Specifically you are not permitted to link this program with the
27
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
* And you are not permitted to distribute binaries compiled against
29
* these libraries without written consent from Quest Software, Inc.
30
* Observe that this does not disallow linking to the Qt Free Edition.
32
* You may link this product with any GPL'd Qt library such as Qt/Free
34
* All trademarks belong to their respective owners.
2
/* BEGIN_COMMON_COPYRIGHT_HEADER
4
* TOra - An Oracle Toolkit for DBA's and developers
6
* Shared/mixed copyright is held throughout files in this product
8
* Portions Copyright (C) 2000-2001 Underscore AB
9
* Portions Copyright (C) 2003-2005 Quest Software, Inc.
10
* Portions Copyright (C) 2004-2008 Numerous Other Contributors
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; only version 2 of
15
* the License is valid for this program.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
* As a special exception, you have permission to link this program
27
* with the Oracle Client libraries and distribute executables, as long
28
* as you follow the requirements of the GNU GPL in regard to all of the
29
* software in the executable aside from Oracle client libraries.
31
* Specifically you are not permitted to link this program with the
32
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
33
* And you are not permitted to distribute binaries compiled against
36
* You may link this product with any GPL'd Qt library.
38
* All trademarks belong to their respective owners.
40
* END_COMMON_COPYRIGHT_HEADER */
41
45
#include "toconf.h"
42
46
#include "tolinechart.h"
43
47
#include "topiechart.h"
44
#include "toresultview.h"
48
#include "toresulttableview.h"
49
#include "toresultmodel.h"
45
50
#include "tovisualize.h"
47
52
#include <qcombobox.h>
48
53
#include <qlabel.h>
49
54
#include <qtoolbar.h>
50
55
#include <qtoolbutton.h>
53
#include "tovisualize.moc"
57
#include <QVBoxLayout>
55
60
#include "icons/axis.xpm"
56
61
#include "icons/execute.xpm"
57
62
#include "icons/grid.xpm"
58
63
#include "icons/legend.xpm"
60
toVisualize::toVisualize(toListView *source, QWidget *parent, const char *name)
61
: QVBox(parent, name), Source(source)
65
toVisualize::toVisualize(toResultTableView *source, QWidget *parent, const char *name)
66
: QWidget(parent), Source(source)
72
QVBoxLayout *vbox = new QVBoxLayout;
74
vbox->setContentsMargins(0, 0, 0, 0);
63
77
QToolBar *toolbar = toAllocBar(this, tr("Data visualization"));
78
vbox->addWidget(toolbar);
65
Type = new QComboBox(toolbar, TO_TOOLBAR_WIDGET_NAME);
66
Type->insertItem(tr("Bar chart"), 0);
67
Type->insertItem(tr("Line chart"), 1);
68
Type->insertItem(tr("Pie chart"), 2);
80
Type = new QComboBox(toolbar);
81
Type->setObjectName(TO_TOOLBAR_WIDGET_NAME);
82
Type->addItem(tr("Bar chart"), 0);
83
Type->addItem(tr("Line chart"), 1);
84
Type->addItem(tr("Pie chart"), 2);
85
toolbar->addWidget(Type);
70
87
toolbar->addSeparator();
72
89
Legend = new QToolButton(toolbar);
73
Legend->setToggleButton(true);
74
Legend->setIconSet(QIconSet(QPixmap(const_cast<const char**>(legend_xpm))));
76
(Legend, tr("Display legend"));
90
Legend->setCheckable(true);
91
Legend->setIcon(QIcon(QPixmap(const_cast<const char**>(legend_xpm))));
92
Legend->setToolTip(tr("Display legend"));
93
Legend->setChecked(true);
94
toolbar->addWidget(Legend);
79
96
Grid = new QToolButton(toolbar);
80
Grid->setToggleButton(true);
81
Grid->setIconSet(QIconSet(QPixmap(const_cast<const char**>(grid_xpm))));
83
(Grid, tr("Display grid"));
97
Grid->setCheckable(true);
98
Grid->setIcon(QIcon(QPixmap(const_cast<const char**>(grid_xpm))));
99
Grid->setToolTip(tr("Display grid"));
100
Grid->setChecked(true);
101
toolbar->addWidget(Grid);
86
103
Axis = new QToolButton(toolbar);
87
Axis->setToggleButton(true);
88
Axis->setIconSet(QIconSet(QPixmap(const_cast<const char**>(axis_xpm))));
90
(Axis, tr("Display axis legend"));
94
(new QLabel(" " + tr("Title columns") + " ", toolbar),
95
tr("Number of columns to use as title"));
96
Title = new QComboBox(toolbar, TO_TOOLBAR_WIDGET_NAME);
97
Title->insertItem(QString::fromLatin1("1"));
98
Title->insertItem(QString::fromLatin1("2"));
99
Title->insertItem(QString::fromLatin1("3"));
100
Title->insertItem(QString::fromLatin1("4"));
101
Title->insertItem(QString::fromLatin1("5"));
102
Title->insertItem(QString::fromLatin1("6"));
104
Axis->setCheckable(true);
105
Axis->setIcon(QIcon(QPixmap(const_cast<const char**>(axis_xpm))));
106
Axis->setToolTip(tr("Display axis legend"));
107
Axis->setChecked(true);
108
toolbar->addWidget(Axis);
110
QLabel *title = new QLabel(tr("Title columns"));
111
title->setToolTip(tr("Number of columns to use as title"));
112
toolbar->addWidget(title);
114
Title = new QComboBox(toolbar);
115
setObjectName(TO_TOOLBAR_WIDGET_NAME);
116
Title->addItem(QString::fromLatin1("1"));
117
Title->addItem(QString::fromLatin1("2"));
118
Title->addItem(QString::fromLatin1("3"));
119
Title->addItem(QString::fromLatin1("4"));
120
Title->addItem(QString::fromLatin1("5"));
121
Title->addItem(QString::fromLatin1("6"));
122
toolbar->addWidget(Title);
104
124
toolbar->addSeparator();
106
new QToolButton(QPixmap(const_cast<const char**>(execute_xpm)),
109
this, SLOT(display(void)),
126
toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(execute_xpm))),
129
SLOT(display(void)));
112
toolbar->setStretchableWidget(new QLabel(toolbar, TO_TOOLBAR_WIDGET_NAME));
131
QLabel *s = new QLabel(toolbar);
132
s->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
133
QSizePolicy::Minimum));
134
toolbar->addWidget(s);
114
136
Result = new QWidget(this);
115
Result->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
137
Result->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
138
QSizePolicy::Expanding));
139
vbox->addWidget(Result);
118
142
void toVisualize::display(void)
120
144
QWidget *last = Result;
121
switch (Type->currentItem())
145
toResultModel *model = Source->model();
147
switch (Type->currentIndex())
125
toBarChart *chart = new toBarChart(this);
126
chart->showLegend(Legend->isOn());
129
int tit = std::max(1, Title->currentText().toInt());
130
if (Source->columnText(0) == QString::fromLatin1("#"))
133
chart->setTitle(Source->columnText(add
135
chart->showGrid(Grid->isOn() ? 5 : 0);
136
chart->showAxisLegend(Axis->isOn());
139
std::list<QString> lst;
140
for (int i = tit + add
141
;i < Source->columns();i++)
142
toPush(lst, Source->columnText(i));
143
chart->setLabels(lst);
145
for (QListViewItem *item = Source->firstChild();item;item = item->nextSibling())
147
QString label = item->text(add
153
label += QString::fromLatin1(", ");
154
label += item->text(j);
156
std::list<double> val;
157
for (int i = tit + add
158
;i < Source->columns();i++)
160
toPush(val, item->text(i).toDouble());
162
chart->addValues(val, label);
152
toBarChart *chart = new toBarChart(this);
153
layout()->addWidget(chart);
154
chart->showLegend(Legend->isChecked());
155
int tit = std::max(1, Title->currentText().toInt()) +
156
Source->numberColumn();
158
model->headerData(Source->numberColumn(),
159
Qt::Horizontal, Qt::DisplayRole).toString());
160
chart->showGrid(Grid->isChecked() ? 5 : 0);
161
chart->showAxisLegend(Axis->isChecked());
164
std::list<QString> lst;
165
for (int i = tit; i < model->columnCount(); i++)
168
model->headerData(i, Qt::Horizontal, Qt::DisplayRole)
171
chart->setLabels(lst);
173
for (int row = 0; row < model->rowCount(); row++)
175
QModelIndex index = model->createIndex(row, Source->numberColumn());
176
QString label = model->data(index, Qt::EditRole).toString();
177
for (int j = 1; j < tit; j++)
179
QModelIndex index = model->createIndex(row, j);
180
label += QString::fromLatin1(", ");
181
label += model->data(index, Qt::EditRole).toString();
184
std::list<double> val;
186
for (int i = tit; i < model->columnCount(); i++)
188
QModelIndex index = model->createIndex(row, i);
189
toPush(val, model->data(index, Qt::EditRole).toDouble());
192
chart->addValues(val, label);
169
toLineChart *chart = new toLineChart(this);
170
chart->showLegend(Legend->isOn());
173
int tit = std::max(1, Title->currentText().toInt());
174
if (Source->columnText(0) == QString::fromLatin1("#"))
177
chart->setTitle(Source->columnText(add
179
chart->showGrid(Grid->isOn() ? 5 : 0);
180
chart->showAxisLegend(Axis->isOn());
183
std::list<QString> lst;
184
for (int i = tit + add
185
;i < Source->columns();i++)
186
toPush(lst, Source->columnText(i));
187
chart->setLabels(lst);
189
for (QListViewItem *item = Source->firstChild();item;item = item->nextSibling())
191
QString label = item->text(add
197
label += QString::fromLatin1(", ");
198
label += item->text(j);
200
std::list<double> val;
201
for (int i = tit + add
202
;i < Source->columns();i++)
204
toPush(val, item->text(i).toDouble());
206
chart->addValues(val, label);
201
toLineChart *chart = new toLineChart(this);
202
layout()->addWidget(chart);
203
chart->showLegend(Legend->isChecked());
204
int tit = std::max(1, Title->currentText().toInt()) +
205
Source->numberColumn();
207
model->headerData(Source->numberColumn(),
208
Qt::Horizontal, Qt::DisplayRole).toString());
209
chart->showGrid(Grid->isChecked() ? 5 : 0);
210
chart->showAxisLegend(Axis->isChecked());
213
std::list<QString> lst;
214
for (int i = tit; i < model->columnCount(); i++)
216
toPush(lst, model->headerData(
219
Qt::DisplayRole).toString());
221
chart->setLabels(lst);
223
for (int row = 0; row < model->rowCount(); row++)
225
QModelIndex index = model->createIndex(row, Source->numberColumn());
226
QString label = model->data(index, Qt::EditRole).toString();
227
for (int j = 1; j < tit; j++)
229
QModelIndex index = model->createIndex(row, j);
230
label += QString::fromLatin1(", ");
231
label += model->data(index, Qt::EditRole).toString();
234
std::list<double> val;
236
for (int i = tit; i < model->columnCount(); i++)
238
QModelIndex index = model->createIndex(row, i);
239
toPush(val, model->data(index, Qt::EditRole).toDouble());
242
chart->addValues(val, label);
251
toPieChart *chart = new toPieChart(this);
252
layout()->addWidget(chart);
253
chart->showLegend(Legend->isChecked());
254
int tit = std::max(1, Title->currentText().toInt()) +
255
Source->numberColumn();
257
model->headerData(Source->numberColumn(),
258
Qt::Horizontal, Qt::DisplayRole).toString());
260
for (int row = 0; row < model->rowCount(); row++)
213
toPieChart *chart = new toPieChart(this);
214
chart->showLegend(Legend->isOn());
217
int tit = std::max(1, Title->currentText().toInt());
218
if (Source->columnText(0) == QString::fromLatin1("#"))
221
chart->setTitle(Source->columnText(add
223
for (QListViewItem *item = Source->firstChild();item;item = item->nextSibling())
262
QModelIndex index = model->createIndex(row, Source->numberColumn());
263
QString label = model->data(index, Qt::EditRole).toString();
264
for (int j = 1; j < tit; j++)
225
QString label = item->text(add
231
label += QString::fromLatin1(", ");
232
label += item->text(j);
234
chart->addValue(item->text(tit + add
235
).toDouble(), label);
266
QModelIndex index = model->createIndex(row, j);
267
label += QString::fromLatin1(", ");
268
label += model->data(index, Qt::EditRole).toString();
271
index = model->createIndex(row, tit);
272
chart->addValue(model->data(index, Qt::EditRole).toDouble(), label);
241
280
Result = new QWidget(this);
281
layout()->addWidget(Result);
243
Result->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
284
Result->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
285
QSizePolicy::Expanding));