00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QGSATTRIBUTETABLE_H
00020 #define QGSATTRIBUTETABLE_H
00021
00022 #include "qgsattributeaction.h"
00023 #include "qgsvectorlayer.h"
00024 #include "qgsfield.h"
00025
00026 #include <QItemDelegate>
00027 #include <QTableWidget>
00028
00029 #include <set>
00030
00035 class QgsAttributeTable;
00036
00037 class QgsAttributeTableItemDelegate: public QItemDelegate
00038 {
00039 Q_OBJECT
00040
00041 public:
00042 QgsAttributeTableItemDelegate( QgsAttributeTable *table, QObject * parent = 0 );
00043 QWidget * createEditor( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
00044
00045 private:
00046 QgsAttributeTable *mTable;
00047 };
00048
00049 class QgsAttributeTable : public QTableWidget
00050 {
00051 Q_OBJECT
00052
00053 public:
00054 QgsAttributeTable( QWidget * parent = 0 );
00055 ~QgsAttributeTable();
00056
00057 enum
00058 {
00059 AttributeIndex = Qt::UserRole,
00060 AttributeName = Qt::UserRole + 1,
00061 AttributeType = Qt::UserRole + 2
00062 };
00063
00064 void setReadOnly( bool b );
00065 void setColumnReadOnly( int col, bool ro );
00066
00067
00068
00069 void insertFeatureId( int id, int row );
00071 void selectRowWithId( int id );
00073 void sortColumn( int col, bool ascending );
00074
00075
00076 void setAttributeActions( const QgsAttributeAction& actions )
00077 { mActions = actions; }
00079 bool edited() const {return mEdited;}
00081 void setEditable( bool enabled ) {mEditable = enabled;}
00082
00085 void copySelectedRows();
00086
00088 void bringSelectedToTop();
00090 void selectRowsWithId( const QgsFeatureIds& ids );
00092 void showRowsWithId( const QgsFeatureIds& ids );
00094 void showAllRows();
00095
00097 void fillTable( QgsVectorLayer *layer );
00098 void addAttribute( int idx, const QgsField &fld );
00099 void deleteAttribute( int idx );
00100
00101 public slots:
00102 void columnClicked( int col );
00103 void rowClicked( int row );
00104
00105
00106 void popupItemSelected( QAction * menuAction );
00107
00108 void attributeValueChanged( int fid, int idx, const QVariant &value );
00109 void featureDeleted( int fid );
00110
00111 protected slots:
00112 void handleChangedSelections();
00113
00114 protected:
00116 bool lockKeyPressed;
00118 QMap<int, int> rowIdMap;
00120 QMap<int, int> mAttrIdxMap;
00121 bool mEditable;
00123 bool mEdited;
00124
00126 std::set<int> mLastSelectedRows;
00127
00128
00129
00130
00131
00132 int compareItems( QString s1, QString s2, bool ascending, bool alphanumeric );
00133 void keyPressEvent( QKeyEvent* ev );
00134 void keyReleaseEvent( QKeyEvent* ev );
00136 void qsort( int lower, int upper, int col, bool ascending, bool alphanumeric );
00138 void contextMenuEvent( QContextMenuEvent* event );
00141 void removeAttrColumn( const QString& name );
00143 void putFeatureInTable( int row, const QgsFeature& fet );
00144 void mouseReleaseEvent( QMouseEvent* e );
00148 bool checkSelectionChanges();
00149
00150 signals:
00152 void selected( int, bool );
00154 void selectionRemoved( bool );
00156 void repaintRequested();
00157
00158 private:
00159 void swapRows( int row1, int row2 );
00160
00161
00162 std::vector<std::pair<QString, QString> > mActionValues;
00163 int mClickedOnValue;
00164 QMenu* mActionPopup;
00165 QgsAttributeAction mActions;
00166
00167 QgsAttributeTableItemDelegate *mDelegate;
00168
00169
00170 int mPreviousSortIndicatorColumn;
00171
00172 QgsVectorLayer *mLayer;
00173 };
00174
00175 #endif