~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/tovisualize.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-04-07 13:16:05 UTC
  • mfrom: (1.2.7 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090407131605-u422yigfv7jgg0l0
Tags: 2.0.0-3
* Cleaned up packaging a little bit.
* Added homepage information to control file.
* Bumped Standards-Version to 3.8.1.
* Released to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****
2
 
*
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
6
 
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.
11
 
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.
16
 
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.
20
 
*
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.
25
 
*
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.
31
 
*
32
 
*      You may link this product with any GPL'd Qt library such as Qt/Free
33
 
*
34
 
* All trademarks belong to their respective owners.
35
 
*
36
 
*****/
 
1
 
 
2
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
3
 *
 
4
 * TOra - An Oracle Toolkit for DBA's and developers
 
5
 * 
 
6
 * Shared/mixed copyright is held throughout files in this product
 
7
 * 
 
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
 
11
 * 
 
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.
 
16
 * 
 
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.
 
21
 * 
 
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.
 
25
 * 
 
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.
 
30
 * 
 
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
 
34
 *      these libraries. 
 
35
 * 
 
36
 *      You may link this product with any GPL'd Qt library.
 
37
 * 
 
38
 * All trademarks belong to their respective owners.
 
39
 *
 
40
 * END_COMMON_COPYRIGHT_HEADER */
37
41
 
38
42
#include "utils.h"
39
43
 
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"
46
51
 
47
52
#include <qcombobox.h>
48
53
#include <qlabel.h>
49
54
#include <qtoolbar.h>
50
55
#include <qtoolbutton.h>
51
 
#include <qtooltip.h>
52
56
 
53
 
#include "tovisualize.moc"
 
57
#include <QVBoxLayout>
 
58
#include <QPixmap>
54
59
 
55
60
#include "icons/axis.xpm"
56
61
#include "icons/execute.xpm"
57
62
#include "icons/grid.xpm"
58
63
#include "icons/legend.xpm"
59
64
 
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)
62
67
{
 
68
 
 
69
    if (name)
 
70
        setObjectName(name);
 
71
 
 
72
    QVBoxLayout *vbox = new QVBoxLayout;
 
73
    vbox->setSpacing(0);
 
74
    vbox->setContentsMargins(0, 0, 0, 0);
 
75
    setLayout(vbox);
 
76
 
63
77
    QToolBar *toolbar = toAllocBar(this, tr("Data visualization"));
 
78
    vbox->addWidget(toolbar);
64
79
 
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);
69
86
 
70
87
    toolbar->addSeparator();
71
88
 
72
89
    Legend = new QToolButton(toolbar);
73
 
    Legend->setToggleButton(true);
74
 
    Legend->setIconSet(QIconSet(QPixmap(const_cast<const char**>(legend_xpm))));
75
 
    QToolTip::add
76
 
        (Legend, tr("Display legend"));
77
 
    Legend->setOn(true);
 
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);
78
95
 
79
96
    Grid = new QToolButton(toolbar);
80
 
    Grid->setToggleButton(true);
81
 
    Grid->setIconSet(QIconSet(QPixmap(const_cast<const char**>(grid_xpm))));
82
 
    QToolTip::add
83
 
        (Grid, tr("Display grid"));
84
 
    Grid->setOn(true);
 
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);
85
102
 
86
103
    Axis = new QToolButton(toolbar);
87
 
    Axis->setToggleButton(true);
88
 
    Axis->setIconSet(QIconSet(QPixmap(const_cast<const char**>(axis_xpm))));
89
 
    QToolTip::add
90
 
        (Axis, tr("Display axis legend"));
91
 
    Axis->setOn(true);
92
 
 
93
 
    QToolTip::add
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);
 
109
 
 
110
    QLabel *title = new QLabel(tr("Title columns"));
 
111
    title->setToolTip(tr("Number of columns to use as title"));
 
112
    toolbar->addWidget(title);
 
113
 
 
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);
103
123
 
104
124
    toolbar->addSeparator();
105
125
 
106
 
    new QToolButton(QPixmap(const_cast<const char**>(execute_xpm)),
107
 
                    tr("Update chart"),
108
 
                    tr("Update chart"),
109
 
                    this, SLOT(display(void)),
110
 
                    toolbar);
 
