ICS

QicsTable Documentation Set

QicsDataModel.h

Go to the documentation of this file.
00001 /*********************************************************************
00002 **
00003 ** Copyright (C) 2002-2006 Integrated Computer Solutions, Inc
00004 ** All rights reserved.
00005 **
00006 ** This file is part of the QicsTable Product.
00007 **
00008 **********************************************************************/
00009 
00010 #ifndef _QicsDataModel_H
00011 #define _QicsDataModel_H
00012 
00013 #include <QVector>
00014 #include <QString>
00015 #include <QObject>
00016 
00017 #include <QicsNamespace.h>
00018 #include <QicsDataItem.h>
00019 #include <QicsRegion.h>
00020 #include <QTextStream>
00021 
00022 
00034 typedef QVector<const QicsDataItem *>         QicsDataModelColumn;
00035 
00045 typedef QVector<const QicsDataItem *>         QicsDataModelRow;
00046 
00047 
00086 
00087 
00090 
00091                   
00092 class QICS_EXPORT QicsDataModel: public QObject, public Qics {
00093     Q_OBJECT
00094 public:
00100     QicsDataModel(int num_rows = 0 , int num_cols = 0,
00101           QObject *parent = 0);
00102 
00106     virtual ~QicsDataModel(void);
00107 
00111     inline int numRows(void) const { return myNumRows; }
00112 
00116     inline int numColumns(void) const { return myNumColumns; }
00117 
00122     inline int lastRow(void) const { return (myNumRows - 1); }
00123 
00128     inline int lastColumn(void) const { return (myNumColumns - 1); }
00129 
00135     inline bool contains(int row, int col) const
00136     { return ((col > lastColumn() ||
00137            row > lastRow() ||
00138            row < 0 ||
00139            col < 0)? false: true );}
00140 
00161     virtual const QicsDataItem *item(int row, int col) const = 0;
00162 
00169     virtual QString itemString(int row, int col) const;
00170 
00177     const QicsDataItem *operator()(int row, int col) { return item(row, col); }
00178 
00184     virtual QicsDataModelRow rowItems(int row,
00185                       int first_col = 0,
00186                       int last_col = -1) const = 0;
00187 
00193     virtual QicsDataModelColumn columnItems(int col,
00194                         int first_row = 0,
00195                         int last_row = -1) const = 0;
00196 
00214     virtual void setRowItems(int row, const QicsDataModelRow &v) = 0;
00215 
00233     virtual void setColumnItems(int col, const QicsDataModelColumn &v) = 0;
00234 
00235 
00243     inline bool emitSignals(void) const { return myEmitSignalsFlag; }
00244 
00252     inline void setEmitSignals(bool b)  { myEmitSignalsFlag = b; }
00253 
00260     inline void notifyRegionChanged(QicsRegion reg) { emit modelChanged(reg); }
00261 
00267     virtual bool isRowEmpty(int /*row*/) const { return false; }
00268 
00274     virtual bool isColumnEmpty(int /*column*/) const { return false; }
00275 
00294     void readASCII(QTextStream &stream, const char separator = ';',
00295            int start_row = 0, int start_col = 0,
00296            bool clear_model = false);
00297 
00309     void writeASCII(QTextStream &stream, const char separator = ';',
00310             int start_row = 0, int start_col = 0,
00311             int nrows = -1, int ncols = -1);
00312 
00320     typedef QicsDataModel *(*Foundry)(int num_rows, int num_cols);
00321 
00332     typedef QicsDataModel *(*FoundryWithKey)(int num_rows, int num_cols,
00333                          void *key);
00334 
00335 public slots:
00345     virtual void setItem(int row, int col, const QicsDataItem &item) = 0;
00346 
00355     virtual void setItem(int row, int col, int val)
00356     { setItem(row, col, QicsDataInt(val)); }
00357 
00366     virtual void setItem(int row, int col, long val)
00367     { setItem(row, col, QicsDataLong(val)); }
00368 
00377     virtual void setItem(int row, int col, qlonglong val)
00378     { setItem(row, col, QicsDataLongLong(val)); }
00387     virtual void setItem(int row, int col, float val)
00388     { setItem(row, col, QicsDataFloat(val)); }
00389 
00398     virtual void setItem(int row, int col, double val)
00399     { setItem(row, col, QicsDataDouble(val)); }
00400 
00409     virtual void setItem(int row, int col, const QString &val)
00410     { setItem(row, col, QicsDataString(val)); }
00411 
00420     virtual void setItem(int row, int col, const char* val)
00421     { setItem(row, col, QicsDataString(val)); }
00422 
00431     virtual void setItem(int row, int col, const QDate &val)
00432     { setItem(row, col, QicsDataDate(val)); }
00433 
00442     virtual void setItem(int row, int col, const QTime &val)
00443     { setItem(row, col, QicsDataTime(val)); }
00444 
00453     virtual void setItem(int row, int col, const QDateTime &val)
00454     { setItem(row, col, QicsDataDateTime(val)); }
00455 
00464     virtual void setItem(int row, int col, const bool &val)
00465     { setItem(row, col, QicsDataBool(val)); }
00466 
00476     virtual void insertRows(int number_of_rows, int starting_position)=0;
00477 
00487     virtual void insertColumns(int number_of_columns,
00488                    int starting_position)=0;
00489 
00499     virtual void addRows(int rows) =0;
00500 
00510     virtual void addColumns(int num) = 0;
00511 
00521     virtual void deleteRow(int row)  = 0;
00522 
00531     virtual void deleteRows(int num_rows, int start_row)  = 0;
00532 
00542     virtual void deleteColumn(int col) = 0;
00543 
00553     virtual void deleteColumns(int num_cols, int start_col) = 0;
00554 
00562     virtual void clearItem(int row, int col)  = 0;
00563 
00570     virtual void clearModel(void) = 0;
00571 
00572 
00573  signals:
00574 
00582     void modelChanged(QicsRegion reg);
00583 
00587     void modelSizeChanged(int new_number_of_rows, int new_number_of_columns);
00588 
00592     void modelSizeChanged(int position, int num_items_added_removed, Qics::QicsIndexType row_or_col);
00593 
00597     void rowsInserted(int number_of_rows, int starting_position);
00601     void columnsInserted(int number_of_columns, int starting_position);
00602 
00606     void rowsDeleted(int number_of_rows, int starting_position);
00610     void columnsDeleted(int number_of_columns, int starting_position);
00611 
00615     void rowsAdded(int number_of_rows);
00619     void columnsAdded(int number_of_columns);
00623     void cellValueChanged( int row, int col );
00629     void prepareForRowChanges(int num_rows, int start_row);
00635     void prepareForColumnChanges(int num_cols, int start_col);
00636 
00637 protected:
00645     inline void setNumRows(int nrows) { myNumRows = nrows; }
00653     inline void setNumColumns(int ncols) { myNumColumns = ncols; }
00654 
00659     int myNumRows;
00660 
00665     int myNumColumns;
00666 
00671     bool myEmitSignalsFlag;
00672 
00673 private:
00678     QicsDataModel(const QicsDataModel&):QObject()
00679     {/*DON'T DO THIS */}
00684     QicsDataModel& operator= (const QicsDataModel& )
00685     {/*DON'T DO THIS */return *this;}
00686 };
00687 
00688 #endif /*_QicsDataModel_H --- Do not add anything past this line */
00689 

All trademarks and copyrights on this page are properties of their respective owners.
The rest is copyright 1999-2006 Integrated Computer Solutions, Inc.