QGIS API Documentation  2.11.0-Master
qgscomposerattributetablemodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerattributetablemodel.h
3  --------------------
4  begin : April 2014
5  copyright : (C) 2014 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOMPOSERATTRIBUTETABLEMODEL_H
19 #define QGSCOMPOSERATTRIBUTETABLEMODEL_H
20 
21 #include <QAbstractTableModel>
22 #include <QSortFilterProxyModel>
23 
26 
27 //QgsComposerAttributeTableColumnModel
28 
31 {
32  Q_OBJECT
33 
34  public:
35 
39  {
41  ShiftDown
42  };
43 
50 
51  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
52  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
53  virtual QVariant data( const QModelIndex &index, int role ) const override;
54  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
55  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
56  Qt::ItemFlags flags( const QModelIndex &index ) const override;
57  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
58  bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
59  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
60  QModelIndex parent( const QModelIndex &child ) const override;
61 
69  bool moveRow( int row, ShiftDirection direction );
70 
75  void resetToLayer();
76 
83  QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
84 
91  QModelIndex indexFromColumn( QgsComposerTableColumn *column );
92 
101  void setColumnAsSorted( QgsComposerTableColumn *column, Qt::SortOrder order );
102 
109  void setColumnAsUnsorted( QgsComposerTableColumn * column );
110 
117  bool moveColumnInSortRank( QgsComposerTableColumn * column, ShiftDirection direction );
118 
119  private:
120  QgsComposerAttributeTable * mComposerTable;
121 
122 };
123 
124 
125 //QgsComposerTableSortColumnsProxyModel
126 
129 {
130  Q_OBJECT
131 
132  public:
133 
137  {
139  ShowUnsortedColumns
140  };
141 
147  QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent = 0 );
148 
150 
151  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
152  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
153  virtual QVariant data( const QModelIndex &index, int role ) const override;
154  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
155  Qt::ItemFlags flags( const QModelIndex &index ) const override;
156  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
157 
164  QgsComposerTableColumn* columnFromRow( int row );
165 
173  QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
174 
175 
184  QgsComposerTableColumn* columnFromSourceIndex( const QModelIndex& sourceIndex ) const;
185 
189  void resetFilter();
190 
191  protected:
192  bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const override;
193 
194  private:
195  QgsComposerAttributeTable * mComposerTable;
196  ColumnFilterType mFilterType;
197 
202  QList<QgsComposerTableColumn*> columnsWithoutSortRank() const;
203 
204 };
205 #endif // QGSCOMPOSERATTRIBUTETABLEMODEL_H
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
static unsigned index
virtual int rowCount(const QModelIndex &parent) const =0
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual bool insertRows(int row, int count, const QModelIndex &parent)
ShiftDirection
Controls whether a row/column is shifted up or down.
A model for displaying columns shown in a QgsComposerAttributeTable.
virtual int columnCount(const QModelIndex &parent) const
virtual QVariant data(const QModelIndex &index, int role) const =0
Stores properties of a column in a QgsComposerTable.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual bool removeRows(int row, int count, const QModelIndex &parent)
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
A table class that displays a vector attribute table.
ColumnFilterType
Controls whether the proxy model shows sorted or unsorted columns.
virtual int columnCount(const QModelIndex &parent) const =0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted...
QObject * parent() const
virtual QVariant data(const QModelIndex &index, int role) const
typedef ItemFlags