18
18
/* $Id$ */
19
19
#include < QApplication>
20
20
#include < QMouseEvent>
21
- #include < Q3PopupMenu>
22
21
#include < QKeyEvent>
23
22
#include < QLabel>
24
23
#include < QFont>
25
24
#include < QClipboard>
26
- #include < Q3ValueList>
25
+ #include < QAction>
26
+ #include < QMenu>
27
27
28
28
#include " qgsattributetable.h"
29
29
#include " qgsfeature.h"
@@ -63,7 +63,7 @@ void QgsAttributeTable::columnClicked(int col)
63
63
QApplication::setOverrideCursor (Qt::waitCursor);
64
64
65
65
// store the ids of the selected rows in a list
66
- Q3ValueList < int >idsOfSelected;
66
+ QList < int >idsOfSelected;
67
67
for (int i = 0 ; i < numSelections (); i++)
68
68
{
69
69
for (int j = selection (i).topRow (); j <= selection (i).bottomRow (); j++)
@@ -88,7 +88,7 @@ void QgsAttributeTable::columnClicked(int col)
88
88
89
89
// select the rows again after sorting
90
90
91
- Q3ValueList < int >::iterator it;
91
+ QList < int >::iterator it;
92
92
for (it = idsOfSelected.begin (); it != idsOfSelected.end (); ++it)
93
93
{
94
94
selectRowWithId ((*it));
@@ -276,29 +276,24 @@ void QgsAttributeTable::contentsMouseReleaseEvent(QMouseEvent * e)
276
276
277
277
void QgsAttributeTable::popupMenu (int row, int col, const QPoint& pos)
278
278
{
279
- std::cerr << " context menu requested" << std::endl;
280
-
281
279
// Duplication of code in qgsidentufyresults.cpp. Consider placing
282
280
// in a seperate class
283
281
if (mActionPopup == 0 )
284
282
{
285
- mActionPopup = new Q3PopupMenu ();
286
-
287
- QLabel* popupLabel = new QLabel ( mActionPopup );
288
- popupLabel->setText ( tr (" <center>Run action</center>" ) );
289
- // TODO: Qt4 uses "QAction"s - need to refactor.
290
- #if QT_VERSION < 0x040000
291
- mActionPopup ->insertItem (popupLabel);
292
- #endif
293
- mActionPopup ->insertSeparator ();
283
+ mActionPopup = new QMenu ();
284
+ QAction *a = mActionPopup ->addAction ( tr (" Run action" ) );
285
+ mActionPopup ->addSeparator ();
294
286
295
287
QgsAttributeAction::aIter iter = mActions .begin ();
296
288
for (int j = 0 ; iter != mActions .end (); ++iter, ++j)
297
289
{
298
- int id = mActionPopup ->insertItem (iter->name (), this ,
299
- SLOT (popupItemSelected (int )));
300
- mActionPopup ->setItemParameter (id, j);
290
+ QAction* a = mActionPopup ->addAction (iter->name ());
291
+ // The menu action stores an integer that is used later on to
292
+ // associate an menu action with an actual qgis action.
293
+ a->setData (QVariant::fromValue (j));
301
294
}
295
+ connect (mActionPopup , SIGNAL (triggered (QAction*)),
296
+ this , SLOT (popupItemSelected (QAction*)));
302
297
}
303
298
304
299
// Get and store the attribute values and their column names are
@@ -324,8 +319,9 @@ void QgsAttributeTable::popupMenu(int row, int col, const QPoint& pos)
324
319
mActionPopup ->popup (pos);
325
320
}
326
321
327
- void QgsAttributeTable::popupItemSelected (int id )
322
+ void QgsAttributeTable::popupItemSelected (QAction* menuAction )
328
323
{
324
+ int id = menuAction->data ().toInt ();
329
325
mActions .doAction (id, mActionValues , mClickedOnValue );
330
326
}
331
327
0 commit comments