Navigation Menu

Skip to content

Commit

Permalink
Use a real scale widget in vector save as dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent e0d29e7 commit a3d919d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
17 changes: 11 additions & 6 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -23,10 +23,12 @@
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"
#include "qgsmapcanvas.h"
#include "qgsgui.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QTextCodec>
#include <QSpinBox>

static const int COLUMN_IDX_NAME = 0;
static const int COLUMN_IDX_TYPE = 1;
Expand Down Expand Up @@ -61,7 +63,7 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, i
mSymbologyExportLabel->hide();
mSymbologyExportComboBox->hide();
mScaleLabel->hide();
mScaleSpinBox->hide();
mScaleWidget->hide();
}

mSelectedOnly->setEnabled( layer && layer->selectedFeatureCount() != 0 );
Expand Down Expand Up @@ -814,14 +816,17 @@ int QgsVectorLayerSaveAsDialog::symbologyExport() const
return mSymbologyExportComboBox->currentData().toInt();
}

double QgsVectorLayerSaveAsDialog::scaleDenominator() const
double QgsVectorLayerSaveAsDialog::scale() const
{
return mScaleSpinBox->value();
return mScaleWidget->scale();
}

void QgsVectorLayerSaveAsDialog::setCanvasExtent( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs )
void QgsVectorLayerSaveAsDialog::setMapCanvas( QgsMapCanvas *canvas )
{
mExtentGroupBox->setCurrentExtent( canvasExtent, canvasCrs );
mMapCanvas = canvas;
mScaleWidget->setMapCanvas( canvas );
mScaleWidget->setShowCurrentScaleButton( true );
mExtentGroupBox->setCurrentExtent( canvas->mapSettings().visibleExtent(), canvas->mapSettings().destinationCrs() );
}

bool QgsVectorLayerSaveAsDialog::hasFilterExtent() const
Expand Down Expand Up @@ -889,7 +894,7 @@ void QgsVectorLayerSaveAsDialog::on_mSymbologyExportComboBox_currentIndexChanged
{
scaleEnabled = false;
}
mScaleSpinBox->setEnabled( scaleEnabled );
mScaleWidget->setEnabled( scaleEnabled );
mScaleLabel->setEnabled( scaleEnabled );
}

Expand Down
14 changes: 11 additions & 3 deletions src/app/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -63,10 +63,17 @@ class APP_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
1: Feature symbology
2: Symbol level symbology*/
int symbologyExport() const;
double scaleDenominator() const;

//! setup canvas extent - for the use in extent group box
void setCanvasExtent( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs );
/**
* Returns the specified map scale.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
double scale() const;

/**
* Sets a map \a canvas to associate with the dialog.
*/
void setMapCanvas( QgsMapCanvas *canvas );

bool hasFilterExtent() const;
QgsRectangle filterExtent() const;
Expand Down Expand Up @@ -130,6 +137,7 @@ class APP_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
QgsRectangle mLayerExtent;
QgsCoordinateReferenceSystem mLayerCrs;
QgsVectorLayer *mLayer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
bool mAttributeTableItemChangedSlotEnabled;
bool mReplaceRawFieldValuesStateChangedSlotEnabled;
QgsVectorFileWriter::ActionOnExistingFile mActionOnExistingFile;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -6776,7 +6776,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt

QgsVectorLayerSaveAsDialog *dialog = new QgsVectorLayerSaveAsDialog( vlayer, options, this );

dialog->setCanvasExtent( mMapCanvas->mapSettings().visibleExtent(), mMapCanvas->mapSettings().destinationCrs() );
dialog->setMapCanvas( mMapCanvas );
dialog->setIncludeZ( QgsWkbTypes::hasZ( vlayer->wkbType() ) );

if ( dialog->exec() == QDialog::Accepted )
Expand Down Expand Up @@ -6835,7 +6835,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
options.layerOptions = dialog->layerOptions();
options.skipAttributeCreation = dialog->selectedAttributes().isEmpty();
options.symbologyExport = static_cast< QgsVectorFileWriter::SymbologyExport >( dialog->symbologyExport() );
options.symbologyScale = dialog->scaleDenominator();
options.symbologyScale = dialog->scale();
if ( dialog->hasFilterExtent() )
options.filterExtent = filterExtent;
options.overrideGeometryType = autoGeometryType ? QgsWkbTypes::Unknown : forcedGeometryType;
Expand Down
33 changes: 16 additions & 17 deletions src/ui/qgsvectorlayersaveasdialogbase.ui
Expand Up @@ -106,9 +106,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-303</y>
<width>557</width>
<height>922</height>
<height>1004</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -235,15 +235,9 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="mScaleSpinBox">
<property name="prefix">
<string>1:</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="value">
<number>50000</number>
<widget class="QgsScaleWidget" name="mScaleWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -469,6 +463,11 @@
<header>qgsextentgroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScaleWidget</class>
<extends>QWidget</extends>
<header>qgsscalewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mFormatComboBox</tabstop>
Expand All @@ -482,15 +481,15 @@
<tabstop>mSelectAllAttributes</tabstop>
<tabstop>mDeselectAllAttributes</tabstop>
<tabstop>mSymbologyExportComboBox</tabstop>
<tabstop>mScaleSpinBox</tabstop>
<tabstop>mGeometryGroupBox</tabstop>
<tabstop>mScaleWidget</tabstop>
<tabstop>mGeometryTypeComboBox</tabstop>
<tabstop>mForceMultiCheckBox</tabstop>
<tabstop>mIncludeZCheckBox</tabstop>
<tabstop>mExtentGroupBox</tabstop>
<tabstop>mDatasourceOptionsGroupBox</tabstop>
<tabstop>mLayerOptionsGroupBox</tabstop>
<tabstop>mOgrOptionsGroupBox</tabstop>
<tabstop>mAddToCanvas</tabstop>
<tabstop>mAttributeTable</tabstop>
<tabstop>mReplaceRawFieldValues</tabstop>
<tabstop>mOgrDatasourceOptions</tabstop>
<tabstop>mOgrLayerOptions</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down

0 comments on commit a3d919d

Please sign in to comment.