Skip to content
Browse files
Changed the selection behaviour of the attribute table. The repaintRe…
…quest signal is now only emitted if the mouse button is released and if the selected rows have changed. This minimises repaint events and allows to selecting multiple rows with mouse drag without generating a seperate repaint event for each new row

git-svn-id: c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 18, 2006
1 parent 37afa70 commit 27ce9ef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
@@ -50,6 +50,7 @@ QgsAttributeTable::QgsAttributeTable(QWidget * parent, const char *name):
QObject::connect(this, SIGNAL(selectionChanged()), this, SLOT(handleChangedSelections()));
connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint&)), this, SLOT(popupMenu(int, int, const QPoint&)));
connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(storeChangedValue(int,int)));
connect(verticalHeader(), SIGNAL(released(int)), this, SLOT(rowClicked(int)));
@@ -128,7 +129,6 @@ void QgsAttributeTable::handleChangedSelections()
//if there is no current selection, there is nothing to do
if (currentSelection() == -1)
emit repaintRequested();

@@ -139,7 +139,9 @@ void QgsAttributeTable::handleChangedSelections()
emit selected(text(index, 0).toInt());

emit repaintRequested();
//don't send the signal repaintRequested() from here
//but in contentsMouseReleaseEvent() and rowClicked(int)
//todo: don't repaint in case of double clicks


@@ -662,3 +664,41 @@ void QgsAttributeTable::showAllRows()
for (int i = 0; i < numRows(); i++)

void QgsAttributeTable::rowClicked(int row)
if(checkSelectionChanges())//only repaint the canvas if the selection has changed
emit repaintRequested();

void QgsAttributeTable::contentsMouseReleaseEvent(QMouseEvent* e)
if(checkSelectionChanges())//only repaint the canvas if the selection has changed
emit repaintRequested();

bool QgsAttributeTable::checkSelectionChanges()
std::set<int> theCurrentSelection;
Q3TableSelection cselection;
cselection = selection(currentSelection());
for (int index = cselection.topRow(); index <= cselection.bottomRow(); index++)

if(theCurrentSelection == mLastSelectedRows)
return false;
mLastSelectedRows = theCurrentSelection;
return true;
@@ -105,6 +105,7 @@ class QgsAttributeTable:public Q3Table

public slots:
void columnClicked(int col);
void rowClicked(int row);
// Called when the user requests a popup menu
void popupMenu(int row, int col, const QPoint& pos);
// Called when the user chooses an item on the popup menu
@@ -132,6 +133,8 @@ class QgsAttributeTable:public Q3Table
/**Nested map containing the changed attribute values. The int is the feature id,
the first QString the attribute name and the second QString the new value*/
std::map<int,std::map<QString,QString> > mChangedValues;
/**Stors the numbers of the last selected rows. This is used to check for selection changes before emit repaintRequested()*/
std::set<int> mLastSelectedRows;

/**Compares the content of two cells either alphanumeric or numeric. If 'ascending' is true, -1 means s1 is less, 0 equal, 1 greater. If 'ascending' is false, -1 means s1 is more, 0 equal, 1 greater. This method is used mainly to sort a column*/
int compareItems(QString s1, QString s2, bool ascending, bool alphanumeric);
@@ -146,7 +149,10 @@ class QgsAttributeTable:public Q3Table
void removeAttrColumn(const QString& name);
/** puts attributes of feature to the chosen table row */
void putFeatureInTable(int row, QgsFeature* fet);

void contentsMouseReleaseEvent(QMouseEvent* e);
/**This function compares the current selection and the selection of the last repaint. Returns true if there are differences in the selection.
Also, mLastSelectedRows is updated*/
bool checkSelectionChanges();

/**Is emitted when a row was selected*/

0 comments on commit 27ce9ef

Please sign in to comment.