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

« back to all changes in this revision

Viewing changes to toworksheetstatistic.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

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
 
*****/
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#include "toanalyze.h"
41
 
#include "tobarchart.h"
42
 
#include "toconf.h"
43
 
#include "toresultview.h"
44
 
#include "toworksheetstatistic.h"
45
 
 
46
 
#include <qcheckbox.h>
47
 
#include <qlabel.h>
48
 
#include <qpopupmenu.h>
49
 
#include <qsplitter.h>
50
 
#include <qtoolbar.h>
51
 
#include <qtoolbutton.h>
52
 
#include <qtooltip.h>
53
 
 
54
 
#include "toworksheetstatistic.moc"
55
 
 
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"
61
 
 
62
 
toAnalyze *toWorksheetStatistic::Widget;
63
 
 
64
 
toWorksheetStatistic::toWorksheetStatistic(QWidget *parent)
65
 
        : QVBox(parent)
66
 
{
67
 
    QToolBar *toolbar = toAllocBar(this, tr("Server Tuning"));
68
 
 
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)),
73
 
                    toolbar);
74
 
 
75
 
    QToolButton *button = new toPopupButton(QPixmap(const_cast<const char**>(filesave_xpm)),
76
 
                                            tr("Save statistics to file"),
77
 
                                            tr("Save statistics to file"),
78
 
                                            toolbar);
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)));
83
 
 
84
 
    toolbar->addSeparator();
85
 
 
86
 
    button = new toPopupButton(QPixmap(const_cast<const char**>(trash_xpm)),
87
 
                               tr("Remove statistics"),
88
 
                               tr("Remove statistics"),
89
 
                               toolbar);
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
94
 
            (int)));
95
 
 
96
 
    Splitter = new QSplitter(Vertical, this);
97
 
 
98
 
    toolbar->addSeparator();
99
 
 
100
 
    ShowCharts = new QToolButton(toolbar);
101
 
    ShowCharts->setToggleButton(true);
102
 
    ShowCharts->setIconSet(QIconSet(QPixmap(const_cast<const char**>(grid_xpm))));
103
 
    QToolTip::add
104
 
        (ShowCharts, tr("Display charts"));
105
 
    ShowCharts->setOn(true);
106
 
    connect(ShowCharts, SIGNAL(toggled(bool)), this, SLOT(showCharts(bool)));
107
 
 
108
 
    ShowPlans = new QToolButton(toolbar);
109
 
    ShowPlans->setToggleButton(true);
110
 
    ShowPlans->setIconSet(QIconSet(QPixmap(const_cast<const char**>(tree_xpm))));
111
 
    QToolTip::add
112
 
        (ShowPlans, tr("Display execution plans"));
113
 
    ShowPlans->setOn(true);
114
 
    connect(ShowPlans, SIGNAL(toggled(bool)), this, SLOT(showPlans(bool)));
115
 
 
116
 
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
117
 
 
118
 
    Dummy = new QWidget(Splitter);
119
 
 
120
 
    try
121
 
    {
122
 
        Tool = dynamic_cast<toAnalyze *>(toCurrentTool(this));
123
 
        if (!Widget)
124
 
            Widget = Tool;
125
 
    }
126
 
    TOCATCH
127
 
}
128
 
 
129
 
toWorksheetStatistic::~toWorksheetStatistic()
130
 
{
131
 
    if (Widget == Tool)
132
 
        Widget = NULL;
133
 
}
134
 
 
135
 
void toWorksheetStatistic::saveStatistics(std::map<QCString, QString> &stats)
136
 
{
137
 
    if (!Widget)
138
 
        toAnalyze::createTool();
139
 
    if (Widget)
140
 
        Widget->worksheet()->addStatistics(stats);
141
 
}
142
 
 
143
 
void toWorksheetStatistic::addStatistics(std::map<QCString, QString> &stats)
144
 
{
145
 
    data cur;
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");
162
 
 
163
 
    QValueList<int> sizes;
164
 
    sizes << 1 << 1 << 1 << 1;
165
 
    cur.Charts->setSizes(sizes);
166
 
    if (!cur.Plan->firstChild())
167
 
    {
168
 
        delete cur.Plan;
169
 
        cur.Plan = NULL;
170
 
    }
171
 
    else if (!ShowPlans->isOn())
172
 
        cur.Plan->hide();
173
 
    if (!ShowCharts->isOn())
174
 
    {
175
 
        cur.Statistics->hide();
176
 
        cur.Wait->hide();
177
 
        cur.IO->hide();
178
 
    }
179
 
    cur.Top->show();
180
 
    setFocus();
181
 
 
182
 
    Open.insert(Open.end(), cur);
183
 
 
184
 
    if (Dummy)
185
 
    {
186
 
        delete Dummy;
187
 
        Dummy = NULL;
188
 
    }
189
 
}
190
 
 
191
 
