Back to index

fet  5.18.0
Public Member Functions | Public Attributes | Private Attributes
SparseItemModel Class Reference

#include <sparseitemmodel.h>

List of all members.

Public Member Functions

 SparseItemModel ()
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
QModelIndex parent (const QModelIndex &index) const
int rowCount (const QModelIndex &parent=QModelIndex()) const
int columnCount (const QModelIndex &parent=QModelIndex()) const
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void clear ()
void clearDataAndHeaders ()
void resize (int _nr, int _nc)
void allItemsChanged ()
void allHeadersChanged ()

Public Attributes

QHash< QPair< int, int >, QString > items
QStringList horizontalHeaderItems
QStringList verticalHeaderItems

Private Attributes

int n_rows
int n_columns

Detailed Description

Definition at line 30 of file sparseitemmodel.h.


Constructor & Destructor Documentation

Definition at line 25 of file sparseitemmodel.cpp.

{
       n_rows=0;
       n_columns=0;

       items.clear();
       horizontalHeaderItems.clear();
       verticalHeaderItems.clear();
}

Member Function Documentation

Definition at line 163 of file sparseitemmodel.cpp.

{
       emit headerDataChanged(Qt::Horizontal, 0, n_columns-1);
       emit headerDataChanged(Qt::Vertical, 0, n_rows-1);
}

Here is the caller graph for this function:

Definition at line 158 of file sparseitemmodel.cpp.

{
       emit dataChanged(index(0,0), index(n_rows-1, n_columns-1));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 99 of file sparseitemmodel.cpp.

{
       assert(n_rows>=0);
       if(n_rows>0){
              beginRemoveRows(QModelIndex(), 0, n_rows-1);
              n_rows=0;
              endRemoveRows();
       }
       
       assert(n_columns>=0);
       if(n_columns>0){
              beginRemoveColumns(QModelIndex(), 0, n_columns-1);
              n_columns=0;
              endRemoveColumns();
       }

       items.clear();
       horizontalHeaderItems.clear();
       verticalHeaderItems.clear();
}

Here is the caller graph for this function:

Definition at line 120 of file sparseitemmodel.cpp.

{
       items.clear();
       
       assert(n_columns==horizontalHeaderItems.count());
       for(int i=0; i<n_columns; i++)
              horizontalHeaderItems[i]="";
              
       assert(n_rows==verticalHeaderItems.count());
       for(int i=0; i<n_rows; i++)
              verticalHeaderItems[i]="";
}

Here is the caller graph for this function:

int SparseItemModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 57 of file sparseitemmodel.cpp.

{
       if(parent!=QModelIndex())
              return 0; //qt doc says that

       return n_columns;
}

Here is the caller graph for this function:

QVariant SparseItemModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

Definition at line 65 of file sparseitemmodel.cpp.

{
       if(role!=Qt::DisplayRole)
              return QVariant();

       int row=index.row();
       assert(row>=0 && row<n_rows);
       int column=index.column();
       assert(column>=0 && column<n_columns);
       
       QPair<int, int> pair;
       pair.first=row;
       pair.second=column;
       if(items.contains(pair))
              return items.value(pair);
       else
              return QVariant();
}
QVariant SparseItemModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const

Definition at line 84 of file sparseitemmodel.cpp.

{
       if(role!=Qt::DisplayRole)
              return QVariant();

       if(orientation==Qt::Horizontal){
              assert(section>=0 && section<horizontalHeaderItems.count());
              return horizontalHeaderItems.at(section);
       }
       else{
              assert(section>=0 && section<verticalHeaderItems.count());
              return verticalHeaderItems.at(section);
       }
}
QModelIndex SparseItemModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const

Definition at line 35 of file sparseitemmodel.cpp.

{
       Q_UNUSED(parent);

       return createIndex(row, column);
}

Here is the caller graph for this function:

QModelIndex SparseItemModel::parent ( const QModelIndex &  index) const

Definition at line 42 of file sparseitemmodel.cpp.

{
       Q_UNUSED(index);

       return QModelIndex();
}
void SparseItemModel::resize ( int  _nr,
int  _nc 
)

Definition at line 133 of file sparseitemmodel.cpp.

{
       if(_nr==n_rows && _nc==n_columns)
              return;

       this->clear();
       
       assert(verticalHeaderItems.count()==0);
       for(int i=0; i<_nr; i++)
              verticalHeaderItems.append("");
       assert(horizontalHeaderItems.count()==0);
       for(int i=0; i<_nc; i++)
              horizontalHeaderItems.append("");
       
       assert(n_rows==0);
       beginInsertRows(QModelIndex(), 0, _nr-1);
       n_rows=_nr;
       endInsertRows();

       assert(n_columns==0);
       beginInsertColumns(QModelIndex(), 0, _nc-1);
       n_columns=_nc;
       endInsertColumns();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int SparseItemModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 49 of file sparseitemmodel.cpp.

{
       if(parent!=QModelIndex())
              return 0; //qt doc says that

       return n_rows;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 37 of file sparseitemmodel.h.

QHash<QPair<int, int> , QString> SparseItemModel::items

Definition at line 36 of file sparseitemmodel.h.

Definition at line 32 of file sparseitemmodel.h.

int SparseItemModel::n_rows [private]

Definition at line 31 of file sparseitemmodel.h.

Definition at line 38 of file sparseitemmodel.h.


The documentation for this class was generated from the following files: