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.
40
#include "toanalyze.h"
41
#include "tobarchart.h"
43
#include "toresultview.h"
44
#include "toworksheetstatistic.h"
46
#include <qcheckbox.h>
48
#include <qpopupmenu.h>
49
#include <qsplitter.h>
51
#include <qtoolbutton.h>
54
#include "toworksheetstatistic.moc"
56
#include "icons/fileopen.xpm"
57
#include "icons/filesave.xpm"
58
#include "icons/grid.xpm"
59
#include "icons/trash.xpm"
60
#include "icons/tree.xpm"
62
toAnalyze *toWorksheetStatistic::Widget;
64
toWorksheetStatistic::toWorksheetStatistic(QWidget *parent)
67
QToolBar *toolbar = toAllocBar(this, tr("Server Tuning"));
69
new QToolButton(QPixmap(const_cast<const char**>(fileopen_xpm)),
70
tr("Load statistics from file"),
71
tr("Load statistics from file"),
72
this, SLOT(load(void)),
75
QToolButton *button = new toPopupButton(QPixmap(const_cast<const char**>(filesave_xpm)),
76
tr("Save statistics to file"),
77
tr("Save statistics to file"),
79
SaveMenu = new QPopupMenu(button);
80
button->setPopup(SaveMenu);
81
connect(SaveMenu, SIGNAL(aboutToShow()), this, SLOT(displayMenu()));
82
connect(SaveMenu, SIGNAL(activated(int)), this, SLOT(save(int)));
84
toolbar->addSeparator();
86
button = new toPopupButton(QPixmap(const_cast<const char**>(trash_xpm)),
87
tr("Remove statistics"),
88
tr("Remove statistics"),
90
RemoveMenu = new QPopupMenu(button);
91
button->setPopup(RemoveMenu);
92
connect(RemoveMenu, SIGNAL(aboutToShow()), this, SLOT(displayMenu()));
93
connect(RemoveMenu, SIGNAL(activated(int)), this, SLOT(remove
96
Splitter = new QSplitter(Vertical, this);
98
toolbar->addSeparator();
100
ShowCharts = new QToolButton(toolbar);
101
ShowCharts->setToggleButton(true);
102
ShowCharts->setIconSet(QIconSet(QPixmap(const_cast<const char**>(grid_xpm))));
104
(ShowCharts, tr("Display charts"));
105
ShowCharts->setOn(true);
106
connect(ShowCharts, SIGNAL(toggled(bool)), this, SLOT(showCharts(bool)));
108
ShowPlans = new QToolButton(toolbar);
109
ShowPlans->setToggleButton(true);
110
ShowPlans->setIconSet(QIconSet(QPixmap(const_cast<const char**>(tree_xpm))));
112
(ShowPlans, tr("Display execution plans"));
113
ShowPlans->setOn(true);
114
connect(ShowPlans, SIGNAL(toggled(bool)), this, SLOT(showPlans(bool)));
116
toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
118
Dummy = new QWidget(Splitter);
122
Tool = dynamic_cast<toAnalyze *>(toCurrentTool(this));
129
toWorksheetStatistic::~toWorksheetStatistic()
135
void toWorksheetStatistic::saveStatistics(std::map<QCString, QString> &stats)
138
toAnalyze::createTool();
140
Widget->worksheet()->addStatistics(stats);
143
void toWorksheetStatistic::addStatistics(std::map<QCString, QString> &stats)
146
cur.Top = new QVBox(Splitter);
147
QHBox *box = new QHBox(cur.Top);
148
box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
149
cur.Label = new QLabel(stats["Description"], box);
150
cur.Label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
151
QCheckBox *check = new QCheckBox(tr("Hide"), box);
152
cur.Charts = new toHideSplitter(Horizontal, cur.Top, this);
153
connect(check, SIGNAL(toggled(bool)), cur.Charts, SLOT(setHidden(bool)));
154
cur.Statistics = new toListView(cur.Charts);
155
cur.Statistics->importData(stats, "Stat");
156
cur.Wait = new toBarChart(cur.Charts);
157
cur.Wait->importData(stats, "Wait");
158
cur.IO = new toBarChart(cur.Charts);
159
cur.IO->importData(stats, "IO");
160
cur.Plan = new toListView(cur.Charts);
161
cur.Plan->importData(stats, "Plan");
163
QValueList<int> sizes;
164
sizes << 1 << 1 << 1 << 1;
165
cur.Charts->setSizes(sizes);
166
if (!cur.Plan->firstChild())
171
else if (!ShowPlans->isOn())
173
if (!ShowCharts->isOn())
175
cur.Statistics->hide();
182
Open.insert(Open.end(), cur);
191
void toWorksheetStatistic::showPlans(bool show)
193
for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
209
void toWorksheetStatistic::showCharts(bool show)
211
for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
215
(*i).Statistics->show();
221
(*i).Statistics->hide();
228
void toWorksheetStatistic::save(int selid)
231
for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
235
QString fn = toSaveFilename(QString::null, QString::fromLatin1("*.stat"), this);
238
std::map<QCString, QString> stat;
239
(*i).Statistics->exportData(stat, "Stat");
240
(*i).IO->exportData(stat, "IO");
241
(*i).Wait->exportData(stat, "Wait");
243
(*i).Plan->exportData(stat, "Plan");
244
stat["Description"] = (*i).Label->text();
247
toTool::saveMap(fn, stat);
257
void toWorksheetStatistic::remove
261
for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
266
if (Open.size() == 1)
268
Dummy = new QWidget(Splitter);
278
void toWorksheetStatistic::load(void)
280
QString filename = toOpenFilename(QString::null, QString::fromLatin1("*.stat"), this);
281
if (!filename.isEmpty())
285
std::map<QCString, QString> ret;
286
toTool::loadMap(filename, ret);
293
void toWorksheetStatistic::displayMenu(void)
298
for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
300
SaveMenu->insertItem((*i).Label->text(), id);
301
RemoveMenu->insertItem((*i).Label->text(), id);
306
void toWorksheetStatistic::updateSplitter(void)
308
QValueList<int> sizes = Splitter->sizes();
311
for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
313
if ((*i).Charts->isHidden())
316
sizes[id] = (*i).Charts->height();
319
Splitter->setSizes(sizes);
322
void toHideSplitter::setHidden(bool hid)
328
StatList->updateSplitter();