18 #include <QHeaderView>
33 : QTableView( parent )
34 , mMasterModel( NULL )
35 , mFilterModel( NULL )
36 , mFeatureSelectionModel( NULL )
37 , mActionPopup( NULL )
40 restoreGeometry( settings.value(
"/BetterAttributeTable/geometry" ).toByteArray() );
42 verticalHeader()->setDefaultSectionSize( 20 );
43 horizontalHeader()->setHighlightSections(
false );
48 setSelectionBehavior( QAbstractItemView::SelectRows );
49 setSelectionMode( QAbstractItemView::ExtendedSelection );
50 setSortingEnabled(
true );
52 verticalHeader()->viewport()->installEventFilter(
this );
54 connect( verticalHeader(), SIGNAL( sectionPressed(
int ) ),
this, SLOT(
selectRow(
int ) ) );
55 connect( verticalHeader(), SIGNAL( sectionEntered(
int ) ),
this, SLOT(
_q_selectRow(
int ) ) );
91 if (
object == verticalHeader()->viewport() )
93 switch ( event->type() )
95 case QEvent::MouseButtonPress:
99 case QEvent::MouseButtonRelease:
115 disconnect(
mFilterModel, SIGNAL( filterAboutToBeInvalidated() ),
this, SLOT( onFilterAboutToBeInvalidated() ) );
116 disconnect(
mFilterModel, SIGNAL( filterInvalidated() ),
this, SLOT( onFilterInvalidated() ) );
120 QTableView::setModel( filterModel );
139 settings.setValue(
"/BetterAttributeTable/geometry", QVariant( saveGeometry() ) );
144 setSelectionMode( QAbstractItemView::NoSelection );
145 QTableView::mousePressEvent( event );
146 setSelectionMode( QAbstractItemView::ExtendedSelection );
151 setSelectionMode( QAbstractItemView::NoSelection );
152 QTableView::mouseReleaseEvent( event );
153 setSelectionMode( QAbstractItemView::ExtendedSelection );
158 setSelectionMode( QAbstractItemView::NoSelection );
159 QTableView::mouseMoveEvent( event );
160 setSelectionMode( QAbstractItemView::ExtendedSelection );
165 switch ( event->key() )
174 setSelectionMode( QAbstractItemView::NoSelection );
175 QTableView::keyPressEvent( event );
176 setSelectionMode( QAbstractItemView::ExtendedSelection );
180 QTableView::keyPressEvent( event );
187 foreach (
const QModelIndex index, indexes )
195 setDirtyRegion( viewport()->rect() );
200 QItemSelection selection;
213 QModelIndex idx = indexAt( event->pos() );
214 if ( !idx.isValid() )
248 if ( selectionBehavior() == QTableView::SelectColumns
249 || ( selectionMode() == QTableView::SingleSelection
250 && selectionBehavior() == QTableView::SelectItems ) )
253 if ( row >= 0 && row < model()->rowCount() )
255 int column = horizontalHeader()->logicalIndexAt( isRightToLeft() ? viewport()->width() : 0 );
256 QModelIndex index = model()->index( row, column );
257 QItemSelectionModel::SelectionFlags command = selectionCommand( index );
258 selectionModel()->setCurrentIndex( index, QItemSelectionModel::NoUpdate );
259 if (( anchor && !( command & QItemSelectionModel::Current ) )
260 || ( selectionMode() == QTableView::SingleSelection ) )
263 if ( selectionMode() != QTableView::SingleSelection
264 && command.testFlag( QItemSelectionModel::Toggle ) )
268 ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
269 command &= ~QItemSelectionModel::Toggle;
272 command |= QItemSelectionModel::Current;
276 QModelIndex br = model()->index( qMax(
mRowSectionAnchor, row ), model()->columnCount() - 1 );
277 if ( verticalHeader()->sectionsMoved() && tl.row() != br.row() )
278 setSelection( visualRect( tl ) | visualRect( br ), command );
QgsAttributeTableFilterModel * mFilterModel
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before basing any other models on this model...
QgsAttributeTableModel * mMasterModel
void setCanvasAndLayerCache(QgsMapCanvas *canvas, QgsVectorLayerCache *layerCache)
Autocreates the models.
QItemSelectionModel::SelectionFlag mCtrlDragSelectionFlag
void mouseMoveEvent(QMouseEvent *event)
Called for mouse move events on a table cell.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
virtual bool eventFilter(QObject *object, QEvent *event)
This event filter is installed on the verticalHeader to intercept mouse press and release events...
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
void enableSync(bool enable)
Enables or disables synchronisation to the QgsVectorLayer When synchronisation is disabled...
Map canvas is a class for displaying all GIS data types on a canvas.
void mousePressEvent(QMouseEvent *event)
Called for mouse press events on a table cell.
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
QgsVectorLayerCache * mLayerCache
QgsFeatureSelectionModel * mFeatureSelectionModel
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QgsAttributeTableView(QWidget *parent=0)
void keyPressEvent(QKeyEvent *event)
Called for key press events Disables selection change by only pressing an arrow key.
virtual void selectFeatures(const QItemSelection &selection, SelectionFlags command)
Select features on this table.
QgsAttributeTableDelegate * mTableDelegate
virtual void setModel(QgsAttributeTableFilterModel *filterModel)
void willShowContextMenu(QMenu *menu, QModelIndex atIndex)
Is emitted, in order to provide a hook to add aditional menu entries to the context menu...
This class caches features of a given QgsVectorLayer.
void closeEvent(QCloseEvent *event)
Saves geometry to the settings on close.
void mouseReleaseEvent(QMouseEvent *event)
Called for mouse release events on a table cell.
A delegate item class for QgsAttributeTable (see Qt documentation for QItemDelegate).
virtual void selectRow(int row)
virtual void _q_selectRow(int row)
virtual ~QgsAttributeTableView()
Represents a vector layer which manages a vector based data sets.
void contextMenuEvent(QContextMenuEvent *event)
Is called when the context menu will be shown.