2019.diff
src/app/attributetable/qgsattributetableview.cpp (working copy) | ||
---|---|---|
16 | 16 |
#include <QKeyEvent> |
17 | 17 |
#include <QSettings> |
18 | 18 |
#include <QHeaderView> |
19 |
#include <QMenu> |
|
19 | 20 | |
20 | 21 |
#include "qgsattributetableview.h" |
21 | 22 |
#include "qgsattributetablemodel.h" |
... | ... | |
25 | 26 | |
26 | 27 |
#include "qgsvectorlayer.h" |
27 | 28 |
#include "qgsvectordataprovider.h" |
29 |
#include "qgsattributeaction.h" |
|
28 | 30 | |
29 | ||
30 | 31 |
QgsAttributeTableView::QgsAttributeTableView( QWidget* parent ) |
31 |
: QTableView( parent ) |
|
32 |
: QTableView( parent ), mActionPopup( 0 )
|
|
32 | 33 |
{ |
33 | 34 |
QSettings settings; |
34 | 35 |
restoreGeometry( settings.value( "/BetterTable/geometry" ).toByteArray() ); |
... | ... | |
41 | 42 |
setSelectionBehavior( QAbstractItemView::SelectRows ); |
42 | 43 |
setSelectionMode( QAbstractItemView::NoSelection ); |
43 | 44 |
setSortingEnabled( true ); |
44 | ||
45 | 45 |
} |
46 | 46 | |
47 | 47 |
void QgsAttributeTableView::setLayer( QgsVectorLayer* layer ) |
... | ... | |
64 | 64 |
{ |
65 | 65 |
delete mModel; |
66 | 66 |
delete mFilterModel; |
67 |
delete mActionPopup; |
|
67 | 68 |
} |
68 | 69 | |
69 | 70 |
void QgsAttributeTableView::closeEvent( QCloseEvent *event ) |
... | ... | |
71 | 72 |
QSettings settings; |
72 | 73 |
settings.setValue( "/BetterAttributeTable/geometry", QVariant( saveGeometry() ) ); |
73 | 74 |
} |
75 | ||
76 |
void QgsAttributeTableView::contextMenuEvent( QContextMenuEvent *event ) |
|
77 |
{ |
|
78 |
if ( mActionPopup ) |
|
79 |
{ |
|
80 |
delete mActionPopup; |
|
81 |
mActionPopup = 0; |
|
82 |
} |
|
83 | ||
84 |
QModelIndex idx = indexAt( event->pos() ); |
|
85 |
if ( !idx.isValid() ) |
|
86 |
{ |
|
87 |
return; |
|
88 |
} |
|
89 | ||
90 |
QgsVectorLayer *vlayer = mModel->layer(); |
|
91 |
if ( !vlayer || vlayer->actions()->size() == 0 ) |
|
92 |
{ |
|
93 |
return; |
|
94 |
} |
|
95 | ||
96 |
mActionPopup = new QMenu(); |
|
97 | ||
98 |
QAction *a = mActionPopup->addAction( tr( "Run action" ) ); |
|
99 |
a->setEnabled( false ); |
|
100 | ||
101 |
for ( int i = 0; i < vlayer->actions()->size(); i++ ) |
|
102 |
{ |
|
103 |
const QgsAction &action = vlayer->actions()->at( i ); |
|
104 | ||
105 |
if ( !action.runable() ) |
|
106 |
continue; |
|
107 | ||
108 |
QgsAttributeTableAction *a = new QgsAttributeTableAction( action.name(), this, mModel, i, idx ); |
|
109 |
mActionPopup->addAction( action.name(), a, SLOT( execute() ) ); |
|
110 |
} |
|
111 | ||
112 |
mActionPopup->popup( event->globalPos() ); |
|
113 |
} |
|
114 | ||
115 |
void QgsAttributeTableAction::execute() |
|
116 |
{ |
|
117 |
mModel->executeAction( mAction, mFieldIdx ); |
|
118 |
} |
src/app/attributetable/qgsattributetableview.h (working copy) | ||
---|---|---|
17 | 17 |
#define QGSATTRIBUTETABLEVIEW_H |
18 | 18 | |
19 | 19 |
#include <QTableView> |
20 |
#include <QAction> |
|
20 | 21 | |
21 | 22 |
class QgsAttributeTableModel; |
22 | 23 |
class QgsAttributeTableFilterModel; |
23 | 24 | |
24 | 25 |
class QgsVectorLayer; |
26 |
class QMenu; |
|
25 | 27 | |
26 | 28 | |
27 | 29 |
class QgsAttributeTableView: public QTableView |
... | ... | |
42 | 44 |
*/ |
43 | 45 |
void closeEvent( QCloseEvent *event ); |
44 | 46 | |
47 |
void contextMenuEvent( QContextMenuEvent* ); |
|
48 | ||
45 | 49 |
private: |
46 | 50 |
QgsAttributeTableModel* mModel; |
47 | 51 |
QgsAttributeTableFilterModel* mFilterModel; |
52 |
QMenu *mActionPopup; |
|
48 | 53 |
}; |
49 | 54 | |
55 |
class QgsAttributeTableAction : public QAction |
|
56 |
{ |
|
57 |
Q_OBJECT |
|
58 | ||
59 |
public: |
|
60 |
QgsAttributeTableAction( const QString &name, QgsAttributeTableView *view, QgsAttributeTableModel *model, int action, const QModelIndex &fieldIdx ) : |
|
61 |
QAction( name, view ), mModel( model ), mAction( action ), mFieldIdx( fieldIdx ) |
|
62 |
{} |
|
63 | ||
64 |
public slots: |
|
65 |
void execute(); |
|
66 | ||
67 |
private: |
|
68 |
QgsAttributeTableModel *mModel; |
|
69 |
int mAction; |
|
70 |
QModelIndex mFieldIdx; |
|
71 |
}; |
|
72 | ||
73 | ||
50 | 74 |
#endif |
src/app/attributetable/qgsattributetablemodel.cpp (working copy) | ||
---|---|---|
19 | 19 |
#include "qgsfield.h" |
20 | 20 |
#include "qgsvectorlayer.h" |
21 | 21 |
#include "qgslogger.h" |
22 |
#include "qgisapp.h" |
|
23 |
#include "qgsattributeaction.h" |
|
22 | 24 | |
23 | 25 |
#include <QtGui> |
24 | 26 |
#include <QVariant> |
... | ... | |
317 | 319 |
return QVariant( attributeName ); |
318 | 320 |
} |
319 | 321 |
} |
320 |
else return QVariant(); |
|
322 |
else |
|
323 |
{ |
|
324 |
return QVariant(); |
|
325 |
} |
|
321 | 326 |
} |
322 | 327 | |
323 | 328 |
void QgsAttributeTableModel::sort( int column, Qt::SortOrder order ) |
... | ... | |
487 | 492 |
emit layoutAboutToBeChanged(); |
488 | 493 |
} |
489 | 494 | |
495 |
static void _runPythonString( const QString &expr ) |
|
496 |
{ |
|
497 |
QgisApp::instance()->runPythonString( expr ); |
|
498 |
} |
|
499 | ||
500 |
void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const |
|
501 |
{ |
|
502 |
QList< QPair<QString, QString> > attributes; |
|
503 | ||
504 |
for ( int i = 0; i < mAttributes.size(); i++ ) |
|
505 |
{ |
|
506 |
attributes << QPair<QString, QString>( |
|
507 |
mLayer->pendingFields()[ mAttributes[i] ].name(), |
|
508 |
data( index( idx.row(), i ), Qt::EditRole ).toString() |
|
509 |
); |
|
510 |
} |
|
511 | ||
512 |
mLayer->actions()->doAction( action, attributes, fieldIdx( idx.column() ), _runPythonString ); |
|
513 |
} |
src/app/attributetable/qgsattributetablemodel.h (working copy) | ||
---|---|---|
125 | 125 |
*/ |
126 | 126 |
QgsVectorLayer* layer() const { return mLayer; } |
127 | 127 | |
128 |
/** Execute an action */ |
|
129 |
void executeAction( int action, const QModelIndex &idx ) const; |
|
130 | ||
128 | 131 |
signals: |
129 | 132 |
/** |
130 | 133 |
* Model has been changed |
src/app/CMakeLists.txt (working copy) | ||
---|---|---|
192 | 192 |
ogr/qgsopenvectorlayerdialog.h |
193 | 193 |
ogr/qgsnewogrconnection.h |
194 | 194 |
|
195 |
attributetable/qgsattributetableview.h |
|
195 | 196 |
attributetable/qgsattributetablemodel.h |
196 | 197 |
attributetable/qgsattributetablememorymodel.h |
197 | 198 |
attributetable/qgsattributetabledialog.h |