Skip to content
Permalink
Browse files
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/qgis@5501 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Jun 1, 2006
1 parent b63a8ed commit efb2cbfffaa309aad29dd019f385e9f85177c777
Showing with 42 additions and 36 deletions.
  1. +5 −3 src/core/qgsfield.cpp
  2. +15 −19 src/gui/qgsattributetable.cpp
  3. +4 −3 src/gui/qgsattributetable.h
  4. +15 −9 src/gui/qgsidentifyresults.cpp
  5. +3 −2 src/gui/qgsidentifyresults.h
@@ -28,9 +28,11 @@ static const char * const ident_ =
QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num)
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num)
{
// lower case the field name since some stores use upper case
// (eg. shapefiles)
mName = mName.lower();
// This function used to lower case the field name since some stores
// use upper case (eg. shapefiles), but that caused problems with
// attribute actions getting confused between uppercase and
// lowercase versions of the attribute names, so just leave the
// names how they are now.
}

QgsField::~QgsField()
@@ -18,12 +18,12 @@
/* $Id$ */
#include <QApplication>
#include <QMouseEvent>
#include <Q3PopupMenu>
#include <QKeyEvent>
#include <QLabel>
#include <QFont>
#include <QClipboard>
#include <Q3ValueList>
#include <QAction>
#include <QMenu>

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

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

//select the rows again after sorting

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

void QgsAttributeTable::popupMenu(int row, int col, const QPoint& pos)
{
std::cerr << "context menu requested" << std::endl;

// Duplication of code in qgsidentufyresults.cpp. Consider placing
// in a seperate class
if (mActionPopup == 0)
{
mActionPopup = new Q3PopupMenu();

QLabel* popupLabel = new QLabel( mActionPopup );
popupLabel->setText( tr("<center>Run action</center>") );
// TODO: Qt4 uses "QAction"s - need to refactor.
#if QT_VERSION < 0x040000
mActionPopup->insertItem(popupLabel);
#endif
mActionPopup->insertSeparator();
mActionPopup = new QMenu();
QAction *a = mActionPopup->addAction( tr("Run action") );
mActionPopup->addSeparator();

QgsAttributeAction::aIter iter = mActions.begin();
for (int j = 0; iter != mActions.end(); ++iter, ++j)
{
int id = mActionPopup->insertItem(iter->name(), this,
SLOT(popupItemSelected(int)));
mActionPopup->setItemParameter(id, j);
QAction* a = mActionPopup->addAction(iter->name());
// The menu action stores an integer that is used later on to
// associate an menu action with an actual qgis action.
a->setData(QVariant::fromValue(j));
}
connect(mActionPopup, SIGNAL(triggered(QAction*)),
this, SLOT(popupItemSelected(QAction*)));
}

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

void QgsAttributeTable::popupItemSelected(int id)
void QgsAttributeTable::popupItemSelected(QAction* menuAction)
{
int id = menuAction->data().toInt();
mActions.doAction(id, mActionValues, mClickedOnValue);
}

@@ -25,11 +25,12 @@
#include <map>
#include <set>

class Q3PopupMenu;
class QgsVectorLayer;
class QgsFeature;
class QMouseEvent;
class QKeyEvent;
class QAction;
class QMenu;

#include "qgsattributeaction.h"

@@ -93,7 +94,7 @@ class QgsAttributeTable:public Q3Table
// 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
void popupItemSelected(int id);
void popupItemSelected(QAction * menuAction);
protected slots:
void handleChangedSelections();
/**Writes changed values to 'mChangedValues'*/
@@ -146,7 +147,7 @@ class QgsAttributeTable:public Q3Table
// Data to do with providing a popup menu of actions that
std::vector<std::pair<QString, QString> > mActionValues;
int mClickedOnValue;
Q3PopupMenu* mActionPopup;
QMenu* mActionPopup;
QgsAttributeAction mActions;
};

@@ -22,6 +22,7 @@

#include <QCloseEvent>
#include <QLabel>
#include <QAction>
#include <Q3ListView>
#include <QPixmap>
#include <Q3PopupMenu>
@@ -79,20 +80,24 @@ void QgsIdentifyResults::popupContextMenu(Q3ListViewItem* item,
// such a dialog box is around.
if (mActionPopup == 0)
{
mActionPopup = new Q3PopupMenu();
mActionPopup = new QMenu();
QAction *a = mActionPopup->addAction( tr("Run action") );
QFont f = a->font();
f.setBold(true);
a->setFont(f);

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

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

// Run the action that was selected in the popup menu
void QgsIdentifyResults::popupItemSelected(int id)
void QgsIdentifyResults::popupItemSelected(QAction* menuAction)
{
int id = menuAction->data().toInt();
mActions.doAction(id, mValues, mClickedOnValue);
}

@@ -27,6 +27,7 @@
class QCloseEvent;
class Q3ListViewItem;
class Q3PopupMenu;
class QAction;

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

void close();
void popupContextMenu(Q3ListViewItem*, const QPoint&, int);
void popupItemSelected(int id);
void popupItemSelected(QAction* menuAction);

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

QgsAttributeAction mActions;
int mClickedOnValue;
Q3PopupMenu* mActionPopup;
QMenu* mActionPopup;
std::vector<std::pair<QString, QString> > mValues;
};

0 comments on commit efb2cbf

Please sign in to comment.