~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt/src/qwt_plot.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2011-06-10 11:22:47 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110610112247-0i1019vvmzaq6p86
Tags: 6.0.0-1
* New upstream release (Closes: #624107):
  - drop Qt3 support. (Closes: #604379, #626868)
* Register documentation with doc-base. (Closes: #626567)
* Drop patches:
  - 01_makefiles.diff
  - 02_add_missing_warnings.diff
  - 03_qwt_branch_pull_r544.diff
* Add qwt_install_paths.patch to fix the hardcoded installation paths.
* Update debian/control:
  - drop libqt3-mt-dev build dependency.
  - bump Standards-Version to 3.9.2 (no changes).
  - drop Qt3 related packages.
  - due to bump soname (and as we dropper Qt3 support):
    - libqwt5-qt4-dev -> libqwt-dev
    - libqwt5-qt4 -> libqwt6
    - libqwt5-doc -> libqwt-doc
* Update debian/copyright file.
* Update debian/rules: drop Qt3 packages support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2
 
 * Qwt Widget Library
3
 
 * Copyright (C) 1997   Josef Wilgen
4
 
 * Copyright (C) 2002   Uwe Rathmann
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the Qwt License, Version 1.0
8
 
 *****************************************************************************/
9
 
 
10
 
#include <qpainter.h>
11
 
#if QT_VERSION < 0x040000
12
 
#include <qguardedptr.h>
13
 
#include <qfocusdata.h>
14
 
#else
15
 
#include <qpointer.h>
16
 
#include <qpaintengine.h>
17
 
#endif
18
 
#include <qapplication.h>
19
 
#include <qevent.h>
20
 
#include "qwt_plot.h"
21
 
#include "qwt_plot_dict.h"
22
 
#include "qwt_plot_layout.h"
23
 
#include "qwt_scale_widget.h"
24
 
#include "qwt_scale_engine.h"
25
 
#include "qwt_text_label.h"
26
 
#include "qwt_legend.h"
27
 
#include "qwt_dyngrid_layout.h"
28
 
#include "qwt_plot_canvas.h"
29
 
#include "qwt_paint_buffer.h"
30
 
 
31
 
class QwtPlot::PrivateData
32
 
{
33
 
public:
34
 
#if QT_VERSION < 0x040000
35
 
    QGuardedPtr<QwtTextLabel> lblTitle;
36
 
    QGuardedPtr<QwtPlotCanvas> canvas;
37
 
    QGuardedPtr<QwtLegend> legend;
38
 
#else
39
 
    QPointer<QwtTextLabel> lblTitle;
40
 
    QPointer<QwtPlotCanvas> canvas;
41
 
    QPointer<QwtLegend> legend;
42
 
#endif
43
 
    QwtPlotLayout *layout;
44
 
 
45
 
    bool autoReplot;
46
 
};
47
 
 
48
 
/*!
49
 
  \brief Constructor
50
 
  \param parent Parent widget
51
 
 */
52
 
QwtPlot::QwtPlot(QWidget *parent):
53
 
    QFrame(parent)
54
 
{
55
 
    initPlot(QwtText());
56
 
}
57
 
 
58
 
/*!
59
 
  \brief Constructor
60
 
  \param title Title text
61
 
  \param parent Parent widget
62
 
 */
63
 
QwtPlot::QwtPlot(const QwtText &title, QWidget *parent):
64
 
    QFrame(parent)
65
 
{
66
 
    initPlot(title);
67
 
}
68
 
 
69
 
#if QT_VERSION < 0x040000
70
 
/*!
71
 
  \brief Constructor
72
 
  \param parent Parent widget
73
 
  \param name Object name
74
 
 */
75
 
QwtPlot::QwtPlot(QWidget *parent, const char *name):
76
 
    QFrame(parent, name)
77
 
{   
78
 
    initPlot(QwtText());
79
 
}   
80
 
#endif
81
 
 
82
 
 
83
 
//! Destructor
84
 
QwtPlot::~QwtPlot()
85
 
{
86
 
    detachItems(QwtPlotItem::Rtti_PlotItem, autoDelete());
87
 
 
88
 
    delete d_data->layout;
89
 
    deleteAxesData();
90
 
    delete d_data;
91
 
}
92
 
 
93
 
/*!
94
 
  \brief Initializes a QwtPlot instance
95
 
  \param title Title text
96
 
 */
97
 
void QwtPlot::initPlot(const QwtText &title)
98
 
{
99
 
    d_data = new PrivateData;
100
 
 
101
 
#if QT_VERSION < 0x040000
102
 
    setWFlags(Qt::WNoAutoErase);
103
 
#endif 
104
 
 
105
 
    d_data->layout = new QwtPlotLayout;
106
 
 
107
 
    d_data->autoReplot = false;
108
 
 
109
 
    d_data->lblTitle = new QwtTextLabel(title, this);
110
 
    d_data->lblTitle->setFont(QFont(fontInfo().family(), 14, QFont::Bold));
111
 
 
112
 
    QwtText text(title);
113
 
    int flags = Qt::AlignCenter;
114
 
#if QT_VERSION < 0x040000
115
 
    flags |= Qt::WordBreak | Qt::ExpandTabs;
116
 
#else
117
 
    flags |= Qt::TextWordWrap;
118
 
#endif
119
 
    text.setRenderFlags(flags);
120
 
    d_data->lblTitle->setText(text);
121
 
 
122
 
    d_data->legend = NULL;
123
 
 
124
 
    initAxesData();
125
 
 
126
 
    d_data->canvas = new QwtPlotCanvas(this);
127
 
    d_data->canvas->setFrameStyle(QFrame::Panel|QFrame::Sunken);
128
 
    d_data->canvas->setLineWidth(2);
129
 
    d_data->canvas->setMidLineWidth(0);
130
 
 
131
 
    updateTabOrder();
132
 
 
133
 
    setSizePolicy(QSizePolicy::MinimumExpanding, 
134
 
        QSizePolicy::MinimumExpanding);
135
 
}
136
 
 
137
 
/*!
138
 
  \brief Adds handling of layout requests
139
 
*/
140
 
bool QwtPlot::event(QEvent *e)
141
 
{
142
 
    bool ok = QFrame::event(e);
143
 
    switch(e->type())
144
 
    {
145
 
#if QT_VERSION < 0x040000
146
 
        case QEvent::LayoutHint:
147
 
#else
148
 
        case QEvent::LayoutRequest:
149
 
#endif
150
 
            updateLayout();
151
 
            break;
152
 
#if QT_VERSION >= 0x040000
153
 
        case QEvent::PolishRequest:
154
 
            polish();
155
 
            break;
156
 
#endif
157
 
        default:;
158
 
    }
159
 
    return ok;
160
 
}
161
 
 
162
 
//! Replots the plot if QwtPlot::autoReplot() is \c true.
163
 
void QwtPlot::autoRefresh()
164
 
{
165
 
    if (d_data->autoReplot)
166
 
        replot();
167
 
}
168
 
 
169
 
/*!
170
 
  \brief Set or reset the autoReplot option
171
 
 
172
 
  If the autoReplot option is set, the plot will be
173
 
  updated implicitly by manipulating member functions.
174
 
  Since this may be time-consuming, it is recommended
175
 
  to leave this option switched off and call replot()
176
 
  explicitly if necessary.
177
 
 
178
 
  The autoReplot option is set to false by default, which
179
 
  means that the user has to call replot() in order to make
180
 
  changes visible.
181
 
  \param tf \c true or \c false. Defaults to \c true.
182
 
  \sa replot()
183
 
*/
184
 
void QwtPlot::setAutoReplot(bool tf)
185
 
{
186
 
    d_data->autoReplot = tf;
187
 
}
188
 
 
189
 
//! \return true if the autoReplot option is set.
190
 
bool QwtPlot::autoReplot() const
191
 
{
192
 
    return d_data->autoReplot; 
193
 
}
194
 
 
195
 
/*!
196
 
  Change the plot's title
197
 
  \param title New title
198
 
*/
199
 
void QwtPlot::setTitle(const QString &title)
200
 
{
201
 
    if ( title != d_data->lblTitle->text().text() )
202
 
    {
203
 
        d_data->lblTitle->setText(title);
204
 
        updateLayout();
205
 
    }
206
 
}
207
 
 
208
 
/*!
209
 
  Change the plot's title
210
 
  \param title New title
211
 
*/
212
 
void QwtPlot::setTitle(const QwtText &title)
213
 
{
214
 
    if ( title != d_data->lblTitle->text() )
215
 
    {
216
 
        d_data->lblTitle->setText(title);
217
 
        updateLayout();
218
 
    }
219
 
}
220
 
 
221
 
//! \return the plot's title
222
 
QwtText QwtPlot::title() const
223
 
{
224
 
    return d_data->lblTitle->text();
225
 
}
226
 
 
227
 
//! \return the plot's title
228
 
QwtPlotLayout *QwtPlot::plotLayout()
229
 
{
230
 
    return d_data->layout;
231
 
}
232
 
 
233
 
//! \return the plot's titel label.
234
 
const QwtPlotLayout *QwtPlot::plotLayout() const
235
 
{
236
 
    return d_data->layout;
237
 
}
238
 
 
239
 
//! \return the plot's titel label.
240
 
QwtTextLabel *QwtPlot::titleLabel()
241
 
{
242
 
    return d_data->lblTitle;
243
 
}
244
 
 
245
 
/*!
246
 
  \return the plot's titel label.
247
 
*/
248
 
const QwtTextLabel *QwtPlot::titleLabel() const
249
 
{
250
 
    return d_data->lblTitle;
251
 
}
252
 
 
253
 
/*!
254
 
  \return the plot's legend
255
 
  \sa insertLegend()
256
 
*/
257
 
QwtLegend *QwtPlot::legend()
258
 
259
 
    return d_data->legend;
260
 
}   
261
 
 
262
 
/*!
263
 
  \return the plot's legend
264
 
  \sa insertLegend()
265
 
*/
266
 
const QwtLegend *QwtPlot::legend() const
267
 
268
 
    return d_data->legend;
269
 
}   
270
 
 
271
 
 
272
 
/*!
273
 
  \return the plot's canvas
274
 
*/
275
 
QwtPlotCanvas *QwtPlot::canvas()
276
 
277
 
    return d_data->canvas;
278
 
}   
279
 
 
280
 
/*!
281
 
  \return the plot's canvas
282
 
*/
283
 
const QwtPlotCanvas *QwtPlot::canvas() const
284
 
285
 
    return d_data->canvas;
286
 
}
287
 
 
288
 
//! Polish
289
 
void QwtPlot::polish()
290
 
{
291
 
    replot();
292
 
 
293
 
#if QT_VERSION < 0x040000
294
 
    QFrame::polish();
295
 
#endif
296
 
}
297
 
 
298
 
/*!  
299
 
  Return sizeHint
300
 
  \sa minimumSizeHint()
301
 
*/
302
 
 
303
 
QSize QwtPlot::sizeHint() const
304
 
{
305
 
    int dw = 0;
306
 
    int dh = 0;
307
 
    for ( int axisId = 0; axisId < axisCnt; axisId++ )
308
 
    {
309
 
        if ( axisEnabled(axisId) )
310
 
        {   
311
 
            const int niceDist = 40;
312
 
            const QwtScaleWidget *scaleWidget = axisWidget(axisId);
313
 
            const QwtScaleDiv &scaleDiv = scaleWidget->scaleDraw()->scaleDiv();
314
 
            const int majCnt = scaleDiv.ticks(QwtScaleDiv::MajorTick).count();
315
 
 
316
 
            if ( axisId == yLeft || axisId == yRight )
317
 
            {
318
 
                int hDiff = (majCnt - 1) * niceDist 
319
 
                    - scaleWidget->minimumSizeHint().height();
320
 
                if ( hDiff > dh )
321
 
                    dh = hDiff;
322
 
            }
323
 
            else
324
 
            {
325
 
                int wDiff = (majCnt - 1) * niceDist 
326
 
                    - scaleWidget->minimumSizeHint().width();
327
 
                if ( wDiff > dw )
328
 
                    dw = wDiff;
329
 
            }
330
 
        }
331
 
    }
332
 
    return minimumSizeHint() + QSize(dw, dh);
333
 
}
334
 
 
335
 
/*!
336
 
  \brief Return a minimum size hint
337
 
*/
338
 
QSize QwtPlot::minimumSizeHint() const
339
 
{
340
 
    QSize hint = d_data->layout->minimumSizeHint(this);
341
 
    hint += QSize(2 * frameWidth(), 2 * frameWidth());
342
 
 
343
 
    return hint;
344
 
}
345
 
 
346
 
/*! 
347
 
  Resize and update internal layout
348
 
  \param e Resize event
349
 
*/
350
 
void QwtPlot::resizeEvent(QResizeEvent *e)
351
 
{
352
 
    QFrame::resizeEvent(e);
353
 
    updateLayout();
354
 
}
355
 
 
356
 
/*!
357
 
  \brief Redraw the plot
358
 
 
359
 
  If the autoReplot option is not set (which is the default)
360
 
  or if any curves are attached to raw data, the plot has to
361
 
  be refreshed explicitly in order to make changes visible.
362
 
 
363
 
  \sa setAutoReplot()
364
 
  \warning Calls canvas()->repaint, take care of infinite recursions
365
 
*/
366
 
void QwtPlot::replot()
367
 
{
368
 
    bool doAutoReplot = autoReplot();
369
 
    setAutoReplot(false);
370
 
 
371
 
    updateAxes();
372
 
 
373
 
    /*
374
 
      Maybe the layout needs to be updated, because of changed
375
 
      axes labels. We need to process them here before painting
376
 
      to avoid that scales and canvas get out of sync.
377
 
     */
378
 
#if QT_VERSION >= 0x040000
379
 
    QApplication::sendPostedEvents(this, QEvent::LayoutRequest);
380
 
#else
381
 
    QApplication::sendPostedEvents(this, QEvent::LayoutHint);
382
 
#endif
383
 
 
384
 
    d_data->canvas->replot();
385
 
 
386
 
    setAutoReplot(doAutoReplot);
387
 
}
388
 
 
389
 
