Skip to content

Commit 0f11f90

Browse files
author
g_j_m
committed
Fix for tickets #127 and #128.
Qgis now respects the case of attribute names, as this was mucking up attribute actions, which depend on consistent attribute names to work correctly. git-svn-id: http://svn.osgeo.org/qgis/trunk@5501 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6535d24 commit 0f11f90

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

src/core/qgsfield.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ static const char * const ident_ =
2828
QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num)
2929
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num)
3030
{
31-
// lower case the field name since some stores use upper case
32-
// (eg. shapefiles)
33-
mName = mName.lower();
31+
// This function used to lower case the field name since some stores
32+
// use upper case (eg. shapefiles), but that caused problems with
33+
// attribute actions getting confused between uppercase and
34+
// lowercase versions of the attribute names, so just leave the
35+
// names how they are now.
3436
}
3537

3638
QgsField::~QgsField()

src/gui/qgsattributetable.cpp

+15-19
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
/* $Id$ */
1919
#include <QApplication>
2020
#include <QMouseEvent>
21-
#include <Q3PopupMenu>
2221
#include <QKeyEvent>
2322
#include <QLabel>
2423
#include <QFont>
2524
#include <QClipboard>
26-
#include <Q3ValueList>
25+
#include <QAction>
26+
#include <QMenu>
2727

2828
#include "qgsattributetable.h"
2929
#include "qgsfeature.h"
@@ -63,7 +63,7 @@ void QgsAttributeTable::columnClicked(int col)
6363
QApplication::setOverrideCursor(Qt::waitCursor);
6464

6565
//store the ids of the selected rows in a list
66-
Q3ValueList < int >idsOfSelected;
66+
QList < int >idsOfSelected;
6767
for (int i = 0; i < numSelections(); i++)
6868
{
6969
for (int j = selection(i).topRow(); j <= selection(i).bottomRow(); j++)
@@ -88,7 +88,7 @@ void QgsAttributeTable::columnClicked(int col)
8888

8989
//select the rows again after sorting
9090

91-
Q3ValueList < int >::iterator it;
91+
QList < int >::iterator it;
9292
for (it = idsOfSelected.begin(); it != idsOfSelected.end(); ++it)
9393
{
9494
selectRowWithId((*it));
@@ -276,29 +276,24 @@ void QgsAttributeTable::contentsMouseReleaseEvent(QMouseEvent * e)
276276

277277
void QgsAttributeTable::popupMenu(int row, int col, const QPoint& pos)
278278
{
279-
std::cerr << "context menu requested" << std::endl;
280-
281279
// Duplication of code in qgsidentufyresults.cpp. Consider placing
282280
// in a seperate class
283281
if (mActionPopup == 0)
284282
{
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();
294286

295287
QgsAttributeAction::aIter iter = mActions.begin();
296288
for (int j = 0; iter != mActions.end(); ++iter, ++j)
297289
{
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));
301294
}
295+
connect(mActionPopup, SIGNAL(triggered(QAction*)),
296+
this, SLOT(popupItemSelected(QAction*)));
302297
}
303298

304299
// 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)
324319
mActionPopup->popup(pos);
325320
}
326321

327-
void QgsAttributeTable::popupItemSelected(int id)
322+
void QgsAttributeTable::popupItemSelected(QAction* menuAction)
328323
{
324+
int id = menuAction->data().toInt();
329325
mActions.doAction(id, mActionValues, mClickedOnValue);
330326
}
331327

src/gui/qgsattributetable.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
#include <map>
2626
#include <set>
2727

28-
class Q3PopupMenu;
2928
class QgsVectorLayer;
3029
class QgsFeature;
3130
class QMouseEvent;
3231
class QKeyEvent;
32+
class QAction;
33+
class QMenu;
3334

3435
#include "qgsattributeaction.h"
3536

