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

« back to all changes in this revision

Viewing changes to src/tobarchart.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 <qpainter.h>
 
39
#include <qworkspace.h>
 
40
 
 
41
#include "tobarchart.h"
 
42
#include "tomain.h"
 
43
#include "utils.h"
 
44
 
 
45
#include "tobarchart.moc"
 
46
 
 
47
toBarChart::toBarChart(QWidget *parent, const char *name, WFlags f)
 
48
        : toLineChart(parent, name, f)
 
49
{
 
50
    setMinValue(0);
 
51
}
 
52
 
 
53
#define FONT_ALIGN AlignLeft|AlignTop|ExpandTabs
 
54
 
 
55
void toBarChart::paintChart(QPainter *p, QRect &rect)
 
56
{
 
57
    QFontMetrics fm = p->fontMetrics();
 
58
 
 
59
    if (!Zooming)
 
60
    {
 
61
        if (MinAuto)
 
62
        {
 
63
            bool first = true;
 
64
            std::list<std::list<double> >::reverse_iterator i = Values.rbegin();
 
65
            if (i != Values.rend())
 
66
            {
 
67
                for (std::list<double>::iterator j = (*i).begin();j != (*i).end();j++)
 
68
                {
 
69
                    if (first)
 
70
                    {
 
71
                        first = false;
 
72
                        zMinValue = *j;
 
73
                    }
 
74
                    else if (zMinValue > *j)
 
75
                        zMinValue = *j;
 
76
                }
 
77
            }
 
78
        }
 
79
        if (MaxAuto)
 
80
        {
 
81
            bool first = true;
 
82
            std::list<double> total;
 
83
            std::list<bool>::iterator e = Enabled.begin();
 
84
            {
 
85
                for (std::list<std::list<double> >::iterator i = Values.begin();i != Values.end();i++)
 
86
                {
 
87
                    std::list<double>::iterator k = total.begin();
 
88
                    if (e == Enabled.end() || *e)
 
89
                    {
 
90
                        for (std::list<double>::iterator j = (*i).begin();j != (*i).end();j++)
 
91
                        {
 
92
                            if (k == total.end())
 
93
                            {
 
94
                                total.insert(total.end(), *j);
 
95
                                k = total.end();
 
96
                            }
 
97
                            else
 
98
                            {
 
99
                                *k += *j;
 
100
                                k++;
 
101
                            }
 
102
                        }
 
103
                    }
 
104
                    if (e != Enabled.end())
 
105
                        e++;
 
106
                }
 
107
            }
 
108
            for (std::list<double>::iterator i = total.begin();i != total.end();i++)
 
109
            {
 
110
                if (first)
 
111
                {
 
112
                    first = false;
 
113
                    zMaxValue = *i;
 
114
                }
 
115
                else if (zMaxValue < *i)
 
116
                    zMaxValue = *i;
 
117
            }
 
118
        }
 
119
        if (!MinAuto)
 
120
            zMinValue = MinValue;
 
121
        else
 
122
        {
 
123
            zMinValue = round(zMinValue, false);
 
124
            MinValue = zMinValue;
 
125
        }
 
126
        if (!MaxAuto)
 
127
            zMaxValue = MaxValue;
 
128
        else
 
129
        {
 
130
            zMaxValue = round(zMaxValue, true);
 
131
            MaxValue = zMaxValue;
 
132
        }
 
133
    }
 
134
 
 
135
    paintTitle(p, rect);
 
136
    paintLegend(p, rect);
 
137
    paintAxis(p, rect);
 
138
 
 
139
    std::list<QPointArray> Points;
 
140
    int cp = 0;
 
141
    int samples = countSamples();
 
142
    int zeroy = int(rect.height() - 2 - ( -zMinValue / (zMaxValue - zMinValue) * (rect.height() - 4)));
 
143
    if (samples > 1)
 
144
    {
 
145
        const QWMatrix &mtx = p->worldMatrix();
 
146
        p->setClipRect(int(mtx.dx() + 2), int(mtx.dy() + 2), rect.width() - 3, rect.height() - 3);
 
147
        if (Zooming)
 
148
            p->drawText(2, 2, rect.width() - 4, rect.height() - 4,
 
149
                        AlignLeft | AlignTop, tr("Zoom"));
 
150
        std::list<bool>::reverse_iterator e = Enabled.rbegin();
 
151
        for (std::list<std::list<double> >::reverse_iterator i = Values.rbegin();i != Values.rend();i++)
 
152
        {
 
153
            if (e == Enabled.rend() || *e)
 
154
            {
 
155
                std::list<double> &val = *i;
 
156
                int count = 0;
 
157
                int skip = SkipSamples;
 
158
                QPointArray a(samples + 10);
 
159
                int x = rect.width() - 2;
 
160
                for (std::list<double>::reverse_iterator j = val.rbegin();j != val.rend() && x >=
 
161
                        2;
 
162
                        j++)
 
163
                {
 
164
                    if (skip > 0)
 
165
                        skip--;
 
166
                    else
 
167
                    {
 
168
                        int val = int(rect.height() - 2 - ((*j - zMinValue) / (zMaxValue - zMinValue) * (rect.height() - 4)));
 
169
                        x = rect.width() - 2 - count * (rect.width() - 4) / (samples - 1);
 
170
                        a.setPoint(count, x, val);
 
171
                        count++;
 
172
                        if (count >= samples)
 
173
                            break;
 
174
                    }
 
175
                }
 
176
                a.resize(count*2);
 
177
                Points.insert(Points.end(), a);
 
178
            }
 
179
            cp++;
 
180
            if (e != Enabled.rend())
 
181
                e++;
 
182
        }
 
183
    }
 
184
 
 
185
    std::map<int, int> Bottom;
 
186
    std::list<bool>::reverse_iterator e = Enabled.rbegin();
 
187
    for (std::list<QPointArray>::iterator i = Points.begin();i != Points.end();)
 
188
    {
 
189
        while (e != Enabled.rend() && !*e)
 
190
        {
 
191
            cp--;
 
192
            e++;
 
193
        }
 
194
        if (e != Enabled.rend())
 
195
            e++;
 
196
        cp--;
 
197
 
 
198
        QPointArray a = *i;
 
199
        int lx = 0;
 
200
        int lb = 0;
 
201
        for (unsigned int j = 0;j < a.size() / 2;j++)
 
202
        {
 
203
            int x, y;
 
204
            a.point(j, &x, &y);
 
205
            if (Bottom.find(x) == Bottom.end())
 
206
                Bottom[x] = 0;
 
207
            if (lx != x)
 
208
                lb = Bottom[x];
 
209
            a.setPoint(a.size() - 1 - j, x, zeroy - lb);
 
210
            y -= lb;
 
211
            a.setPoint(j, x, y);
 
212
            Bottom[x] = zeroy - y;
 
213
            lx = x;
 
214
        }
 
215
 
 
216
        p->save();
 
217
        QBrush brush(toChartBrush(cp));
 
218
        p->setBrush(brush.color());
 
219
        p->drawPolygon(a);
 
220
        if (brush.style() != QBrush::SolidPattern)
 
221
        {
 
222
            p->setBrush(QBrush(Qt::white, brush.style()));
 
223
            p->drawPolygon(a);
 
224
        }
 
225
        p->restore();
 
226
        i++;
 
227
    }
 
228
}
 
