WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZblDataModel.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2015 Bob Dinitto
4  *
5  * Filename: ZblDataModel.h
6  * Created on: 3/22/2015
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef ZBLDATAMODEL_H
26 #define ZBLDATAMODEL_H
27 
28 #include <QHash>
29 #include <QByteArray>
30 #include "ZblTableCell.h"
31 #include <QMap>
32 
33 //#include <QList>
34 //#include <QString>
35 
36 
37 namespace Zbl
38 {
39 
40 class ZblTableHeaders;
41 
63 {
64 public:
65 
66  typedef QHash<int, QByteArray> zRoleNames;
67 
68  ZblDataModel();
69 
70  ~ZblDataModel();
71 
76  void setColumnCount(int count, ZblTableCell* cell = NULL);
77 
78 
79  int columnCount(const ZblTableCell* cell = NULL) const;
80 
81  int rowCount(const ZblTableCell* cell = NULL) const;
82 
83  QVariant data(int role, int row, int col,
84  const ZblTableCell* cell = NULL) const;
85 
86  void setData(int role, int row, int col, const QVariant& value,
87  ZblTableCell *cell = NULL);
88 
89  QVariant getTableColumnRows(
90  QList<int> roles,
91  int startRow,
92  int col,
93  int rowCount,
94  ZblTableCell *cell = NULL) const;
95 
96  void putTableColumnRows(
97  QVariant rows,
98  int startRow,
99  int col,
100  ZblTableCell *cell = NULL);
101 
102  void appendRow(QMap<int, QList<QVariant> > data,
103  ZblTableCell *cell = NULL);
104 
105  void appendRows(QList<QMap<int, QList<QVariant> > > data,
106  ZblTableCell* cell = NULL);
107 
108  void prependRow(QMap<int, QList<QVariant> > data,
109  ZblTableCell *cell = NULL);
110 
111  void prependRows(QList<QMap<int, QList<QVariant> > > data,
112  ZblTableCell* cell = NULL);
113 
121  void removeRows(int row, int count, ZblTableCell *cell = NULL);
122 
123 
124 
136  bool addRole(int roleNumber, ZblTableCell* cell = NULL);
137 
150  bool addRole(int roleNumber, const QByteArray& roleName, ZblTableCell* cell = NULL);
151 
158  bool hasRole(int role, const ZblTableCell* cell = NULL) const;
159 
166  QList<int> roles(const ZblTableCell* cell = NULL) const;
167 
175  zRoleNames roleNames() const;
176 
185  int roleCount(const ZblTableCell* cell = NULL) const;
186 
193  void clearData(ZblTableCell* cell = NULL);
194 
206  void clearRoles();
207 
208  //void setRoleNames(const QHash<int, QByteArray> roleNames);
209 
215  void dumpModelData(const ZblTableCell* cell = NULL) const;
216 
221  int findNextItemRow(
222  int startRow,
223  const QString& text,
224  int column = 0,
225  bool caseSensitive = true,
226  bool forwardDirection = true,
227  bool keySearch = false,
228  const ZblTableCell* cell = NULL) const;
229 
230 
240  bool copyColumn(int fromColumn, int toColumn, ZblTableCell *cell = NULL);
241 
242 
243 protected:
244 
246 
248 
249 
251 
252  const ZblTableCell& constRootCell() const;
253 
254 private:
255 
261 
262 
269 
274  zRoleNames* m_roleNames;
275 
282 
283 
284 };
285 
286 } // Zbl
287 
288 #endif // ZBLDATAMODEL_H
ZblTableCell * m_columnNames
The cell containing column names if column names have been set. TBD: do we need column names...
Definition: ZblDataModel.h:268
void dumpModelData(const ZblTableCell *cell=NULL) const
Prints diagnostic information about the state of the contained data to debug output.
bool copyColumn(int fromColumn, int toColumn, ZblTableCell *cell=NULL)
Copies data between data model columns for all rows and roles in the model.
int findNextItemRow(int startRow, const QString &text, int column=0, bool caseSensitive=true, bool forwardDirection=true, bool keySearch=false, const ZblTableCell *cell=NULL) const
Searches for the specified text from startIndex.
bool hasRole(int role, const ZblTableCell *cell=NULL) const
Determines if a specified role already exists in the data table.
void setColumnCount(int count, ZblTableCell *cell=NULL)
Sets the number of columns in the data table. This method fails if the data table contains rows...
void prependRows(QList< QMap< int, QList< QVariant > > > data, ZblTableCell *cell=NULL)
ZblTableHeaders & headers()
zRoleNames * m_roleNames
A hash of role value/name pairs.
Definition: ZblDataModel.h:274
void clearData(ZblTableCell *cell=NULL)
Removes all data rows from the specified table cell.
QHash< int, QByteArray > zRoleNames
Definition: ZblDataModel.h:66
ZblTableCell & colNamesCell()
void setData(int role, int row, int col, const QVariant &value, ZblTableCell *cell=NULL)
int rowCount(const ZblTableCell *cell=NULL) const
void prependRow(QMap< int, QList< QVariant > > data, ZblTableCell *cell=NULL)
const ZblTableCell & constRootCell() const
Definition: ZAndGate.cpp:6
ZblTableHeaders * m_headers
This object contains row and column header values for the model.
Definition: ZblDataModel.h:260
A table cell object contains the data for its child cells and maintains the cell&#39;s positional relatio...
Definition: ZblTableCell.h:47
void putTableColumnRows(QVariant rows, int startRow, int col, ZblTableCell *cell=NULL)
void clearRoles()
Removes all information from the model and returns the model to it&#39;s uninitialized state...
ZblTableCell * m_rootCell
The model&#39;s root cell contains the top level items. The root cell has no parent.
Definition: ZblDataModel.h:281
ZblTableCell & rootCell()
void appendRows(QList< QMap< int, QList< QVariant > > > data, ZblTableCell *cell=NULL)
int roleCount(const ZblTableCell *cell=NULL) const
Obtains the number of roles contained by the specified cell.
bool addRole(int roleNumber, ZblTableCell *cell=NULL)
Adds the specified role to the data table.
QList< int > roles(const ZblTableCell *cell=NULL) const
Determines which roles are in the data set.
This class is an implementation of an N+1 dimensional data store suitable for use as a generic QAbstr...
Definition: ZblDataModel.h:62
void appendRow(QMap< int, QList< QVariant > > data, ZblTableCell *cell=NULL)
zRoleNames roleNames() const
Obtains a hash that maps role numbers to role names.
void removeRows(int row, int count, ZblTableCell *cell=NULL)
Removes the specified data rows from the model.
int columnCount(const ZblTableCell *cell=NULL) const
QVariant getTableColumnRows(QList< int > roles, int startRow, int col, int rowCount, ZblTableCell *cell=NULL) const
Contains the data for data model column and row headers.
QVariant data(int role, int row, int col, const ZblTableCell *cell=NULL) const