Skip to content
Permalink
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: http://svn.osgeo.org/qgis/trunk@5706 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 18, 2006
1 parent 336ae2a commit 99ff0493d60d134e071be5038edd89acd731ef60
Showing with 49 additions and 3 deletions.
  1. +42 −2 src/gui/qgsattributetable.cpp
  2. +7 −1 src/gui/qgsattributetable.h
@@ -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)));
setReadOnly(true);
setFocus();
}
@@ -128,7 +129,6 @@ void QgsAttributeTable::handleChangedSelections()
//if there is no current selection, there is nothing to do
if (currentSelection() == -1)
{
emit repaintRequested();
return;
}

@@ -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++)
showRow(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();
}
Q3Table::contentsMouseReleaseEvent(e);
}

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

if(theCurrentSelection == mLastSelectedRows)
{
return false;
}
else
{
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();
signals:

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

0 comments on commit 99ff049

Please sign in to comment.