void toWorksheetStatistic::showPlans(bool show)
192
 
{
193
 
    for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
194
 
    {
195
 
        if ((*i).Plan)
196
 
        {
197
 
            if (show)
198
 
            {
199
 
                (*i).Plan->show();
200
 
            }
201
 
            else
202
 
            {
203
 
                (*i).Plan->hide();
204
 
            }
205
 
        }
206
 
    }
207
 
}
208
 
 
209
 
void toWorksheetStatistic::showCharts(bool show)
210
 
{
211
 
    for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
212
 
    {
213
 
        if (show)
214
 
        {
215
 
            (*i).Statistics->show();
216
 
            (*i).Wait->show();
217
 
            (*i).IO->show();
218
 
        }
219
 
        else
220
 
        {
221
 
            (*i).Statistics->hide();
222
 
            (*i).Wait->hide();
223
 
            (*i).IO->hide();
224
 
        }
225
 
    }
226
 
}
227
 
 
228
 
void toWorksheetStatistic::save(int selid)
229
 
{
230
 
    int id = 1;
231
 
    for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
232
 
    {
233
 
        if (selid == id)
234
 
        {
235
 
            QString fn = toSaveFilename(QString::null, QString::fromLatin1("*.stat"), this);
236
 
            if (!fn.isEmpty())
237
 
            {
238
 
                std::map<QCString, QString> stat;
239
 
                (*i).Statistics->exportData(stat, "Stat");
240
 
                (*i).IO->exportData(stat, "IO");
241
 
                (*i).Wait->exportData(stat, "Wait");
242
 
                if ((*i).Plan)
243
 
                    (*i).Plan->exportData(stat, "Plan");
244
 
                stat["Description"] = (*i).Label->text();
245
 
                try
246
 
                {
247
 
                    toTool::saveMap(fn, stat);
248
 
                }
249
 
                TOCATCH
250
 
            }
251
 
            break;
252
 
        }
253
 
        id++;
254
 
    }
255
 
}
256
 
 
257
 
void toWorksheetStatistic::remove
258
 
    (int selid)
259
 
{
260
 
    int id = 1;
261
 
    for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
262
 
    {
263
 
        if (selid == id)
264
 
        {
265
 
            delete (*i).Top;
266
 
            if (Open.size() == 1)
267
 
            {
268
 
                Dummy = new QWidget(Splitter);
269
 
                Dummy->show();
270
 
            }
271
 
            Open.erase(i);
272
 
            break;
273
 
        }
274
 
        id++;
275
 
    }
276
 
}
277
 
 
278
 
void toWorksheetStatistic::load(void)
279
 
{
280
 
    QString filename = toOpenFilename(QString::null, QString::fromLatin1("*.stat"), this);
281
 
    if (!filename.isEmpty())
282
 
    {
283
 
        try
284
 
        {
285
 
            std::map<QCString, QString> ret;
286
 
            toTool::loadMap(filename, ret);
287
 
            addStatistics(ret);
288
 
        }
289
 
        TOCATCH
290
 
    }
291
 
}
292
 
 
293
 
void toWorksheetStatistic::displayMenu(void)
294
 
{
295
 
    SaveMenu->clear();
296
 
    RemoveMenu->clear();
297
 
    int id = 1;
298
 
    for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
299
 
    {
300
 
        SaveMenu->insertItem((*i).Label->text(), id);
301
 
        RemoveMenu->insertItem((*i).Label->text(), id);
302
 
        id++;
303
 
    }
304
 
}
305
 
 
306
 
void toWorksheetStatistic::updateSplitter(void)
307
 
{
308
 
    QValueList<int> sizes = Splitter->sizes();
309
 
 
310
 
    int id = 0;
311
 
    for (std::list<data>::iterator i = Open.begin();i != Open.end();i++)
312
 
    {
313
 
        if ((*i).Charts->isHidden())
314
 
            sizes[id] = 0;
315
 
        else
316
 
            sizes[id] = (*i).Charts->height();
317
 
        id++;
318
 
    }
319
 
    Splitter->setSizes(sizes);
320
 
}
321
 
 
322
 
void toHideSplitter::setHidden(bool hid)
323
 
{
324
 
    if (hid)
325
 
        hide();
326
 
    else
327
 
        show();
328
 
    StatList->updateSplitter();
329
 
}