00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
#include <qpainter.h>
00011
#include "qwt_painter.h"
00012
#include "qwt_grid.h"
00013
00015 QwtGrid::QwtGrid()
00016 {
00017 d_xMinEnabled = FALSE;
00018 d_yMinEnabled = FALSE;
00019 d_xEnabled = TRUE;
00020 d_yEnabled = TRUE;
00021 }
00022
00024 QwtGrid::~QwtGrid()
00025 {
00026 }
00027
00035 void QwtGrid::enableX(
bool tf)
00036 {
00037
if ( d_xEnabled != tf )
00038 {
00039 d_xEnabled = tf;
00040
gridChanged();
00041 }
00042 }
00043
00049 void QwtGrid::enableY(
bool tf)
00050 {
00051
if ( d_yEnabled != tf )
00052 {
00053 d_yEnabled = tf;
00054
gridChanged();
00055 }
00056 }
00057
00063 void QwtGrid::enableXMin(
bool tf)
00064 {
00065
if ( d_xMinEnabled != tf )
00066 {
00067 d_xMinEnabled = tf;
00068
gridChanged();
00069 }
00070 }
00071
00077 void QwtGrid::enableYMin(
bool tf)
00078 {
00079
if ( d_yMinEnabled != tf )
00080 {
00081 d_yMinEnabled = tf;
00082
gridChanged();
00083 }
00084 }
00085
00093 void QwtGrid::setXDiv(
const QwtScaleDiv &sx)
00094 {
00095
if ( d_sdx != sx )
00096 {
00097 d_sdx = sx;
00098
gridChanged();
00099 }
00100 }
00101
00109 void QwtGrid::setYDiv(
const QwtScaleDiv &sy)
00110 {
00111
if ( d_sdy != sy )
00112 {
00113 d_sdy = sy;
00114
gridChanged();
00115 }
00116 }
00117
00122 void QwtGrid::setPen(
const QPen &p)
00123 {
00124
if ( d_majPen != p || d_minPen != p )
00125 {
00126 d_majPen = p;
00127 d_minPen = p;
00128
gridChanged();
00129 }
00130 }
00131
00136 void QwtGrid::setMajPen(
const QPen &p)
00137 {
00138
if ( d_majPen != p )
00139 {
00140 d_majPen = p;
00141
gridChanged();
00142 }
00143 }
00144
00149 void QwtGrid::setMinPen(
const QPen &p)
00150 {
00151
if ( d_minPen != p )
00152 {
00153 d_minPen = p;
00154
gridChanged();
00155 }
00156 }
00157
00170 void QwtGrid::draw(QPainter *p,
const QRect &r,
00171
const QwtDiMap &mx,
const QwtDiMap &my)
const
00172
{
00173
int x1 = r.left();
00174
int x2 = r.right();
00175
int y1 = r.top();
00176
int y2 = r.bottom();
00177
00178
00179
00180
00181 p->setPen(d_minPen);
00182
00183
if (d_xEnabled && d_xMinEnabled)
00184 {
00185
for (uint i = 0; i < d_sdx.
minCnt(); i++)
00186 {
00187
const int x = mx.
transform(d_sdx.
minMark(i));
00188
if ((x >= x1) && (x <= x2))
00189
QwtPainter::drawLine(p, x, y1, x, y2);
00190 }
00191 }
00192
00193
if (d_yEnabled && d_yMinEnabled)
00194 {
00195
for (uint i = 0; i < d_sdy.
minCnt(); i++)
00196 {
00197
const int y = my.
transform(d_sdy.
minMark(i));
00198
if ((y >= y1) && (y <= y2))
00199
QwtPainter::drawLine(p, x1, y, x2, y);
00200 }
00201 }
00202
00203
00204
00205
00206 p->setPen(d_majPen);
00207
00208
if (d_xEnabled)
00209 {
00210
for (uint i = 0; i < d_sdx.
majCnt(); i++)
00211 {
00212
const int x = mx.
transform(d_sdx.
majMark(i));
00213
if ((x >= x1) && (x <= x2))
00214
QwtPainter::drawLine(p, x, y1, x, y2);
00215 }
00216
00217 }
00218
00219
if (d_yEnabled)
00220 {
00221
for (uint i = 0; i < d_sdy.
majCnt(); i++)
00222 {
00223
const int y = my.
transform(d_sdy.
majMark(i));
00224
if ((y >= y1) && (y <= y2))
00225
QwtPainter::drawLine(p, x1, y, x2, y);
00226 }
00227 }
00228 }
00229
00234 const QPen &
QwtGrid::majPen()
const
00235
{
00236
return d_majPen;
00237 }
00238
00243 const QPen &
QwtGrid::minPen()
const
00244
{
00245
return d_minPen;
00246 }
00247
00252 bool QwtGrid::xEnabled()
const
00253
{
00254
return d_xEnabled;
00255 }
00256
00261 bool QwtGrid::xMinEnabled()
const
00262
{
00263
return d_xMinEnabled;
00264 }
00265
00270 bool QwtGrid::yEnabled()
const
00271
{
00272
return d_yEnabled;
00273 }
00274
00279 bool QwtGrid::yMinEnabled()
const
00280
{
00281
return d_yMinEnabled;
00282 }
00283
00284
00286 const QwtScaleDiv &
QwtGrid::xScaleDiv()
const
00287
{
00288
return d_sdx;
00289 }
00290
00292 const QwtScaleDiv &
QwtGrid::yScaleDiv()
const
00293
{
00294
return d_sdy;
00295 }
00296
00304 void QwtGrid::gridChanged()
00305 {
00306 }
00307