/*!
390
 
  \brief Adjust plot content to its current size.
391
 
  \sa resizeEvent()
392
 
*/
393
 
void QwtPlot::updateLayout()
394
 
{
395
 
    d_data->layout->activate(this, contentsRect());
396
 
 
397
 
    //
398
 
    // resize and show the visible widgets
399
 
    //
400
 
    if (!d_data->lblTitle->text().isEmpty())
401
 
    {
402
 
        d_data->lblTitle->setGeometry(d_data->layout->titleRect());
403
 
        if (!d_data->lblTitle->isVisible())
404
 
            d_data->lblTitle->show();
405
 
    }
406
 
    else
407
 
        d_data->lblTitle->hide();
408
 
 
409
 
    for (int axisId = 0; axisId < axisCnt; axisId++ )
410
 
    {
411
 
        if (axisEnabled(axisId) )
412
 
        {
413
 
            axisWidget(axisId)->setGeometry(d_data->layout->scaleRect(axisId));
414
 
 
415
 
            if ( axisId == xBottom || axisId == xTop )
416
 
            {
417
 
                QRegion r(d_data->layout->scaleRect(axisId));
418
 
                if ( axisEnabled(yLeft) )
419
 
                    r = r.subtract(QRegion(d_data->layout->scaleRect(yLeft)));
420
 
                if ( axisEnabled(yRight) )
421
 
                    r = r.subtract(QRegion(d_data->layout->scaleRect(yRight)));
422
 
                r.translate(-d_data->layout->scaleRect(axisId).x(), 
423
 
                    -d_data->layout->scaleRect(axisId).y());
424
 
 
425
 
                axisWidget(axisId)->setMask(r);
426
 
            }
427
 
            if (!axisWidget(axisId)->isVisible())
428
 
                axisWidget(axisId)->show();
429
 
        }
430
 
        else
431
 
            axisWidget(axisId)->hide();
432
 
    }
433
 
 
434
 
    if ( d_data->legend && 
435
 
        d_data->layout->legendPosition() != ExternalLegend )
436
 
    {
437
 
        if (d_data->legend->itemCount() > 0)
438
 
        {
439
 
            d_data->legend->setGeometry(d_data->layout->legendRect());
440
 
            d_data->legend->show();
441
 
        }
442
 
        else
443
 
            d_data->legend->hide();
444
 
    }
445
 
 
446
 
    d_data->canvas->setGeometry(d_data->layout->canvasRect());
447
 
}
448
 
 
449
 
