QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_pixel_matrix.h
1/******************************************************************************
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 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner -> QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_PIXEL_MATRIX_H
28#define QWT_PIXEL_MATRIX_H
29
30#include "qwt_global.h"
31
32#include <qbitarray.h>
33#include <qrect.h>
34
41class QWT_EXPORT QwtPixelMatrix : public QBitArray
42{
43public:
44 // Constructor with bounding rectangle
45 explicit QwtPixelMatrix(const QRect& rect);
46 // Destructor
48
49 // Set the bounding rectangle of the matrix
50 void setRect(const QRect& rect);
51 // Get the bounding rectangle
52 QRect rect() const;
53
54 // Test if a pixel has been set
55 bool testPixel(int x, int y) const;
56 // Set a pixel and test if it was set before
57 bool testAndSetPixel(int x, int y, bool on);
58
59 // Calculate the index in the bit field for a position
60 int index(int x, int y) const;
61
62private:
63 QRect m_rect;
64};
65
72inline bool QwtPixelMatrix::testPixel(int x, int y) const
73{
74 const int idx = index(x, y);
75 return (idx >= 0) ? testBit(idx) : true;
76}
77
85inline bool QwtPixelMatrix::testAndSetPixel(int x, int y, bool on)
86{
87 const int idx = index(x, y);
88 if (idx < 0)
89 return true;
90
91 const bool onBefore = testBit(idx);
92 setBit(idx, on);
93
94 return onBefore;
95}
96
103inline int QwtPixelMatrix::index(int x, int y) const
104{
105 const int dx = x - m_rect.x();
106 if (dx < 0 || dx >= m_rect.width())
107 return -1;
108
109 const int dy = y - m_rect.y();
110 if (dy < 0 || dy >= m_rect.height())
111 return -1;
112
113 return dy * m_rect.width() + dx;
114}
115
116#endif
A bit field corresponding to the pixels of a rectangle
Definition qwt_pixel_matrix.h:42
bool testPixel(int x, int y) const
Test if a pixel has been set
Definition qwt_pixel_matrix.h:72
bool testAndSetPixel(int x, int y, bool on)
Set a pixel and test if a pixel has been set before
Definition qwt_pixel_matrix.h:85
int index(int x, int y) const
Calculate the index in the bit field corresponding to a position
Definition qwt_pixel_matrix.h:103