src/app/qgsattributetable.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsattributetable.h  -  description
00003                              -------------------
00004     begin                : Sat Nov 23 2002
00005     copyright            : (C) 2002 by Gary E.Sherman
00006     email                : sherman at mrcc dot com
00007         Romans 3:23=>Romans 6:23=>Romans 5:8=>Romans 10:9,10=>Romans 12
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 /* $Id: qgsattributetable.h 9138 2008-08-23 21:37:31Z jef $ */
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     /* Inserts the feature with the specified id into rowIdMap. This function has to be called
00068        (e.g. from QgsShapeFileLayer) when a row is inserted into the table */
00069     void insertFeatureId( int id, int row );
00071     void selectRowWithId( int id );
00073     void sortColumn( int col, bool ascending );
00074     /* Use this to give this class the current attribute actions,
00075        which are used when the user requests a popup menu */
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     // Called when the user chooses an item on the popup menu
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     /* Compares the content of two cells either alphanumeric or numeric.
00129        If 'ascending' is true, -1 means s1 is less, 0 equal, 1 greater.
00130        If 'ascending' is false, -1 means s1 is more, 0 equal, 1 greater.
00131        This method is used mainly to sort a column*/
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     // Data to do with providing a popup menu of actions that
00162     std::vector<std::pair<QString, QString> > mActionValues;
00163     int mClickedOnValue;
00164     QMenu* mActionPopup;
00165     QgsAttributeAction mActions;
00166 
00167     QgsAttributeTableItemDelegate *mDelegate;
00168 
00169     // Track previous columm for QTableView sortIndicator wrong direction workaround
00170     int mPreviousSortIndicatorColumn;
00171 
00172     QgsVectorLayer *mLayer;
00173 };
00174 
00175 #endif

Generated on Tue Oct 28 16:51:26 2008 for Quantum GIS API Documentation by  doxygen 1.5.1