126
    toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(execute_xpm))),
 
127
                       tr("Update chart"),
 
128
                       this,
 
129
                       SLOT(display(void)));
111
130
 
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);
113
135
 
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);
116
140
}
117
141
 
118
142
void toVisualize::display(void)
119
143
{
120
144
    QWidget *last = Result;
121
 
    switch (Type->currentItem())
 
145
    toResultModel *model = Source->model();
 
146
 
 
147
    switch (Type->currentIndex())
122
148
    {
 
149
 
123
150
    case 0:
124
 
        {
125
 
            toBarChart *chart = new toBarChart(this);
126
 
            chart->showLegend(Legend->isOn());
127
 
            int add
128
 
                = 0;
129
 
            int tit = std::max(1, Title->currentText().toInt());
130
 
            if (Source->columnText(0) == QString::fromLatin1("#"))
131
 
                add
132
 
                    = 1;
133
 
            chart->setTitle(Source->columnText(add
134
 
                                              ));
135
 
            chart->showGrid(Grid->isOn() ? 5 : 0);
136
 
            chart->showAxisLegend(Axis->isOn());
137
 
            chart->setSamples();
138
 
 
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);
144
 
 
145
 
            for (QListViewItem *item = Source->firstChild();item;item = item->nextSibling())
146
 
            {
147
 
                QString label = item->text(add
148
 
                                          );
149
 
                for (int j = add
150
 
                                 + 1;j < tit + add
151
 
                                ;j++)
152
 
                        {
153
 
                            label += QString::fromLatin1(", ");
154
 
                            label += item->text(j);
155
 
                        }
156
 
                std::list<double> val;
157
 
                for (int i = tit + add
158
 
                                 ;i < Source->columns();i++)
159
 
                    {
160
 
                        toPush(val, item->text(i).toDouble());
161
 
                    }
162
 
                chart->addValues(val, label);
163
 
            }
164
 
            Result = chart;
165
 
        }
166
 
        break;
 
151
    {
 
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();
 
157
        chart->setTitle(
 
158
            model->headerData(Source->numberColumn(),
 
159
                              Qt::Horizontal, Qt::DisplayRole).toString());
 
160
        chart->showGrid(Grid->isChecked() ? 5 : 0);
 
161
        chart->showAxisLegend(Axis->isChecked());
 
162
        chart->setSamples();
 
163
 
 
164
        std::list<QString> lst;
 
165
        for (int i = tit; i < model->columnCount(); i++)
 
166
        {
 
167
            toPush(lst,
 
168
                   model->headerData(i, Qt::Horizontal, Qt::DisplayRole)
 
169
                   .toString());
 
170
        }
 
171
        chart->setLabels(lst);
 
172
 
 
173
        for (int row = 0; row < model->rowCount(); row++)
 
174
        {
 
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++)
 
178
            {
 
179
                QModelIndex index = model->createIndex(row, j);
 
180
                label += QString::fromLatin1(", ");
 
181
                label += model->data(index, Qt::EditRole).toString();
 
182
            }
 
183
 
 
184
            std::list<double> val;
 
185
 
 
186
            for (int i = tit; i < model->columnCount(); i++)
 
187
            {
 
188
                QModelIndex index = model->createIndex(row, i);
 
189
                toPush(val, model->data(index, Qt::EditRole).toDouble());
 
190
            }
 
191
 
 
192
            chart->addValues(val, label);
 
193
        }
 
194
 
 
195
        Result = chart;
 
196
    }
 
197
    break;
 
198
 
167
199
    case 1:
168
 
        {
169
 
            toLineChart *chart = new toLineChart(this);
170
 
            chart->showLegend(Legend->isOn());
171
 
            int add
172
 
                = 0;
173
 
            int tit = std::max(1, Title->currentText().toInt());
174
 
            if (Source->columnText(0) == QString::fromLatin1("#"))
175
 
                add
176
 
                    = 1;
177
 
            chart->setTitle(Source->columnText(add
178
 
                                              ));
179
 
            chart->showGrid(Grid->isOn() ? 5 : 0);
180
 
            chart->showAxisLegend(Axis->isOn());
181
 
            chart->setSamples();
182
 
 
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);
188
 
 
189
 
            for (QListViewItem *item = Source->firstChild();item;item = item->nextSibling())
