Skip to content

Commit

Permalink
Add field calc to main app window
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed May 15, 2013
1 parent 4b76600 commit 1bfa7e9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class QgisInterface : QObject
/** @note added in 1.9 */
virtual QAction *actionPasteLayerStyle() = 0;
virtual QAction *actionOpenTable() = 0;
virtual QAction *actionOpenFieldCalculator() = 0;
virtual QAction *actionToggleEditing() = 0;
/** @note added in 1.9 */
virtual QAction *actionSaveActiveLayerEdits() = 0;
Expand Down
35 changes: 35 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#include "qgsexpressionselectiondialog.h"
#include "qgsfeature.h"
#include "qgsformannotationitem.h"
#include "qgsfieldcalculator.h"
#include "qgshtmlannotationitem.h"
#include "qgsgenericprojectionselector.h"
#include "qgsgpsinformationwidget.h"
Expand Down Expand Up @@ -981,6 +982,7 @@ void QgisApp::createActions()
connect( mActionAddWcsLayer, SIGNAL( triggered() ), this, SLOT( addWcsLayer() ) );
connect( mActionAddWfsLayer, SIGNAL( triggered() ), this, SLOT( addWfsLayer() ) );
connect( mActionOpenTable, SIGNAL( triggered() ), this, SLOT( attributeTable() ) );
connect( mActionOpenFieldCalc, SIGNAL( triggered() ), this, SLOT( fieldCalculator() ) );
connect( mActionToggleEditing, SIGNAL( triggered() ), this, SLOT( toggleEditing() ) );
connect( mActionSaveLayerEdits, SIGNAL( triggered() ), this, SLOT( saveActiveLayerEdits() ) );
connect( mActionSaveEdits, SIGNAL( triggered() ), this, SLOT( saveEdits() ) );
Expand Down Expand Up @@ -1738,6 +1740,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionDeselectAll->setIcon( QgsApplication::getThemeIcon( "/mActionDeselectAll.png" ) );
mActionSelectByExpression->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
mActionOpenTable->setIcon( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ) );
mActionOpenFieldCalc->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) );
mActionMeasure->setIcon( QgsApplication::getThemeIcon( "/mActionMeasure.png" ) );
mActionMeasureArea->setIcon( QgsApplication::getThemeIcon( "/mActionMeasureArea.png" ) );
mActionMeasureAngle->setIcon( QgsApplication::getThemeIcon( "/mActionMeasureAngle.png" ) );
Expand Down Expand Up @@ -4244,6 +4247,26 @@ void QgisApp::labeling()
activateDeactivateLayerRelatedActions( layer );
}

void QgisApp::fieldCalculator()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
}

QgsVectorLayer *myLayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
if ( !myLayer )
{
return;
}

QgsFieldCalculator calc( myLayer );
if ( calc.exec() )
{
mMapCanvas->refresh();
}
}

void QgisApp::attributeTable()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
Expand Down Expand Up @@ -7828,6 +7851,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectRadius->setEnabled( false );
mActionIdentify->setEnabled( QSettings().value( "/Map/identifyMode", 0 ).toInt() != 0 );
mActionOpenTable->setEnabled( false );
mActionOpenFieldCalc->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
mActionSaveLayerEdits->setEnabled( false );
Expand Down Expand Up @@ -8057,6 +8081,14 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
}
}

bool canChangeAttributes = dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool canAddAttributes = dprovider->capabilities() & QgsVectorDataProvider::AddAttributes;
bool canDeleteAttributes = dprovider->capabilities() & QgsVectorDataProvider::DeleteAttributes;
bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures;

mActionOpenFieldCalc->setEnabled(( canChangeAttributes || canAddAttributes ) && vlayer->isEditable() );

return;
}
else
Expand All @@ -8066,6 +8098,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionRedo->setEnabled( false );
}



mActionLayerSubsetString->setEnabled( false );
}//end vector layer block
/*************Raster layers*************/
Expand Down Expand Up @@ -8100,6 +8134,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectRadius->setEnabled( false );
mActionZoomActualSize->setEnabled( true );
mActionOpenTable->setEnabled( false );
mActionOpenFieldCalc->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
mActionSaveLayerEdits->setEnabled( false );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
/** @note added in 1.9 */
QAction *actionPasteLayerStyle() { return mActionPasteStyle; }
QAction *actionOpenTable() { return mActionOpenTable; }
QAction *actionOpenFieldCalculator() { return mActionOpenFieldCalc; }
QAction *actionToggleEditing() { return mActionToggleEditing; }
/** @note added in 1.9 */
QAction *actionSaveActiveLayerEdits() { return mActionSaveLayerEdits; }
Expand Down Expand Up @@ -448,6 +449,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! show the attribute table for the currently selected layer
void attributeTable();

void fieldCalculator();

//! mark project dirty
void markDirty();

Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ QAction *QgisAppInterface::actionAddWmsLayer() { return qgis->actionAddWmsLayer(
QAction *QgisAppInterface::actionCopyLayerStyle() { return qgis->actionCopyLayerStyle(); }
QAction *QgisAppInterface::actionPasteLayerStyle() { return qgis->actionPasteLayerStyle(); }
QAction *QgisAppInterface::actionOpenTable() { return qgis->actionOpenTable(); }
QAction *QgisAppInterface::actionOpenFieldCalculator() { return qgis->actionOpenFieldCalculator(); }
QAction *QgisAppInterface::actionToggleEditing() { return qgis->actionToggleEditing(); }
QAction *QgisAppInterface::actionSaveActiveLayerEdits() { return qgis->actionSaveActiveLayerEdits(); }
QAction *QgisAppInterface::actionAllEdits() { return qgis->actionAllEdits(); }
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class QgisAppInterface : public QgisInterface
/** @note added in 1.9 */
virtual QAction *actionPasteLayerStyle();
virtual QAction *actionOpenTable();
virtual QAction *actionOpenFieldCalculator();
virtual QAction *actionToggleEditing();
/** @note added in 1.9 */
virtual QAction *actionSaveActiveLayerEdits();
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class GUI_EXPORT QgisInterface : public QObject
/** @note added in 1.9 */
virtual QAction *actionPasteLayerStyle() = 0;
virtual QAction *actionOpenTable() = 0;
virtual QAction *actionOpenFieldCalculator() = 0;
virtual QAction *actionToggleEditing() = 0;
/** @note added in 1.9 */
virtual QAction *actionSaveActiveLayerEdits() = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/ui/qgisapp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
<addaction name="mActionDeselectAll"/>
<addaction name="mActionSelectByExpression"/>
<addaction name="mActionOpenTable"/>
<addaction name="mActionOpenFieldCalc"/>
<addaction name="mActionMapTips"/>
<addaction name="mActionNewBookmark"/>
<addaction name="mActionShowBookmarks"/>
Expand Down Expand Up @@ -2074,6 +2075,18 @@ Acts on currently active editable layer</string>
<string>Need Support?</string>
</property>
</action>
<action name="mActionOpenFieldCalc">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionCalculateField.png</normaloff>:/images/themes/default/mActionCalculateField.png</iconset>
</property>
<property name="text">
<string>Open Field Calculator</string>
</property>
<property name="toolTip">
<string>Open Field Calculator</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 1bfa7e9

Please sign in to comment.