229
 
 
230
toBarChart::toBarChart (toBarChart *chart, QWidget *parent, const char *name, WFlags f)
 
231
        : toLineChart(chart, parent, name, f)
 
232
{}
 
233
 
 
234
toLineChart *toBarChart::openCopy(QWidget *parent)
 
235
{
 
236
    toBarChart *newWin = new toBarChart(this,
 
237
                                        parent ? parent : toMainWidget()->workspace(),
 
238
                                        NULL, parent ? 0 : WDestructiveClose);
 
239
    if (!parent)
 
240
    {
 
241
        newWin->show();
 
242
        newWin->raise();
 
243
        newWin->setFocus();
 
244
 
 
245
        toMainWidget()->windowsMenu();
 
246
 
 
247
#if QT_VERSION < 0x030100
 
248
        // This is a really ugly workaround for a Qt layout bug
 
249
        QWidget *tmp = NULL;
 
250
        QWidget *tmp2 = NULL;
 
251
 
 
252
#if QT_VERSION < 0x030200
 
253
 
 
254
        for (unsigned int i = 0;i < toMainWidget()->workspace()->windowList().count();i++)
 
255
        {
 
256
            QWidget *widget = toMainWidget()->workspace()->windowList().at(i);
 
257
#else
 
258
 
 
259
        for (unsigned int i = 0;i < toMainWidget()->workspace()->windowList(QWorkspace::CreationOrder).count();i++)
 
260
        {
 
261
            QWidget *widget = toMainWidget()->workspace()->windowList(QWorkspace::CreationOrder).at(i);
 
262
#endif
 
263
 
 
264
            if (newWin != widget)
 
265
                tmp2 = widget;
 
266
            else
 
267
                tmp = newWin;
 
268
            if (tmp2 && tmp)
 
269
                break;
 
270
        }
 
271
        if (tmp2 && tmp)
 
272
        {
 
273
            tmp2->setFocus();
 
274
            tmp->setFocus();
 
275
        }
 
276
#endif
 
277
 
 
278
    }
 
279
    return newWin;
 
280
}
 
281