190
 
            {
191
 
                QString label = item->text(add
192
 
                                          );
193
 
                for (int j = add
194
 
                                 + 1;j < tit + add
195
 
                                ;j++)
196
 
                        {
197
 
                            label += QString::fromLatin1(", ");
198
 
                            label += item->text(j);
199
 
                        }
200
 
                std::list<double> val;
201
 
                for (int i = tit + add
202
 
                                 ;i < Source->columns();i++)
203
 
                    {
204
 
                        toPush(val, item->text(i).toDouble());
205
 
                    }
206
 
                chart->addValues(val, label);
207
 
            }
208
 
            Result = chart;
209
 
        }
210
 
        break;
 
200
    {
 
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();
 
206
        chart->setTitle(
 
207
            model->headerData(Source->numberColumn(),
 
208
                              Qt::Horizontal, Qt::DisplayRole).toString());
 
209
        chart->showGrid(Grid->isChecked() ? 5 : 0);
 
210
        chart->showAxisLegend(Axis->isChecked());
 
211
        chart->setSamples();
 
212
 
 
213
        std::list<QString> lst;
 
214
        for (int i = tit; i < model->columnCount(); i++)
 
215
        {
 
216
            toPush(lst, model->headerData(
 
217
                       i,
 
218
                       Qt::Horizontal,
 
219
                       Qt::DisplayRole).toString());
 
220
        }
 
221
        chart->setLabels(lst);
 
222
 
 
223
        for (int row = 0; row < model->rowCount(); row++)
 
224
        {
 
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++)
 
228
            {
 
229
                QModelIndex index = model->createIndex(row, j);
 
230
                label += QString::fromLatin1(", ");
 
231
                label += model->data(index, Qt::EditRole).toString();
 
232
            }
 
233
 
 
234
            std::list<double> val;
 
235
 
 
236
            for (int i = tit; i < model->columnCount(); i++)
 
237
            {
 
238
                QModelIndex index = model->createIndex(row, i);
 
239
                toPush(val, model->data(index, Qt::EditRole).toDouble());
 
240
            }
 
241
 
 
242
            chart->addValues(val, label);
 
243
        }
 
244
 
 
245
        Result = chart;
 
246
    }
 
247
    break;
 
248
 
211
249
    case 2:
 
250
    {
 
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();
 
256
        chart->setTitle(
 
257
            model->headerData(Source->numberColumn(),
 
258
                              Qt::Horizontal, Qt::DisplayRole).toString());
 
259
 
 
260
        for (int row = 0; row < model->rowCount(); row++)
212
261
        {
213
 
            toPieChart *chart = new toPieChart(this);
214
 
            chart->showLegend(Legend->isOn());
215
 
            int add
216
 
                = 0;
217
 
            int tit = std::max(1, Title->currentText().toInt());
218
 
            if (Source->columnText(0) == QString::fromLatin1("#"))
219
 
                add
220
 
                    = 1;
221
 
            chart->setTitle(Source->columnText(add
222
 
                                              ));
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++)
224
265
            {
225
 
                QString label = item->text(add
226
 
                                          );
227
 
                for (int j = add
228
 
                                 + 1;j < tit + add
229
 
                                ;j++)
230
 
                        {
231
 
                            label += QString::fromLatin1(", ");
232
 
                            label += item->text(j);
233
 
                        }
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();
236
269
            }
237
 
            Result = chart;
 
270
 
 
271
            index = model->createIndex(row, tit);
 
272
            chart->addValue(model->data(index, Qt::EditRole).toDouble(), label);
238
273
        }
239
 
        break;
 
274
 
 
275
        Result = chart;
 
276
    }
 
277
    break;
 
278
 
240
279
    default:
241
280
        Result = new QWidget(this);
 
281
        layout()->addWidget(Result);
242
282
    }
243
 
    Result->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
 
283
 
 
284
    Result->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
 
285
                                      QSizePolicy::Expanding));
244
286
    Result->show();
245
287
    delete last;
246
288
}