QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
33 {
34  Q_OBJECT
35 
36  public:
37 
41  {
43  ShiftDown
44  };
45 
50  QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent = nullptr );
52 
53  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
54  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
55  virtual QVariant data( const QModelIndex &index, int role ) const override;
56  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
57  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
58  Qt::ItemFlags flags( const QModelIndex &index ) const override;
59  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
60  bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
61  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
62  QModelIndex parent( const QModelIndex &child ) const override;
63 
71  bool moveRow( int row, ShiftDirection direction );
72 
77  void resetToLayer();
78 
85  QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
86 
93  QModelIndex indexFromColumn( QgsComposerTableColumn *column );
94 
103  void setColumnAsSorted( QgsComposerTableColumn *column, Qt::SortOrder order );
104 
111  void setColumnAsUnsorted( QgsComposerTableColumn * column );
112 
119  bool moveColumnInSortRank( QgsComposerTableColumn * column, ShiftDirection direction );
120 
121  private:
122  QgsComposerAttributeTable * mComposerTable;
123 
124 };
125 
126 
127 //QgsComposerTableSortColumnsProxyModel
128 
133 {
134  Q_OBJECT
135 
136  public:
137 
141  {
143  ShowUnsortedColumns
144  };
145 
151  QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent = nullptr );
152 
154 
155  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
156  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
157  virtual QVariant data( const QModelIndex &index, int role ) const override;
158  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
159  Qt::ItemFlags flags( const QModelIndex &index ) const override;
160  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
161 
168  QgsComposerTableColumn* columnFromRow( int row );
169 
177  QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
178 
179 
188  QgsComposerTableColumn* columnFromSourceIndex( const QModelIndex& sourceIndex ) const;
189 
193  void resetFilter();
194 
195  protected:
196  bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const override;
197 
198  private:
199  QgsComposerAttributeTable * mComposerTable;
200  ColumnFilterType mFilterType;
201 
206  QList<QgsComposerTableColumn*> columnsWithoutSortRank() const;
207 
208 };
209 #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