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 
00242     inline bool emitSignals(void) const { return myEmitSignalsFlag; }
00243 
00251     inline void setEmitSignals(bool b)  { myEmitSignalsFlag = b; }
00252 
00271     void readASCII(QTextStream &stream, const char separator = ';',
00272            int start_row = 0, int start_col = 0,
00273            bool clear_model = false);
00274 
00286     void writeASCII(QTextStream &stream, const char separator = ';',
00287             int start_row = 0, int start_col = 0,
00288             int nrows = -1, int ncols = -1);
00289 
00297     typedef QicsDataModel *(*Foundry)(int num_rows, int num_cols);
00298 
00309     typedef QicsDataModel *(*FoundryWithKey)(int num_rows, int num_cols,
00310                          void *key);
00311 
00312 public slots:
00322     virtual void setItem(int row, int col, const QicsDataItem &item) = 0;
00323 
00332     virtual void setItem(int row, int col, int val)
00333     { setItem(row, col, QicsDataInt(val)); }
00334 
00343     virtual void setItem(int row, int col, long val)
00344     { setItem(row, col, QicsDataLong(val)); }
00345 
00354     virtual void setItem(int row, int col, qlonglong val)
00355     { setItem(row, col, QicsDataLongLong(val)); }
00364     virtual void setItem(int row, int col, float val)
00365     { setItem(row, col, QicsDataFloat(val)); }
00366 
00375     virtual void setItem(int row, int col, double val)
00376     { setItem(row, col, QicsDataDouble(val)); }
00377 
00386     virtual void setItem(int row, int col, const QString &val)
00387     { setItem(row, col, QicsDataString(val)); }
00388 
00397     virtual void setItem(int row, int col, const char* val)
00398     { setItem(row, col, QicsDataString(val)); }
00399 
00408     virtual void setItem(int row, int col, const QDate &val)
00409     { setItem(row, col, QicsDataDate(val)); }
00410 
00419     virtual void setItem(int row, int col, const QTime &val)
00420     { setItem(row, col, QicsDataTime(val)); }
00421 
00430     virtual void setItem(int row, int col, const QDateTime &val)
00431     { setItem(row, col, QicsDataDateTime(val)); }
00432 
00441     virtual void setItem(int row, int col, const bool &val)
00442     { setItem(row, col, QicsDataBool(val)); }
00443 
00453     virtual void insertRows(int number_of_rows, int starting_position)=0;
00454 
00464     virtual void insertColumns(int number_of_columns,
00465                    int starting_position)=0;
00466 
00476     virtual void addRows(int rows) =0;
00477 
00487     virtual void addColumns(int num) = 0;
00488 
00498     virtual void deleteRow(int row)  = 0;
00499 
00508     virtual void deleteRows(int num_rows, int start_row)  = 0;
00509 
00519     virtual void deleteColumn(int col) = 0;
00520 
00530     virtual void deleteColumns(int num_cols, int start_col) = 0;
00531 
00539     virtual void clearItem(int row, int col)  = 0;
00540 
00547     virtual void clearModel(void) = 0;
00548 
00549 
00550  signals:
00551 
00559     void modelChanged(QicsRegion reg);
00560 
00564     void modelSizeChanged(int new_number_of_rows, int new_number_of_columns);
00565 
00569     void modelSizeChanged(int position, int num_items_added_removed, Qics::QicsIndexType row_or_col);
00570 
00574     void rowsInserted(int number_of_rows, int starting_position);
00578     void columnsInserted(int number_of_columns, int starting_position);
00579 
00583     void rowsDeleted(int number_of_rows, int starting_position);
00587     void columnsDeleted(int number_of_columns, int starting_position);
00588 
00592     void rowsAdded(int number_of_rows);
00596     void columnsAdded(int number_of_columns);
00600     void cellValueChanged( int row, int col );
00606     void prepareForRowChanges(int num_rows, int start_row);
00612     void prepareForColumnChanges(int num_cols, int start_col);
00613 
00614 protected:
00622     inline void setNumRows(int nrows) { myNumRows = nrows; }
00630     inline void setNumColumns(int ncols) { myNumColumns = ncols; }
00631 
00636     int myNumRows;
00637 
00642     int myNumColumns;
00643 
00648     bool myEmitSignalsFlag;
00649 
00650 private:
00655     QicsDataModel(const QicsDataModel&):QObject()
00656     {/*DON'T DO THIS */}
00661     QicsDataModel& operator= (const QicsDataModel& )
00662     {/*DON'T DO THIS */return *this;}
00663 };
00664 
00665 #endif /*_QicsDataModel_H --- Do not add anything past this line */
00666 

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