Skip to content

Commit 27ce9ef

Browse files
author
mhugent
committed
Changed the selection behaviour of the attribute table. The repaintRequest 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/qgis@5706 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 37afa70 commit 27ce9ef

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/gui/qgsattributetable.cpp

+42-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ QgsAttributeTable::QgsAttributeTable(QWidget * parent, const char *name):
5050
QObject::connect(this, SIGNAL(selectionChanged()), this, SLOT(handleChangedSelections()));
5151
connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint&)), this, SLOT(popupMenu(int, int, const QPoint&)));
5252
connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(storeChangedValue(int,int)));
53+
connect(verticalHeader(), SIGNAL(released(int)), this, SLOT(rowClicked(int)));
5354
setReadOnly(true);
5455
setFocus();
5556
}
@@ -128,7 +129,6 @@ void QgsAttributeTable::handleChangedSelections()
128129
//if there is no current selection, there is nothing to do
129130
if (currentSelection() == -1)
130131
{
131-
emit repaintRequested();
132132
return;
133133
}
134134

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

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

144146
}
145147

@@ -662,3 +664,41 @@ void QgsAttributeTable::showAllRows()
662664
for (int i = 0; i < numRows(); i++)
663665
showRow(i);
664666
}
667+
668+
void QgsAttributeTable::rowClicked(int row)
669+
{
670+
if(checkSelectionChanges())//only repaint the canvas if the selection has changed
671+
{
672+
emit repaintRequested();
673+
}
674+
}
675+
676+
void QgsAttributeTable::contentsMouseReleaseEvent(QMouseEvent* e)
677+
{
678+
if(checkSelectionChanges())//only repaint the canvas if the selection has changed
679+
{
680+
emit repaintRequested();
681+
}
682+
Q3Table::contentsMouseReleaseEvent(e);
683+
}
684+
685+
bool QgsAttributeTable::checkSelectionChanges()
686+
{
687+
std::set<int> theCurrentSelection;
688+
Q3TableSelection cselection;
689+
cselection = selection(currentSelection());
690+
for (int index = cselection.topRow(); index <= cselection.bottomRow(); index++)
691+
{
692+
theCurrentSelection.insert(index);
693+
}
694+
695+
if(theCurrentSelection == mLastSelectedRows)
696+
{
697+
return false;
698+
}
699+
else
700+
{
701+
mLastSelectedRows = theCurrentSelection;
702+
return true;
703+
}
704+
}

src/gui/qgsattributetable.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class QgsAttributeTable:public Q3Table
105105

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

136139
/**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*/
137140
int compareItems(QString s1, QString s2, bool ascending, bool alphanumeric);
@@ -146,7 +149,10 @@ class QgsAttributeTable:public Q3Table
146149
void removeAttrColumn(const QString& name);
147150
/** puts attributes of feature to the chosen table row */
148151
void putFeatureInTable(int row, QgsFeature* fet);
149-
152+
void contentsMouseReleaseEvent(QMouseEvent* e);
153+
/**This function compares the current selection and the selection of the last repaint. Returns true if there are differences in the selection.
154+
Also, mLastSelectedRows is updated*/
155+
bool checkSelectionChanges();
150156
signals:
151157

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

0 commit comments

Comments
 (0)