Index: plotmatrix/plotmatrix.cpp
===================================================================
--- plotmatrix/plotmatrix.cpp (revision 1477)
+++ plotmatrix/plotmatrix.cpp (working copy)
@@ -14,6 +14,9 @@
#include <qwt_plot.h>
#include <qwt_scale_widget.h>
#include <qwt_scale_draw.h>
+#include <qwt_plot_curve.h>
+#include <qwt_plot_layout.h>
+#include <qwt_legend.h>
#include "plotmatrix.h"
class PlotMatrix::PrivateData
@@ -47,6 +50,30 @@
layout->addWidget( plot, row, col );
+if (row
== 0 && col
== 0) plot
->axisWidget
(QwtPlot::yLeft)->setTitle
("Hello!");
+if (row
== 1 && col
== 0) plot
->axisWidget
(QwtPlot::yLeft)->setTitle
("Hello!<BR>Units");
+if (row == 1 && col == 3) {
+ data.
push_back (QPointF (-420,
10));
+ data.
push_back (QPointF (940,
-10));
+ curve->setSamples (data);
+ curve
->setPen
( QPen( Qt
::cyan ) );
+ curve->attach (plot);
+ // legend
+ plot
->insertLegend
( legend,
QwtPlot::RightLegend );
+}
+
for ( int axis
= 0; axis <
QwtPlot::axisCnt; axis
++ ) {
connect( plot->axisWidget( axis ),
@@ -276,7 +303,13 @@
sd->setMinimumExtent( 0.0 );
- const double extent = sd->extent( scaleWidget->font() );
+ double extent = sd->extent( scaleWidget->font() );
+ if( !scaleWidget->title().isEmpty())
+ extent += scaleWidget->title().textSize().height();
+ if (p->legend () && axis == p->plotLayout ()->legendPosition ()) {
+ double legendSize = p->legend ()->sizeHint ().width ();
+ extent += legendSize;
+ }
if ( extent > maxExtent )
maxExtent = extent;
}
@@ -287,7 +320,16 @@
if ( p )
{
- scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
+ double extent = maxExtent;
+ if(!scaleWidget->title().text().isEmpty()) {
+ extent -= scaleWidget->title().textSize().height();
+ }
+
+ if (p->legend () && axis == p->plotLayout ()->legendPosition ()) {
+ double legendSize = p->legend ()->sizeHint ().width ();
+ extent -= legendSize;
+ }
+ scaleWidget->scaleDraw()->setMinimumExtent( extent );
}
}
}
Index: plotmatrix/plotmatrix.cpp
===================================================================
--- plotmatrix/plotmatrix.cpp (revision 1477)
+++ plotmatrix/plotmatrix.cpp (working copy)
@@ -14,6 +14,9 @@
#include <qwt_plot.h>
#include <qwt_scale_widget.h>
#include <qwt_scale_draw.h>
+#include <qwt_plot_curve.h>
+#include <qwt_plot_layout.h>
+#include <qwt_legend.h>
#include "plotmatrix.h"
class PlotMatrix::PrivateData
@@ -47,6 +50,30 @@
QwtPlot *plot = new QwtPlot( this );
layout->addWidget( plot, row, col );
+if (row == 0 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Hello!");
+if (row == 1 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Hello!<BR>Units");
+if (row == 1 && col == 3) {
+ QVector <QPointF> data;
+ data.push_back (QPointF (-420, 10));
+ data.push_back (QPointF (940, -10));
+ QwtPlotCurve *curve = new QwtPlotCurve ("data");
+ curve->setSamples (data);
+ curve->setPen( QPen( Qt::cyan ) );
+ curve->attach (plot);
+ // legend
+ QwtLegend *legend = new QwtLegend;
+ plot->insertLegend( legend, QwtPlot::RightLegend );
+}
+
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
connect( plot->axisWidget( axis ),
@@ -276,7 +303,13 @@
QwtScaleDraw *sd = scaleWidget->scaleDraw();
sd->setMinimumExtent( 0.0 );
- const double extent = sd->extent( scaleWidget->font() );
+ double extent = sd->extent( scaleWidget->font() );
+ if( !scaleWidget->title().isEmpty())
+ extent += scaleWidget->title().textSize().height();
+ if (p->legend () && axis == p->plotLayout ()->legendPosition ()) {
+ double legendSize = p->legend ()->sizeHint ().width ();
+ extent += legendSize;
+ }
if ( extent > maxExtent )
maxExtent = extent;
}
@@ -287,7 +320,16 @@
if ( p )
{
QwtScaleWidget *scaleWidget = p->axisWidget( axis );
- scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
+ double extent = maxExtent;
+ if(!scaleWidget->title().text().isEmpty()) {
+ extent -= scaleWidget->title().textSize().height();
+ }
+
+ if (p->legend () && axis == p->plotLayout ()->legendPosition ()) {
+ double legendSize = p->legend ()->sizeHint ().width ();
+ extent -= legendSize;
+ }
+ scaleWidget->scaleDraw()->setMinimumExtent( extent );
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks