Quark  0.1
Matrix.h++
Go to the documentation of this file.
1 #ifndef __libquark_gui_Matrix_hxx
2 #define __libquark_gui_Matrix_hxx
3 
4 #include <QDataStream>
5 #include <QList>
6 #include <QPoint>
7 
8 namespace quark {
9 namespace gui {
10 
19 template<typename T> class Matrix
20 {
21  public:
22 
29  Matrix(int width = 0, int height = 0);
30 
32  ~Matrix();
33 
35  int rows() const;
36 
38  int columns() const;
39 
41  bool isEmpty() const
42  { return(_rows.isEmpty()); }
43 
51  void setItemAt(int row, int column, T item);
52 
60  T getItemAt(int row, int column) const;
61 
68  void insertRows(int rowIndex, int rowCount);
69 
76  void deleteRows(int rowIndex, int rowCount);
77 
84  void insertColumns(int columnIndex, int columnCount);
85 
92  void deleteColumns(int columnIndex, int columnCount);
93 
104  bool isRegionEmpty(int row, int column, int width, int height) const;
105 
115  QPoint findEmptyRegion(int width, int height) const;
116 
124  bool read(QDataStream &stream);
125 
132  void write(QDataStream &stream) const;
133 
134  protected:
135 
137  virtual bool isEmptyValue(const T& value) const;
138 
139  private:
140 
141  void setSize(int rows, int cols);
142 
143  QList<QList<T>*> _rows;
144 };
145 
146 #include <quark/MatrixImpl.h++>
147 
148 } // namespace gui
149 } // namespace quark
150 
151 /*
152  */
153 
154 template<typename T>
155  QDataStream& operator<<(QDataStream &stream,
156  const quark::gui::Matrix<T> &matrix)
157 {
158  matrix.write(stream);
159  return(stream);
160 }
161 
162 /*
163  */
164 
165 template<typename T>
166  QDataStream& operator>>(QDataStream& stream, quark::gui::Matrix<T> &matrix)
167 {
168  matrix.read(stream);
169  return(stream);
170 }
171 
172 #endif // __libquark_gui_Matrix_hxx
int rows() const
Returns the height of the matrix, in rows.
bool isEmpty() const
Tests if the matrix is empty.
Definition: Matrix.h++:41
Matrix(int width=0, int height=0)
Constructs a matrix with the given dimensions.
QPoint findEmptyRegion(int width, int height) const
Attempts to locate a rectangular region with the given dimensions in the matrix such that all cells i...
T getItemAt(int row, int column) const
Returns the item at the given row and column.
QDataStream & operator>>(QDataStream &stream, quark::gui::Matrix< T > &matrix)
Definition: Matrix.h++:166
A matrix data model.
Definition: Matrix.h++:19
QDataStream & operator<<(QDataStream &stream, const quark::gui::Matrix< T > &matrix)
Definition: Matrix.h++:155
Definition: BarChartView.h++:6
bool isRegionEmpty(int row, int column, int width, int height) const
Tests if the given region in the matrix contains only "empty" items.
bool read(QDataStream &stream)
Reads the matrix from a data stream.
virtual bool isEmptyValue(const T &value) const
Tests if a given item is to be considered "empty".
void insertColumns(int columnIndex, int columnCount)
Inserts new columns into the matrix.
void deleteRows(int rowIndex, int rowCount)
Deletes rows from the matrix.
~Matrix()
Destructor.
int columns() const
Returns the width of the matrix, in columns.
void setItemAt(int row, int column, T item)
Sets the item at the given row and column.
void write(QDataStream &stream) const
Writes the matrix to a data stream.
void deleteColumns(int columnIndex, int columnCount)
Deletes columns from the matrix.
void insertRows(int rowIndex, int rowCount)
Inserts new rows into the matrix.