|
1 | 1 | /*************************************************************************** |
2 | | - BeataModel.h |
| 2 | + BeataModel.h |
3 | 3 | BEtter Attribute TAble |
4 | 4 | ------------------- |
5 | 5 | date : Feb 2009 |
|
30 | 30 |
|
31 | 31 | class idColumnPair |
32 | 32 | { |
33 | | -public: |
34 | | - int id; |
35 | | - QVariant columnItem; |
| 33 | + public: |
| 34 | + int id; |
| 35 | + QVariant columnItem; |
36 | 36 |
|
37 | | - bool operator<(const idColumnPair &b) const; |
| 37 | + bool operator<( const idColumnPair &b ) const; |
38 | 38 | }; |
39 | 39 |
|
40 | 40 | class BeataFilterModel: public QSortFilterProxyModel |
41 | 41 | { |
42 | | -public: |
43 | | - BeataFilterModel(QgsVectorLayer* theLayer); |
44 | | - //QModelIndex mapToSource ( const QModelIndex & filterIndex ) const; |
45 | | - //QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const; |
46 | | - bool mHideUnselected; |
47 | | - virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); |
48 | | -protected: |
49 | | - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; |
50 | | -private: |
51 | | - QgsVectorLayer* mLayer; |
| 42 | + public: |
| 43 | + BeataFilterModel( QgsVectorLayer* theLayer ); |
| 44 | + //QModelIndex mapToSource ( const QModelIndex & filterIndex ) const; |
| 45 | + //QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const; |
| 46 | + bool mHideUnselected; |
| 47 | + virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ); |
| 48 | + protected: |
| 49 | + bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const; |
| 50 | + private: |
| 51 | + QgsVectorLayer* mLayer; |
52 | 52 | }; |
53 | 53 |
|
54 | 54 |
|
55 | 55 | class BeataModel: public QAbstractTableModel |
56 | 56 | { |
57 | | -Q_OBJECT |
58 | | - |
59 | | -public: |
60 | | - BeataModel(QgsVectorLayer *theLayer, QObject *parent = 0); |
61 | | - |
62 | | - int rowCount(const QModelIndex &parent = QModelIndex()) const; |
63 | | - int columnCount(const QModelIndex &parent = QModelIndex()) const; |
64 | | - |
65 | | - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
66 | | - virtual QVariant data(const QModelIndex &index, int role) const; |
67 | | - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); |
68 | | - Qt::ItemFlags flags(const QModelIndex &index) const; |
69 | | - |
70 | | - void reload(const QModelIndex &index1, const QModelIndex &index2); |
71 | | - void resetModel(); |
72 | | - void changeLayout(); |
73 | | - void incomingChangeLayout(); |
74 | | - int idToRow(const int id) const; |
75 | | - int rowToId(const int id) const; |
76 | | - virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); |
77 | | - void swapRows(int a, int b); |
78 | | - |
79 | | - QgsVectorLayer* layer() const { return mLayer; } |
80 | | - |
81 | | -signals: |
82 | | - void modelChanged(); |
83 | | - void setNumRows(int oldNum, int newNum); |
84 | | - |
85 | | -private slots: |
86 | | - virtual void attributeAdded (int idx); |
87 | | - virtual void attributeDeleted (int idx); |
88 | | - virtual void attributeValueChanged (int fid, int idx, const QVariant &value); |
89 | | - virtual void layerModified(bool onlyGeometry); |
90 | | - |
91 | | -protected slots: |
92 | | - virtual void featureDeleted(int fid); |
93 | | - virtual void featureAdded(int fid); |
94 | | - virtual void layerDeleted (); |
95 | | - |
96 | | -protected: |
97 | | - QgsVectorLayer *mLayer; |
98 | | - int mFeatureCount; |
99 | | - int mFieldCount; |
100 | | - mutable int mLastRowId; |
101 | | - mutable QgsFeature mFeat; |
102 | | - |
103 | | - mutable QgsAttributeMap *mLastRow; |
104 | | - QgsAttributeList mAttributes; |
105 | | - |
106 | | - QList<idColumnPair> mSortList; |
107 | | - QMap<int, int> mIdRowMap; |
108 | | - QMap<int, int> mRowIdMap; |
109 | | - |
110 | | - void initIdMaps(); |
111 | | - virtual void loadLayer(); |
| 57 | + Q_OBJECT |
| 58 | + |
| 59 | + public: |
| 60 | + BeataModel( QgsVectorLayer *theLayer, QObject *parent = 0 ); |
| 61 | + |
| 62 | + int rowCount( const QModelIndex &parent = QModelIndex() ) const; |
| 63 | + int columnCount( const QModelIndex &parent = QModelIndex() ) const; |
| 64 | + |
| 65 | + QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
| 66 | + virtual QVariant data( const QModelIndex &index, int role ) const; |
| 67 | + virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); |
| 68 | + Qt::ItemFlags flags( const QModelIndex &index ) const; |
| 69 | + |
| 70 | + void reload( const QModelIndex &index1, const QModelIndex &index2 ); |
| 71 | + void resetModel(); |
| 72 | + void changeLayout(); |
| 73 | + void incomingChangeLayout(); |
| 74 | + int idToRow( const int id ) const; |
| 75 | + int rowToId( const int id ) const; |
| 76 | + virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ); |
| 77 | + void swapRows( int a, int b ); |
| 78 | + |
| 79 | + QgsVectorLayer* layer() const { return mLayer; } |
| 80 | + |
| 81 | + signals: |
| 82 | + void modelChanged(); |
| 83 | + void setNumRows( int oldNum, int newNum ); |
| 84 | + |
| 85 | + private slots: |
| 86 | + virtual void attributeAdded( int idx ); |
| 87 | + virtual void attributeDeleted( int idx ); |
| 88 | + virtual void attributeValueChanged( int fid, int idx, const QVariant &value ); |
| 89 | + virtual void layerModified( bool onlyGeometry ); |
| 90 | + |
| 91 | + protected slots: |
| 92 | + virtual void featureDeleted( int fid ); |
| 93 | + virtual void featureAdded( int fid ); |
| 94 | + virtual void layerDeleted(); |
| 95 | + |
| 96 | + protected: |
| 97 | + QgsVectorLayer *mLayer; |
| 98 | + int mFeatureCount; |
| 99 | + int mFieldCount; |
| 100 | + mutable int mLastRowId; |
| 101 | + mutable QgsFeature mFeat; |
| 102 | + |
| 103 | + mutable QgsAttributeMap *mLastRow; |
| 104 | + QgsAttributeList mAttributes; |
| 105 | + |
| 106 | + QList<idColumnPair> mSortList; |
| 107 | + QMap<int, int> mIdRowMap; |
| 108 | + QMap<int, int> mRowIdMap; |
| 109 | + |
| 110 | + void initIdMaps(); |
| 111 | + virtual void loadLayer(); |
112 | 112 |
|
113 | 113 | }; |
114 | 114 |
|
115 | 115 | class BeataMemModel: public BeataModel |
116 | 116 | { |
117 | | -Q_OBJECT |
| 117 | + Q_OBJECT |
118 | 118 |
|
119 | | -public: |
120 | | - BeataMemModel(QgsVectorLayer *theLayer);//, QObject *parent = 0); |
| 119 | + public: |
| 120 | + BeataMemModel( QgsVectorLayer *theLayer );//, QObject *parent = 0); |
121 | 121 |
|
122 | | -protected slots: |
123 | | - virtual void featureDeleted(int fid); |
124 | | - virtual void featureAdded(int fid); |
125 | | - virtual void layerDeleted (); |
| 122 | + protected slots: |
| 123 | + virtual void featureDeleted( int fid ); |
| 124 | + virtual void featureAdded( int fid ); |
| 125 | + virtual void layerDeleted(); |
126 | 126 |
|
127 | | -private slots: |
128 | | - //virtual void attributeAdded (int idx); |
129 | | - //virtual void attributeDeleted (int idx); |
130 | | - virtual void attributeValueChanged (int fid, int idx, const QVariant &value); |
131 | | - //virtual void layerModified(bool onlyGeometry); |
| 127 | + private slots: |
| 128 | + //virtual void attributeAdded (int idx); |
| 129 | + //virtual void attributeDeleted (int idx); |
| 130 | + virtual void attributeValueChanged( int fid, int idx, const QVariant &value ); |
| 131 | + //virtual void layerModified(bool onlyGeometry); |
132 | 132 |
|
133 | | -private: |
134 | | - virtual QVariant data(const QModelIndex &index, int role) const; |
135 | | - virtual bool setData(const QModelIndex &index, const QVariant &value, int role); |
136 | | - virtual void loadLayer(); |
| 133 | + private: |
| 134 | + virtual QVariant data( const QModelIndex &index, int role ) const; |
| 135 | + virtual bool setData( const QModelIndex &index, const QVariant &value, int role ); |
| 136 | + virtual void loadLayer(); |
137 | 137 |
|
138 | | - QMap<int, QgsFeature> mFeatureMap; |
| 138 | + QMap<int, QgsFeature> mFeatureMap; |
139 | 139 | }; |
140 | 140 |
|
141 | 141 | #endif |
0 commit comments