Skip to content

Commit 6a6b3b4

Browse files
committed
[GRASS] browser import options dialog
1 parent 407f721 commit 6a6b3b4

12 files changed

+658
-109
lines changed

src/core/raster/qgsrasterprojector.cpp

+184-97
Large diffs are not rendered by default.

src/core/raster/qgsrasterprojector.h

+25-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ class QgsPoint;
3838
class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
3939
{
4040
public:
41+
/** Precison defines if each pixel is reprojected or approximate reprojection based
42+
* on an approximation matrix of reprojected points is used. */
43+
enum Precision
44+
{
45+
Approximate = 0, //!< Approximate (default), fast but possibly inaccurate
46+
Exact = 1, //!< Exact, precise but slow
47+
};
48+
4149
/** \brief QgsRasterProjector implements approximate projection support for
4250
* it calculates grid of points in source CRS for target CRS + extent
4351
* which are used to calculate affine transformation matrices.
@@ -101,12 +109,21 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
101109
mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
102110
}
103111

112+
Precision precision() const { return mPrecision; }
113+
void setPrecision( Precision precision ) { mPrecision = precision; }
114+
// Translated precision mode, for use in ComboBox etc.
115+
static QString precisionLabel( Precision precision );
116+
104117
QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;
105118

106-
/** Calculate destination extent and size from source extent and size
107-
*/
119+
/** Calculate destination extent and size from source extent and size */
108120
bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
109-
QgsRectangle& theDestExtent, int& theDestXSize, int& theDesYSize );
121+
QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
122+
123+
/** Calculate destination extent and size from source extent and size */
124+
static bool extentSize( const QgsCoordinateTransform* ct,
125+
const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
126+
QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );
110127

111128
private:
112129
/** get source extent */
@@ -265,7 +282,11 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
265282
double mMaxSrcXRes;
266283
double mMaxSrcYRes;
267284

268-
/** Use approximation */
285+
/** Requested precision */
286+
Precision mPrecision;
287+
288+
/** Use approximation (requested precision is Approximate and it is possible to calculate
289+
* an approximation matrix with a sufficient precision) */
269290
bool mApproximate;
270291
};
271292

src/providers/grass/6/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
INCLUDE_DIRECTORIES(${GRASS_INCLUDE_DIR})
1+
INCLUDE_DIRECTORIES(
2+
${GRASS_INCLUDE_DIR}
3+
${CMAKE_CURRENT_BINARY_DIR}
4+
)
25
ADD_GRASSLIB(6)

src/providers/grass/7/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
INCLUDE_DIRECTORIES(${GRASS_INCLUDE_DIR7})
1+
INCLUDE_DIRECTORIES(
2+
${GRASS_INCLUDE_DIR7}
3+
${CMAKE_CURRENT_BINARY_DIR}
4+
)
25
ADD_GRASSLIB(7)

src/providers/grass/CMakeLists.txt

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,29 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
2222
SET(GRASS_MAJOR_VERSION ${GRASS_MAJOR_VERSION${GRASS_BUILD_VERSION}})
2323
SET(GRASS_MINOR_VERSION ${GRASS_MINOR_VERSION${GRASS_BUILD_VERSION}})
2424

25-
QT4_WRAP_CPP(GRASS_LIBRARY_MOC_SRCS ../qgsgrassprovider.h ../qgsgrassimport.h)
25+
QT4_WRAP_CPP(GRASS_LIBRARY_MOC_SRCS
26+
../qgsgrassprovider.h
27+
../qgsgrassimport.h
28+
../qgsgrassoptions.h
29+
)
30+
31+
SET (GRASS_LIBRARY_SRCS
32+
../qgsgrass.cpp
33+
../qgsgrassfeatureiterator.cpp
34+
../qgsgrassprovider.cpp
35+
../qgsgrassimport.cpp
36+
../qgsgrassoptions.cpp
37+
)
2638

27-
ADD_LIBRARY(qgisgrass${GRASS_BUILD_VERSION} SHARED ../qgsgrass.cpp ../qgsgrassfeatureiterator.cpp ../qgsgrassprovider.cpp ../qgsgrassimport.cpp ${GRASS_LIBRARY_MOC_SRCS})
39+
QT4_WRAP_UI (GRASS_LIBRARY_UIS_H
40+
../qgsgrassoptionsbase.ui
41+
)
42+
43+
ADD_LIBRARY(qgisgrass${GRASS_BUILD_VERSION} SHARED
44+
${GRASS_LIBRARY_SRCS}
45+
${GRASS_LIBRARY_MOC_SRCS}
46+
${GRASS_LIBRARY_UIS_H}
47+
)
2848

2949
SET_TARGET_PROPERTIES(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES
3050
CLEAN_DIRECT_OUTPUT 1
@@ -53,6 +73,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
5373
IF (GRASS_MAJOR_VERSION LESS 7 )
5474
SET(GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}
5575
qgis_core
76+
qgis_gui
5677
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
5778
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vect}
5879
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
@@ -62,6 +83,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
6283
ELSE (GRASS_MAJOR_VERSION LESS 7 )
6384
SET(GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}
6485
qgis_core
86+
qgis_gui
6587
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
6688
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vector}
6789
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}

src/providers/grass/qgsgrass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ QRegExp GRASS_LIB_EXPORT QgsGrassObject::newNameRegExp( Type type )
201201
}
202202
else
203203
{
204-
rx.setPattern( "[A-Za-z0-9_.]+" );
204+
rx.setPattern( "[A-Za-z0-9_\\-][A-Za-z0-9_\\-.]+" );
205205
}
206206
return rx;
207207
}

src/providers/grass/qgsgrassimport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ bool QgsGrassRasterImport::import()
214214
{
215215
if ( !block->convert( qgis_out_type ) )
216216
{
217-
setError( "cannot convert data type" );
217+
setError( tr( "Cannot convert block (%1) to data type %2" ).arg( block->toString() ).arg( qgis_out_type ) );
218218
delete block;
219219
return false;
220220
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************
2+
qgsgrassoptions.cpp
3+
-------------------
4+
begin : May, 2015
5+
copyright : (C) 2015 Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#include "qgsrasterprojector.h"
17+
18+
#include "qgsgrassoptions.h"
19+
#include "ui_qgsgrassoptionsbase.h"
20+
21+
QgsGrassOptions::QgsGrassOptions(QWidget *parent)
22+
: QDialog(parent)
23+
, QgsGrassOptionsBase()
24+
, mImportSettingsPath("/GRASS/browser/import")
25+
{
26+
setupUi(this);
27+
28+
connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );
29+
30+
QSettings settings;
31+
32+
QgsRasterProjector::Precision crsTransform = (QgsRasterProjector::Precision) settings.value( mImportSettingsPath + "/crsTransform", QgsRasterProjector::Approximate).toInt();
33+
mCrsTransformationComboBox->addItem ( QgsRasterProjector::precisionLabel(QgsRasterProjector::Approximate), QgsRasterProjector::Approximate);
34+
mCrsTransformationComboBox->addItem ( QgsRasterProjector::precisionLabel(QgsRasterProjector::Exact), QgsRasterProjector::Exact);
35+
mCrsTransformationComboBox->setCurrentIndex ( mCrsTransformationComboBox->findData(crsTransform) );
36+
37+
mImportExternalCheckBox->setChecked( settings.value(mImportSettingsPath + "/external", true).toBool() );
38+
}
39+
40+
QgsGrassOptions::~QgsGrassOptions()
41+
{
42+
}
43+
44+
void QgsGrassOptions::saveOptions()
45+
{
46+
QSettings settings;
47+
48+
settings.setValue( mImportSettingsPath + "/crsTransform",
49+
mCrsTransformationComboBox->itemData( mCrsTransformationComboBox->currentIndex() ).toInt() );
50+
51+
settings.setValue( mImportSettingsPath + "/external", mImportExternalCheckBox->isChecked() );
52+
}

src/providers/grass/qgsgrassoptions.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************
2+
qgsgrassoptions.h
3+
-------------------
4+
begin : May, 2015
5+
copyright : (C) 2015 Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#ifndef QGSGRASSOPTIONS_H
17+
#define QGSGRASSOPTIONS_H
18+
19+
#include <QDialog>
20+
21+
#include "ui_qgsgrassoptionsbase.h"
22+
23+
class GRASS_LIB_EXPORT QgsGrassOptions : public QDialog, private Ui::QgsGrassOptionsBase
24+
{
25+
Q_OBJECT
26+
27+
public:
28+
explicit QgsGrassOptions(QWidget *parent = 0);
29+
~QgsGrassOptions();
30+
31+
private slots:
32+
void saveOptions();
33+
34+
private:
35+
QString mImportSettingsPath;
36+
37+
};
38+
39+
#endif // QGSGRASSOPTIONS_H

0 commit comments

Comments
 (0)