/*! 
450
 
   Update the focus tab order
451
 
 
452
 
   The order is changed so that the canvas will be in front of the
453
 
   first legend item, or behind the last legend item - depending
454
 
   on the position of the legend.
455
 
*/
456
 
 
457
 
void QwtPlot::updateTabOrder()
458
 
{
459
 
#if QT_VERSION >= 0x040000
460
 
    using namespace Qt; // QWidget::NoFocus/Qt::NoFocus
461
 
#else
462
 
    if ( d_data->canvas->focusPolicy() == NoFocus )
463
 
        return;
464
 
#endif
465
 
    if ( d_data->legend.isNull()  
466
 
        || d_data->layout->legendPosition() == ExternalLegend
467
 
        || d_data->legend->legendItems().count() == 0 )
468
 
    {
469
 
        return;
470
 
    }
471
 
 
472
 
    // Depending on the position of the legend the 
473
 
    // tab order will be changed that the canvas is
474
 
    // next to the last legend item, or before
475
 
    // the first one. 
476
 
 
477
 
    const bool canvasFirst = 
478
 
        d_data->layout->legendPosition() == QwtPlot::BottomLegend ||
479
 
        d_data->layout->legendPosition() == QwtPlot::RightLegend;
480
 
 
481
 
    QWidget *previous = NULL; 
482
 
 
483
 
    QWidget *w;
484
 
#if QT_VERSION >= 0x040000
485
 
    w = d_data->canvas;
486
 
    while ( ( w = w->nextInFocusChain() ) != d_data->canvas )
487
 
#else
488
 
    if ( focusData() == NULL )
489
 
        return;
490
 
 
491
 
    while ( focusData()->next() != d_data->canvas );
492
 
    while ( (w = focusData()->next()) != d_data->canvas )
493
 
#endif
494
 
    {
495
 
        bool isLegendItem = false;
496
 
        if ( w->focusPolicy() != NoFocus 
497
 
            && w->parent() && w->parent() == d_data->legend->contentsWidget() )
498
 
        {
499
 
            isLegendItem = true;
500
 
        }
501
 
 
502
 
        if ( canvasFirst )
503
 
        {
504
 
            if ( isLegendItem )
505
 
                break;
506
 
 
507
 
            previous = w;
508
 
        }
509
 
        else
510
 
        {
511
 
            if ( isLegendItem )
512
 
                previous = w;
513
 
            else
514
 
            {
515
 
                if ( previous )
516
 
                    break;
517
 
            }
518
 
        }
519
 
    }
520
 
 
521
 
    if ( previous && previous != d_data->canvas)
522
 
        setTabOrder(previous, d_data->canvas);
523
 
}
524
 
 
525
 
/*! 
526
 
  Redraw the canvas.
527
 
  \param painter Painter used for drawing
528
 
 
529
 
  \warning drawCanvas calls drawItems what is also used
530
 
           for printing. Applications that like to add individual
531
 
           plot items better overload drawItems()
532
 
  \sa drawItems()
533
 
*/
534
 
void QwtPlot::drawCanvas(QPainter *painter)
535
 
{
536
 
    QwtScaleMap maps[axisCnt];
537
 
    for ( int axisId = 0; axisId < axisCnt; axisId++ )
538
 
        maps[axisId] = canvasMap(axisId);
539
 
 
540
 
    drawItems(painter, 
541
 
        d_data->canvas->contentsRect(), maps, QwtPlotPrintFilter());
542
 
}
543
 
 
544
 
