mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Made the actions popup menu accessable from the attribute table dialog
box. git-svn-id: http://svn.osgeo.org/qgis/trunk@2240 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
c7ba33f0f2
commit
c0c2fd0e89
@ -18,13 +18,15 @@
|
||||
/* $Id$ */
|
||||
#include <qapplication.h>
|
||||
#include <qcursor.h>
|
||||
#include <qpopupmenu.h>
|
||||
#include <qlabel.h>
|
||||
#include <qfont.h>
|
||||
#include "qgsattributetable.h"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
QgsAttributeTable::QgsAttributeTable(QWidget * parent, const char *name):QTable(parent, name), lockKeyPressed(false),
|
||||
sort_ascending(true)
|
||||
sort_ascending(true), mActionPopup(0)
|
||||
{
|
||||
QFont f(font());
|
||||
f.setFamily("Helvetica");
|
||||
@ -32,6 +34,7 @@ sort_ascending(true)
|
||||
setFont(f);
|
||||
setSelectionMode(QTable::MultiRow);
|
||||
QObject::connect(this, SIGNAL(selectionChanged()), this, SLOT(handleChangedSelections()));
|
||||
connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint&)), this, SLOT(popupMenu(int, int, const QPoint&)));
|
||||
setFocus();
|
||||
}
|
||||
|
||||
@ -255,3 +258,55 @@ void QgsAttributeTable::contentsMouseReleaseEvent(QMouseEvent * e)
|
||||
contentsMouseMoveEvent(e); //send out a move event to keep the selections updated
|
||||
emit repaintRequested();
|
||||
}
|
||||
|
||||
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 QPopupMenu();
|
||||
|
||||
QLabel* popupLabel = new QLabel( mActionPopup );
|
||||
popupLabel->setText( tr("<center>Run action</center>") );
|
||||
mActionPopup->insertItem(popupLabel);
|
||||
mActionPopup->insertSeparator();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Get and store the attribute values and their column names are
|
||||
// these are needed for substituting into the actions if the user
|
||||
// chooses one.
|
||||
mActionValues.clear();
|
||||
QHeader* header = horizontalHeader();
|
||||
|
||||
#ifdef QGISDEBUG
|
||||
if (header->count() != numCols())
|
||||
std::cerr << "Something wrong with the table (file "
|
||||
<< __FILE__<< ", line " << __LINE__
|
||||
<< ")." << std::endl;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < numCols(); ++i)
|
||||
mActionValues.push_back(std::make_pair(header->label(i), text(row, i)));
|
||||
|
||||
// The item that was clicked on, stored as an index into the
|
||||
// mActionValues vector.
|
||||
mClickedOnValue = col;
|
||||
|
||||
mActionPopup->popup(pos);
|
||||
}
|
||||
|
||||
void QgsAttributeTable::popupItemSelected(int id)
|
||||
{
|
||||
mActions.doAction(id, mActionValues, mClickedOnValue);
|
||||
}
|
||||
|
@ -22,6 +22,11 @@
|
||||
#include <qtable.h>
|
||||
#include <qmap.h>
|
||||
|
||||
class QPopupMenu;
|
||||
#include "qgsattributeaction.h"
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
/**
|
||||
*@author Gary E.Sherman
|
||||
*/
|
||||
@ -40,8 +45,17 @@ class QgsAttributeTable:public QTable
|
||||
void selectRowWithId(int id);
|
||||
/**Sorts a column. This method replaces the one from QTable to allow numeric sorting*/
|
||||
virtual void sortColumn(int col, bool ascending=true, bool wholeRows=false);
|
||||
/* Use this to give this class the current attribute actions,
|
||||
which are used when the user requests a popup menu */
|
||||
void setAttributeActions(const QgsAttributeAction& actions)
|
||||
{ mActions = actions; }
|
||||
|
||||
public slots:
|
||||
void columnClicked(int col);
|
||||
// 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);
|
||||
protected slots:
|
||||
void handleChangedSelections();
|
||||
protected:
|
||||
@ -58,6 +72,7 @@ class QgsAttributeTable:public QTable
|
||||
/**Method used by sortColumn (implementation of a quicksort)*/
|
||||
void qsort(int lower, int upper, int col, bool ascending, bool alphanumeric);
|
||||
void contentsMouseReleaseEvent(QMouseEvent* e);
|
||||
|
||||
signals:
|
||||
|
||||
/**Is emitted when a row was selected*/
|
||||
@ -66,6 +81,14 @@ class QgsAttributeTable:public QTable
|
||||
void selectionRemoved();
|
||||
/**Is emmited when a set of related selection and deselection signals have been emitted*/
|
||||
void repaintRequested();
|
||||
|
||||
private:
|
||||
|
||||
// Data to do with providing a popup menu of actions that
|
||||
std::vector<std::pair<QString, QString> > mActionValues;
|
||||
int mClickedOnValue;
|
||||
QPopupMenu* mActionPopup;
|
||||
QgsAttributeAction mActions;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -679,6 +679,9 @@ void QgsVectorLayer::table()
|
||||
if (tabledisplay)
|
||||
{
|
||||
tabledisplay->raise();
|
||||
// Give the table the most recent copy of the actions for this
|
||||
// layer.
|
||||
tabledisplay->table()->setAttributeActions(mActions);
|
||||
} else
|
||||
{
|
||||
// display the attribute table
|
||||
@ -727,6 +730,9 @@ void QgsVectorLayer::table()
|
||||
tabledisplay->show();
|
||||
tabledisplay->table()->clearSelection(); //deselect the first row
|
||||
|
||||
// Give the table the most recent copy of the actions for this
|
||||
// layer.
|
||||
tabledisplay->table()->setAttributeActions(mActions);
|
||||
|
||||
QObject::disconnect(tabledisplay->table(), SIGNAL(selectionChanged()), tabledisplay->table(), SLOT(handleChangedSelections()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user