@@ -93,7 +94,7 @@ class QgsAttributeTable:public Q3Table
9394
// Called when the user requests a popup menu
9495
void popupMenu(int row, int col, const QPoint& pos);
9596
// Called when the user chooses an item on the popup menu
96-
void popupItemSelected(int id);
97+
void popupItemSelected(QAction * menuAction);
9798
protected slots:
9899
void handleChangedSelections();
99100
/**Writes changed values to 'mChangedValues'*/
@@ -146,7 +147,7 @@ class QgsAttributeTable:public Q3Table
146147
// Data to do with providing a popup menu of actions that
147148
std::vector<std::pair<QString, QString> > mActionValues;
148149
int mClickedOnValue;
149-
Q3PopupMenu* mActionPopup;
150+
QMenu* mActionPopup;
150151
QgsAttributeAction mActions;
151152
};
152153

src/gui/qgsidentifyresults.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <QCloseEvent>
2424
#include <QLabel>
25+
#include <QAction>
2526
#include <Q3ListView>
2627
#include <QPixmap>
2728
#include <Q3PopupMenu>
@@ -79,20 +80,24 @@ void QgsIdentifyResults::popupContextMenu(Q3ListViewItem* item,
7980
// such a dialog box is around.
8081
if (mActionPopup == 0)
8182
{
82-
mActionPopup = new Q3PopupMenu();
83+
mActionPopup = new QMenu();
84+
QAction *a = mActionPopup->addAction( tr("Run action") );
85+
QFont f = a->font();
86+
f.setBold(true);
87+
a->setFont(f);
8388

84-
QLabel* popupLabel = new QLabel( mActionPopup );
85-
popupLabel->setText( tr("<center>Run action</center>") );
86-
// TODO: Qt4 uses "QAction"s - need to refactor.
87-
mActionPopup->insertSeparator();
89+
mActionPopup->addSeparator();
8890

8991
QgsAttributeAction::aIter iter = mActions.begin();
9092
for (int j = 0; iter != mActions.end(); ++iter, ++j)
9193
{
92-
int id = mActionPopup->insertItem(iter->name(), this,
93-
SLOT(popupItemSelected(int)));
94-
mActionPopup->setItemParameter(id, j);
94+
QAction* a = mActionPopup->addAction(iter->name());
95+
// The menu action stores an integer that is used later on to
96+
// associate an menu action with an actual qgis action.
97+
a->setData(QVariant::fromValue(j));
9598
}
99+
connect(mActionPopup, SIGNAL(triggered(QAction*)),
100+
this, SLOT(popupItemSelected(QAction*)));
96101
}
97102
// Save the attribute values as these are needed for substituting into
98103
// the action.
@@ -190,8 +195,9 @@ void QgsIdentifyResults::setColumnText ( int column, const QString & label )
190195
}
191196

192197
// Run the action that was selected in the popup menu
193-
void QgsIdentifyResults::popupItemSelected(int id)
198+
void QgsIdentifyResults::popupItemSelected(QAction* menuAction)
194199
{
200+
int id = menuAction->data().toInt();
195201
mActions.doAction(id, mValues, mClickedOnValue);
196202
}
197203

src/gui/qgsidentifyresults.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class QCloseEvent;
2828
class Q3ListViewItem;
2929
class Q3PopupMenu;
30+
class QAction;
3031

3132
/**
3233
*@author Gary E.Sherman
@@ -78,7 +79,7 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
7879

7980
void close();
8081
void popupContextMenu(Q3ListViewItem*, const QPoint&, int);
81-
void popupItemSelected(int id);
82+
void popupItemSelected(QAction* menuAction);
8283

8384
/* Item in tree was clicked */
8485
void clicked ( Q3ListViewItem *lvi );
@@ -87,7 +88,7 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
8788

8889
QgsAttributeAction mActions;
8990
int mClickedOnValue;
90-
Q3PopupMenu* mActionPopup;
91+
QMenu* mActionPopup;
9192
std::vector<std::pair<QString, QString> > mValues;
9293
};
9394

0 commit comments

Comments
 (0)