/*! 
545
 
  Redraw the canvas items.
546
 
  \param painter Painter used for drawing
547
 
  \param rect Bounding rectangle where to paint
548
 
  \param map QwtPlot::axisCnt maps, mapping between plot and paint device coordinates
549
 
  \param pfilter Plot print filter
550
 
*/
551
 
 
552
 
void QwtPlot::drawItems(QPainter *painter, const QRect &rect, 
553
 
        const QwtScaleMap map[axisCnt], 
554
 
        const QwtPlotPrintFilter &pfilter) const
555
 
{
556
 
    const QwtPlotItemList& itmList = itemList();
557
 
    for ( QwtPlotItemIterator it = itmList.begin();
558
 
        it != itmList.end(); ++it )
559
 
    {
560
 
        QwtPlotItem *item = *it;
561
 
        if ( item && item->isVisible() )
562
 
        {
563
 
            if ( !(pfilter.options() & QwtPlotPrintFilter::PrintGrid)
564
 
                && item->rtti() == QwtPlotItem::Rtti_PlotGrid )
565
 
            {
566
 
                continue;
567
 
            }
568
 
 
569
 
            painter->save();
570
 
 
571
 
#if QT_VERSION >= 0x040000
572
 
            painter->setRenderHint(QPainter::Antialiasing,
573
 
                item->testRenderHint(QwtPlotItem::RenderAntialiased) );
574
 
#endif
575
 
 
576
 
            item->draw(painter, 
577
 
                map[item->xAxis()], map[item->yAxis()],
578
 
                rect);
579
 
 
580
 
            painter->restore();
581
 
        }
582
 
    }
583
 
}
584
 
 
585
 
/*!
586
 
  \param axisId Axis
587
 
  \return Map for the axis on the canvas. With this map pixel coordinates can
588
 
          translated to plot coordinates and vice versa.
589
 
  \sa QwtScaleMap, transform(), invTransform()
590
 
  
591
 
*/
592
 
QwtScaleMap QwtPlot::canvasMap(int axisId) const
593
 
{
594
 
    QwtScaleMap map;
595
 
    if ( !d_data->canvas )
596
 
        return map;
597
 
 
598
 
    map.setTransformation(axisScaleEngine(axisId)->transformation());
599
 
 
600
 
    const QwtScaleDiv *sd = axisScaleDiv(axisId);
601
 
    map.setScaleInterval(sd->lowerBound(), sd->upperBound());
602
 
 
603
 
    if ( axisEnabled(axisId) )
604
 
    {
605
 
        const QwtScaleWidget *s = axisWidget(axisId);
606
 
        if ( axisId == yLeft || axisId == yRight )
607
 
        {
608
 
            int y = s->y() + s->startBorderDist() - d_data->canvas->y();
609
 
            int h = s->height() - s->startBorderDist() - s->endBorderDist();
610
 
            map.setPaintInterval(y + h, y);
611
 
        }
612
 
        else
613
 
        {
614
 
            int x = s->x() + s->startBorderDist() - d_data->canvas->x();
615
 
            int w = s->width() - s->startBorderDist() - s->endBorderDist();
616
 
            map.setPaintInterval(x, x + w);
617
 
        }
618
 
    }
619
 
    else
620
 
    {
621
 
        const int margin = plotLayout()->canvasMargin(axisId);
622
 
 
623
 
        const QRect &canvasRect = d_data->canvas->contentsRect();
624
 
        if ( axisId == yLeft || axisId == yRight )
625
 
        {
626
 
            map.setPaintInterval(canvasRect.bottom() - margin, 
627
 
                canvasRect.top() + margin);
628
 
        }
629
 
        else
630
 
        {
631
 
            map.setPaintInterval(canvasRect.left() + margin, 
632
 
                canvasRect.right() - margin);
633
 
        }
634
 
    }
635
 
    return map;
636
 
}
637
 
 
638
 
/*!
639
 
  Change the margin of the plot. The margin is the space
640
 
  around all components.
641
 
 
642
 
  \param margin new margin
643
 
  \sa QwtPlotLayout::setMargin(), margin(), plotLayout()
644
 
*/
645
 
