File indexing completed on 2024-05-12 16:33:26

0001 /* This file is part of the KDE project
0002 
0003    Copyright 2008 Johannes Simon <johannes.simon@gmail.com>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef KCHART_CELLREGION_H
0022 #define KCHART_CELLREGION_H
0023 
0024 
0025 // Qt
0026 #include <Qt>
0027 #include <QVector>
0028 #include <QRect>
0029 
0030 // KoChart
0031 #include "ChartShape.h"
0032 
0033 
0034 class QRect;
0035 class QPoint;
0036 
0037 namespace KoChart {
0038 
0039 /**
0040  * @brief A CellRegion represents a selection of cells in a table.
0041  *
0042  * Seen from the outside, each CellRegion is one-dimensional, i.e. a
0043  * cell in it can be addressed by a single index.  However, the actual
0044  * cells in it can be broken up into several one-dimensional
0045  * rectangles with either width=1 or height=1.
0046  *
0047  * Every data set on the chart has five independent cell regions
0048  * that indicate where the data in a series comes from:
0049  * 1) a label to represent the data set (size 1x1)
0050  * 2) a region for y values
0051  * 3) one for x values (only for scatter and bubble charts)
0052  * 4) for bubble widths (only for bubble charts)
0053  * 5) for the category data (one label for every x value/column on
0054  *    the x axis; this region is the same among all data sets)
0055  *
0056  * A CellRegion can also represent a region in a spreadsheet that
0057  * is relevant for the data of a chart. That way, the initial chart
0058  * is created based on the cell selection the user made before
0059  * inserting the chart shape.
0060  *
0061  * In contrast to a QItemSelection, a CellRegion can include header
0062  * data. Therefore, CellRegion(QPoint(1, 1)) represents the
0063  * top-left item of a QAbstractItemModel.
0064  *
0065  * An instance can represent either a simple, continuous region of
0066  * cells, as in most cases, or a more complex discontinuous region.
0067  * In its second form, the orientation of each separate continuous
0068  * region can vary, as well as their sizes.
0069  */
0070 
0071 // Definition in TableSource.h
0072 class Table;
0073 
0074 class CellRegion
0075 {
0076 public:
0077     CellRegion();
0078     CellRegion(const CellRegion& region);
0079     CellRegion(TableSource *source, const QString& regions);
0080     CellRegion(Table *table, const QPoint &point);
0081     CellRegion(Table *table, const QRect &rect);
0082     CellRegion(Table *table, const QVector<QRect> &rects);
0083     explicit CellRegion(Table *table);
0084     ~CellRegion();
0085     
0086     CellRegion& operator = (const CellRegion& region);    
0087     bool operator == (const CellRegion &other) const;
0088 
0089     Table *table() const;
0090     
0091     QVector<QRect> rects() const;
0092     
0093     QString sheetName() const;
0094 
0095     bool isValid() const;
0096 
0097     QString toString() const;
0098     
0099     bool contains(const QPoint &point, bool proper = false) const;
0100     bool contains(const QRect &rect, bool proper = false) const;
0101     
0102     bool intersects(const CellRegion &other) const;
0103 
0104     CellRegion intersected(const QRect &rect) const;
0105     
0106     int cellCount() const;
0107     int rectCount() const;
0108     
0109     Qt::Orientation orientation() const;
0110     
0111     void add(const CellRegion &other);
0112     void add(const QPoint &point);
0113     void add(const QRect &rect);
0114     void add(const QVector<QRect> &rects);
0115     
0116     QRect boundingRect() const;
0117     
0118     bool   hasPointAtIndex(int index) const;    
0119     QPoint pointAtIndex(int index) const;
0120     int    indexAtPoint(const QPoint &point) const;
0121     
0122     static int rangeCharToInt(char c);
0123     static int rangeStringToInt(const QString &string);
0124     static QString rangeIntToString(int i);
0125 
0126     static QString columnName(uint column);
0127 
0128 private:
0129     class Private;
0130     Private *const d;
0131 };
0132 
0133 }
0134 
0135 QDebug operator<<(QDebug dbg, const KoChart::CellRegion &r);
0136 
0137 #endif // KCHART_CELLREGION_H