void QwtPlot::setMargin(int margin)
646
 
{
647
 
    if ( margin < 0 )
648
 
        margin = 0;
649
 
 
650
 
    if ( margin != d_data->layout->margin() )
651
 
    {
652
 
        d_data->layout->setMargin(margin);
653
 
        updateLayout();
654
 
    }
655
 
}
656
 
 
657
 
/*!
658
 
    \return margin
659
 
    \sa setMargin(), QwtPlotLayout::margin(), plotLayout()
660
 
*/
661
 
int QwtPlot::margin() const
662
 
{
663
 
    return d_data->layout->margin();
664
 
}
665
 
 
666
 
/*!
667
 
  \brief Change the background of the plotting area
668
 
  
669
 
  Sets c to QColorGroup::Background of all colorgroups of 
670
 
  the palette of the canvas. Using canvas()->setPalette()
671
 
  is a more powerful way to set these colors.
672
 
  \param c new background color
673
 
*/
674
 
void QwtPlot::setCanvasBackground(const QColor &c)
675
 
{
676
 
    QPalette p = d_data->canvas->palette();
677
 
 
678
 
    for ( int i = 0; i < QPalette::NColorGroups; i++ )
679
 
    {
680
 
#if QT_VERSION < 0x040000
681
 
        p.setColor((QPalette::ColorGroup)i, QColorGroup::Background, c);
682
 
#else
683
 
        p.setColor((QPalette::ColorGroup)i, QPalette::Background, c);
684
 
#endif
685
 
    }
686
 
 
687
 
    canvas()->setPalette(p);
688
 
}
689
 
 
690
 
/*!
691
 
  Nothing else than: canvas()->palette().color(
692
 
        QPalette::Normal, QColorGroup::Background);
693
 
  
694
 
  \return the background color of the plotting area.
695
 
*/
696
 
const QColor & QwtPlot::canvasBackground() const
697
 
{
698
 
#if QT_VERSION < 0x040000
699
 
    return canvas()->palette().color(
700
 
        QPalette::Normal, QColorGroup::Background);
701
 
#else
702
 
    return canvas()->palette().color(
703
 
        QPalette::Normal, QPalette::Background);
704
 
#endif
705
 
}
706
 
 
707
 
/*!
708
 
  \brief Change the border width of the plotting area
709
 
  Nothing else than canvas()->setLineWidth(w), 
710
 
  left for compatibility only.
711
 
  \param w new border width
712
 
*/
713
 
void QwtPlot::setCanvasLineWidth(int w)
714
 
{
715
 
    canvas()->setLineWidth(w);
716
 
    updateLayout();
717
 
}
718
 
 
719
 
/*! 
720
 
  Nothing else than: canvas()->lineWidth(), 
721
 
  left for compatibility only.
722
 
  \return the border width of the plotting area
723
 
*/
724
 
int QwtPlot::canvasLineWidth() const
725
 
726
 
    return canvas()->lineWidth();
727
 
}
728
 
 
729
 
/*!
730
 
  \return \c true if the specified axis exists, otherwise \c false
731
 
  \param axisId axis index
732
 
 */
733
 
bool QwtPlot::axisValid(int axisId)
734
 
{
735
 
    return ((axisId >= QwtPlot::yLeft) && (axisId < QwtPlot::axisCnt));
736
 
}
737
 
 
738
 
/*!
739
 
  Called internally when the legend has been clicked on.
740
 
  Emits a legendClicked() signal.
741
 
*/
742
 
void QwtPlot::legendItemClicked()
743
 
{
744
 
    if ( d_data->legend && sender()->isWidgetType() )
745
 
    {
746
 
        QwtPlotItem *plotItem = 
747
 
            (QwtPlotItem*)d_data->legend->find((QWidget *)sender());
748
 
        if ( plotItem )
749
 
            emit legendClicked(plotItem);
750
 
    }
751
 
}
752
 
 
753
 
/*!
754
 
  Called internally when the legend has been checked
755
 
  Emits a legendClicked() signal.
756
 
*/
757
 
void QwtPlot::legendItemChecked(bool on)
758
 
{
759
 
    if ( d_data->legend && sender()->isWidgetType() )
760
 
    {
761
 
        QwtPlotItem *plotItem = 
762
 
            (QwtPlotItem*)d_data->legend->find((QWidget *)sender());
763
 
        if ( plotItem )
764
 
            emit legendChecked(plotItem, on);
765
 
    }
766
 
}
767
 
 
768
 
/*! 
769
 
   Remove all curves and markers
770
 
   \deprecated Use QwtPlotDeict::detachItems instead
771
 
*/
772
 
void QwtPlot::clear()
773
 
{
774
 
    detachItems(QwtPlotItem::Rtti_PlotCurve);
775
 
    detachItems(QwtPlotItem::Rtti_PlotMarker);
776
 
}
777
 
 
778
 
/*!
779
 
  \brief Insert a legend
780
 
 
781
 
  If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend
782
 
  the legend will be organized in one column from top to down. 
783
 
  Otherwise the legend items will be placed in a table 
784
 
  with a best fit number of columns from left to right.
785
 
 
786
 
  If pos != QwtPlot::ExternalLegend the plot widget will become 
787
 
  parent of the legend. It will be deleted when the plot is deleted, 
788
 
  or another legend is set with insertLegend().
789
 
       
790
 
  \param legend Legend
791
 
  \param pos The legend's position. For top/left position the number
792
 
             of colums will be limited to 1, otherwise it will be set to
793
 
             unlimited. 
794
 
 
795
 
  \param ratio Ratio between legend and the bounding rect
796
 
               of title, canvas and axes. The legend will be shrinked
797
 
               if it would need more space than the given ratio.
798
 
               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
799
 
               it will be reset to the default ratio.
800
 
               The default vertical/horizontal ratio is 0.33/0.5.
801
 
 
802
 
  \sa legend(), QwtPlotLayout::legendPosition(), 
803
 
      QwtPlotLayout::setLegendPosition()
804
 
*/
805
 
void QwtPlot::insertLegend(QwtLegend *legend, 
806
 
    QwtPlot::LegendPosition pos, double ratio)
807
 
{
808
 
    d_data->layout->setLegendPosition(pos, ratio);
809
 
 
810
 
    if ( legend != d_data->legend )
811
 
    {
812
 
        if ( d_data->legend && d_data->legend->parent() == this )
813
 
            delete d_data->legend;
814
 
 
815
 
        d_data->legend = legend;
816
 
 
817
 
        if ( d_data->legend )
818
 
        {
819
 
            if ( pos != ExternalLegend )
820
 
            {
821
 
                if ( d_data->legend->parent() != this )
822
 
                {
823
 
#if QT_VERSION < 0x040000
824
 
                    d_data->legend->reparent(this, QPoint(0, 0));
825
 
#else
826
 
                    d_data->legend->setParent(this);
827
 
#endif
828
 
                }
829
 
            }
830
 
 
831
 
            const QwtPlotItemList& itmList = itemList();
832
 
            for ( QwtPlotItemIterator it = itmList.begin();
833
 
                it != itmList.end(); ++it )
834
 
            {
835
 
                (*it)->updateLegend(d_data->legend);
836
 
            }
837
 
 
838
 
            QLayout *l = d_data->legend->contentsWidget()->layout();
839
 
            if ( l && l->inherits("QwtDynGridLayout") )
840
 
            {
841
 
                QwtDynGridLayout *tl = (QwtDynGridLayout *)l;
842
 
                switch(d_data->layout->legendPosition())
843
 
                {
844
 
                    case LeftLegend:
845
 
                    case RightLegend:
846
 
                        tl->setMaxCols(1); // 1 column: align vertical
847
 
                        break;
848
 
                    case TopLegend:
849
 
                    case BottomLegend:
850
 
                        tl->setMaxCols(0); // unlimited
851
 
                        break;
852
 
                    case ExternalLegend:
853
 
                        break;
854
 
                }
855
 
            }
856
 
        }
857
 
        updateTabOrder();
858
 
    }
859
 
 
860
 
    updateLayout();
861
 
}