Skip to content

Commit e4b6f30

Browse files
author
mhugent
committedNov 1, 2007

20 files changed

+722
-390
lines changed
 

‎src/plugins/georeferencer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SET (GEOREF_SRCS
99
qgsimagewarper.cpp
1010
qgsleastsquares.cpp
1111
qgspointdialog.cpp
12+
qgsgeorefdescriptiondialog.cpp
1213
qgsgeorefwarpoptionsdialog.cpp
1314
mapcoordsdialog.cpp
1415
)
@@ -17,6 +18,7 @@ SET (GEOREF_UIS
1718
pluginguibase.ui
1819
qgspointdialogbase.ui
1920
mapcoordsdialogbase.ui
21+
qgsgeorefdescriptiondialogbase.ui
2022
qgsgeorefwarpoptionsdialogbase.ui
2123
)
2224

‎src/plugins/georeferencer/mapcoordsdialog.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#include <QValidator>
1617
#include <mapcoordsdialog.h>
1718

@@ -34,7 +35,8 @@ MapCoordsDialog::MapCoordsDialog(const QgsPoint& pixelCoords, QgsMapCanvas* qgis
3435

3536
mToolEmitPoint = new QgsMapToolEmitPoint(qgisCanvas);
3637
mToolEmitPoint->setButton(btnPointFromCanvas);
37-
connect(mToolEmitPoint, SIGNAL(gotPoint(QgsPoint&,Qt::MouseButton)), this, SLOT(setXY(QgsPoint&)));
38+
connect((QgsMapToolEmitPoint*)mToolEmitPoint, SIGNAL(gotPoint(QgsPoint&,Qt::MouseButton)),
39+
this, SLOT(setXY(QgsPoint&)));
3840

3941
connect(leXCoord, SIGNAL(textChanged(const QString&)), this, SLOT(updateOK()));
4042
connect(leYCoord, SIGNAL(textChanged(const QString&)), this, SLOT(updateOK()));
@@ -79,3 +81,4 @@ void MapCoordsDialog::on_btnPointFromCanvas_clicked()
7981
mPrevMapTool = mQgisCanvas->mapTool();
8082
mQgisCanvas->setMapTool(mToolEmitPoint);
8183
}
84+

‎src/plugins/georeferencer/plugin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
7878
* @param theQGisInterface - Pointer to the QGIS interface object
7979
*/
8080
QgsGeorefPlugin::QgsGeorefPlugin(QgisInterface * theQgisInterface):
81-
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
81+
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
8282
mQGisIface(theQgisInterface)
8383
{
8484
}
@@ -113,8 +113,9 @@ void QgsGeorefPlugin::help()
113113
// Slot called when the buffer menu item is activated
114114
void QgsGeorefPlugin::run()
115115
{
116-
QgsGeorefPluginGui *myPluginGui=new QgsGeorefPluginGui(mQGisIface, mQGisIface->getMainWindow());
116+
QgsGeorefPluginGui *myPluginGui=new QgsGeorefPluginGui(mQGisIface, QgsGeorefPluginGui::findMainWindow());
117117
myPluginGui->show();
118+
myPluginGui->setFocus();
118119
}
119120

120121
// Unload the plugin by cleaning up the GUI

‎src/plugins/georeferencer/plugin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ class QgsGeorefPlugin:public QObject, public QgisPlugin
6868
//////////////////////////////////////////////////////////////////////
6969

7070
/**
71-
* Constructor for a plugin. The QgisInterface pointer is passed by
71+
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
7272
* QGIS when it attempts to instantiate the plugin.
73-
* @param Pointer to the QgisInterface object.
73+
* @param Pointer to the QgisApp object
74+
* @param Pointer to the QgisIface object.
7475
*/
7576
QgsGeorefPlugin(QgisInterface * );
7677
//! Destructor

‎src/plugins/georeferencer/plugingui.cpp

Lines changed: 169 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
* (at your option) any later version. *
1111
***************************************************************************/
1212
#include "plugingui.h"
13+
#include "qgsgeorefdescriptiondialog.h"
1314
#include "qgsleastsquares.h"
1415
#include "qgspointdialog.h"
1516
#include "qgsrasterlayer.h"
1617
#include "qgsmaplayerregistry.h"
1718
#include "qgsproject.h"
1819

1920
//qt includes
21+
#include <QApplication>
22+
#include <QDesktopWidget>
2023
#include <QFileDialog>
2124
#include <QLineEdit>
2225
#include <QMessageBox>
@@ -32,14 +35,31 @@ QgsGeorefPluginGui::QgsGeorefPluginGui() : QgsGeorefPluginGuiBase()
3235

3336
QgsGeorefPluginGui::QgsGeorefPluginGui(QgisInterface* theQgisInterface,
3437
QWidget* parent, Qt::WFlags fl)
35-
: QDialog(parent, fl), mIface(theQgisInterface)
38+
: QDialog(parent, fl), mIface(theQgisInterface), mPluginWindowsArranged(false)
3639
{
3740
setupUi(this);
41+
setAttribute(Qt::WA_DeleteOnClose);
42+
mPointDialog = new QgsPointDialog(mIface, parent);
43+
//move point dialog to the left of the screen so that both windows are visible
44+
mPointDialog->move(0, mPointDialog->pos().y());
45+
mPointDialog->show();
3846
}
3947

4048

4149
QgsGeorefPluginGui::~QgsGeorefPluginGui()
4250
{
51+
delete mPointDialog;
52+
53+
//restore size of qgis main window if arrange button was used
54+
if(mPluginWindowsArranged)
55+
{
56+
QWidget* mainWindow = QgsGeorefPluginGui::findMainWindow();
57+
if(mainWindow)
58+
{
59+
mainWindow->resize(origSize);
60+
mainWindow->move(origPos);
61+
}
62+
}
4363
}
4464

4565

@@ -48,6 +68,12 @@ void QgsGeorefPluginGui::on_pbnClose_clicked()
4868
close(1);
4969
}
5070

71+
void QgsGeorefPluginGui::on_pbnDescription_clicked()
72+
{
73+
QgsGeorefDescriptionDialog d(0);
74+
d.exec();
75+
}
76+
5177

5278
void QgsGeorefPluginGui::on_pbnSelectRaster_clicked() {
5379
QSettings settings;
@@ -59,20 +85,13 @@ void QgsGeorefPluginGui::on_pbnSelectRaster_clicked() {
5985
tr("Choose a raster file"),
6086
dir,
6187
tr("Raster files (*.*)"));
62-
leSelectRaster->setText(filename);
63-
}
64-
6588

66-
void QgsGeorefPluginGui::on_pbnEnterWorldCoords_clicked() {
67-
68-
// Is there a filename
69-
if (leSelectRaster->text().isEmpty())
70-
{
71-
QMessageBox::critical(this, tr("Error"),
72-
tr("You need to specify a file to georeference first."));
89+
if(filename.isNull())
90+
{
91+
return;
92+
}
93+
leSelectRaster->setText(filename);
7394

74-
return;
75-
}
7695
// do we think that this is a valid raster?
7796
if (!QgsRasterLayer::isValidRasterFileName(leSelectRaster->text())) {
7897
QMessageBox::critical(this, tr("Error"),
@@ -94,26 +113,154 @@ void QgsGeorefPluginGui::on_pbnEnterWorldCoords_clicked() {
94113
QString worldfile;
95114
if (point != -1 && point != raster.length() - 1) {
96115
worldfile = raster.left(point + 1);
97-
worldfile += raster.at(point + 1);
98-
worldfile += raster.at(raster.length() - 1);
99-
worldfile += 'w';
116+
worldfile += ("wld");
100117
}
101118

102119
// check if there already is a world file
103120
if (!worldfile.isEmpty()) {
104121
if (QFile::exists(worldfile)) {
105-
QMessageBox::StandardButton r = QMessageBox::question(this, tr("World file exists"),
122+
int r = QMessageBox::question(this, tr("World file exists"),
106123
tr("<p>The selected file already seems to have a ")+
107124
tr("world file! Do you want to replace it with the ")+
108-
tr("new world file?</p>"),
109-
QMessageBox::Ok | QMessageBox::Cancel);
110-
if (r == QMessageBox::Cancel)
125+
tr("new world file?</p>"),
126+
QMessageBox::Yes|QMessageBox::Default,
127+
QMessageBox::No|QMessageBox::Escape);
128+
if (r == QMessageBox::No)
111129
return;
112130
else
113131
QFile::remove(worldfile);
114132
}
115133
}
116134

117-
QgsPointDialog* dlg = new QgsPointDialog(raster, mIface, this);
118-
dlg->show();
135+
// XXX This is horrible, but it works and I'm tired / ll
136+
{
137+
QSettings settings;
138+
QgsProject* prj = QgsProject::instance();
139+
mProjBehaviour = settings.readEntry("/Projections/defaultBehaviour");
140+
mProjectSRS = prj->readEntry("SpatialRefSys", "/ProjectSRSProj4String");
141+
mProjectSRSID = prj->readNumEntry("SpatialRefSys", "/ProjectSRSID");
142+
143+
settings.writeEntry("/Projections/defaultBehaviour", "useProject");
144+
prj->writeEntry("SpatialRefSys", "/ProjectSRSProj4String", GEOPROJ4);
145+
prj->writeEntry("SpatialRefSys", "/ProjectSRSID", int(GEOSRS_ID));
146+
147+
settings.writeEntry("/Projections/defaultBehaviour", mProjBehaviour);
148+
prj->writeEntry("SpatialRefSys", "/ProjectSRSProj4String", mProjectSRS);
149+
prj->writeEntry("SpatialRefSys", "/ProjectSRSID", mProjectSRSID);
150+
}
151+
152+
mPointDialog->openImageFile(filename);
153+
mPointDialog->show();
154+
}
155+
156+
157+
158+
void QgsGeorefPluginGui::on_mArrangeWindowsButton_clicked()
159+
{
160+
if(mPointDialog && mIface)
161+
{
162+
QWidget* mainWindow = QgsGeorefPluginGui::findMainWindow();
163+
if(!mainWindow)
164+
{
165+
return;
166+
}
167+
168+
int width, height; //width and height of screen
169+
170+
//store initial size and position of qgis window
171+
mPluginWindowsArranged = true;
172+
origSize = mainWindow->size();
173+
origPos = mainWindow->pos();
174+
175+
176+
//qt distinguishes between geometry with and without window frame
177+
int widthIncrMainWindow, heightIncrMainWindow;
178+
int widthIncrPointDialog, heightIncrPointDialog;
179+
int widthIncrThis, heightIncrThis;
180+
181+
//read the desktop geometry
182+
QDesktopWidget* desktop = QApplication::desktop();
183+
QRect screenGeometry = desktop->availableGeometry();
184+
width = screenGeometry.width();
185+
height = screenGeometry.height();
186+
187+
int leftRightBorder; //border between plugin/point dialogs on the left and qgis main window on the right
188+
int pluginPointDialogBorder; //border on y-axis between plugin dialog and point dialog
189+
190+
191+
leftRightBorder = width/3;
192+
pluginPointDialogBorder = height/5;
193+
194+
//consider minimum heights of plugin dialog and mPointDialog
195+
int minPluginDialogHeight = minimumHeight() + (frameSize().height() - this->height());
196+
int minPointDialogHeight = mPointDialog->minimumHeight() + \
197+
(mPointDialog->frameSize().height() - mPointDialog->height());
198+
199+
if((height - pluginPointDialogBorder) < minPointDialogHeight)
200+
{
201+
pluginPointDialogBorder = (height - minPointDialogHeight);
202+
}
203+
if(pluginPointDialogBorder < minPluginDialogHeight)
204+
{
205+
pluginPointDialogBorder = minPluginDialogHeight;
206+
}
207+
208+
//consider minimum widths of plugin/point dialogs and qgis main window
209+
int minPluginDialogWidth = minimumWidth() + (frameSize().width() - this->width());
210+
int minPointDialogWidth = mPointDialog->minimumWidth() + \
211+
(mPointDialog->frameSize().width() - mPointDialog->width());
212+
int minMainWindowWidth = mainWindow->minimumWidth() + \
213+
(mainWindow->frameSize().width() - mainWindow->width());
214+
215+
if(leftRightBorder < minPointDialogWidth)
216+
{
217+
leftRightBorder = minPointDialogWidth;
218+
}
219+
if(leftRightBorder < minPluginDialogWidth)
220+
{
221+
leftRightBorder = minPluginDialogWidth;
222+
}
223+
if((width - leftRightBorder) < minMainWindowWidth)
224+
{
225+
leftRightBorder = width - minMainWindowWidth;
226+
}
227+
228+
//place main window
229+
widthIncrMainWindow = (width -leftRightBorder) - mainWindow->frameSize().width();
230+
heightIncrMainWindow = height - mainWindow->frameSize().height();
231+
mainWindow->setEnabled(false); //avoid getting two resize events for the main canvas
232+
mainWindow->resize(mainWindow->width() + widthIncrMainWindow, mainWindow->height() + heightIncrMainWindow);
233+
mainWindow->move(leftRightBorder, 0);
234+
mainWindow->setEnabled(true);
235+
236+
//place point dialog
237+
widthIncrPointDialog = leftRightBorder - mPointDialog->frameSize().width();
238+
heightIncrPointDialog = height - pluginPointDialogBorder - mPointDialog->frameSize().height();
239+
mPointDialog->resize(mPointDialog->width() + widthIncrPointDialog, mPointDialog->height() + heightIncrPointDialog);
240+
mPointDialog->move(0, pluginPointDialogBorder);
241+
242+
//place this dialog
243+
widthIncrThis = leftRightBorder - frameSize().width();
244+
heightIncrThis = pluginPointDialogBorder - frameSize().height();
245+
resize(this->width() + widthIncrThis, this->height() + heightIncrThis);
246+
move(0, 0);
247+
}
248+
}
249+
250+
251+
QWidget* QgsGeorefPluginGui::findMainWindow()
252+
{
253+
QWidget* result = 0;
254+
255+
QWidgetList topLevelWidgets = qApp->topLevelWidgets();
256+
QWidgetList::iterator it = topLevelWidgets.begin();
257+
for(; it != topLevelWidgets.end(); ++it)
258+
{
259+
if((*it)->objectName() == "QgisApp")
260+
{
261+
result = *it;
262+
break;
263+
}
264+
}
265+
return result;
119266
}

‎src/plugins/georeferencer/plugingui.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QDialog>
1717

1818
class QgisInterface;
19+
class QgsPointDialog;
1920

2021
/**
2122
@author Tim Sutton
@@ -27,18 +28,28 @@ Q_OBJECT
2728
QgsGeorefPluginGui();
2829
QgsGeorefPluginGui(QgisInterface* theQgisInterface, QWidget* parent = 0, Qt::WFlags fl = 0);
2930
~QgsGeorefPluginGui();
31+
32+
/**Finds the qgis main window
33+
@return window pointer or 0 in case or error*/
34+
static QWidget* findMainWindow();
3035

3136
public slots:
3237
void on_pbnClose_clicked();
33-
void on_pbnEnterWorldCoords_clicked();
38+
void on_pbnDescription_clicked();
3439
void on_pbnSelectRaster_clicked();
40+
void on_mArrangeWindowsButton_clicked();
3541

3642
private:
3743

3844
QString mProjBehaviour, mProjectSRS;
3945
int mProjectSRSID;
4046
QgisInterface* mIface;
41-
47+
/**dialog to enter reference point*/
48+
QgsPointDialog* mPointDialog;
49+
/**Flag if plugin windows have been arranged with button*/
50+
bool mPluginWindowsArranged;
51+
QSize origSize;
52+
QPoint origPos;
4253
};
4354

4455
#endif

‎src/plugins/georeferencer/pluginguibase.ui

Lines changed: 42 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<rect>
66
<x>0</x>
77
<y>0</y>
8-
<width>542</width>
9-
<height>258</height>
8+
<width>424</width>
9+
<height>155</height>
1010
</rect>
1111
</property>
1212
<property name="windowTitle" >
@@ -22,44 +22,62 @@
2222
<property name="spacing" >
2323
<number>6</number>
2424
</property>
25-
<item row="1" column="2" >
26-
<widget class="QLabel" name="textLabel1" >
25+
<item row="1" column="1" colspan="2" >
26+
<widget class="QPushButton" name="mArrangeWindowsButton" >
2727
<property name="text" >
28-
<string>Raster file:</string>
28+
<string>Arrange plugin windows</string>
2929
</property>
3030
</widget>
3131
</item>
32-
<item row="0" column="2" colspan="3" >
33-
<widget class="QTextEdit" name="textEdit" >
34-
<property name="html" >
35-
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:11pt; font-weight:600;">Description&lt;/span>&lt;/p>&lt;p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This plugin can generate world files for rasters. You select points on the raster and give their world coordinates, and the plugin will compute the world file parameters. The more coordinates you can provide the better the result will be.&lt;/p>&lt;/body>&lt;/html></string>
32+
<item row="0" column="2" >
33+
<widget class="QPushButton" name="pbnSelectRaster" >
34+
<property name="sizePolicy" >
35+
<sizepolicy>
36+
<hsizetype>0</hsizetype>
37+
<vsizetype>0</vsizetype>
38+
<horstretch>0</horstretch>
39+
<verstretch>0</verstretch>
40+
</sizepolicy>
41+
</property>
42+
<property name="text" >
43+
<string>...</string>
3644
</property>
3745
</widget>
3846
</item>
39-
<item rowspan="3" row="0" column="0" >
40-
<widget class="QLabel" name="pixmapLabel2" >
41-
<property name="maximumSize" >
42-
<size>
43-
<width>150</width>
44-
<height>32767</height>
45-
</size>
46-
</property>
47-
<property name="pixmap" >
48-
<pixmap resource="georeferencer.qrc" >:/georef.png</pixmap>
47+
<item row="0" column="1" >
48+
<widget class="QLineEdit" name="leSelectRaster" >
49+
<property name="sizePolicy" >
50+
<sizepolicy>
51+
<hsizetype>0</hsizetype>
52+
<vsizetype>0</vsizetype>
53+
<horstretch>0</horstretch>
54+
<verstretch>0</verstretch>
55+
</sizepolicy>
4956
</property>
50-
<property name="scaledContents" >
51-
<bool>true</bool>
57+
</widget>
58+
</item>
59+
<item row="0" column="0" >
60+
<widget class="QLabel" name="textLabel1" >
61+
<property name="text" >
62+
<string>Raster file:</string>
5263
</property>
5364
</widget>
5465
</item>
55-
<item row="3" column="0" colspan="5" >
66+
<item row="2" column="0" colspan="3" >
5667
<layout class="QHBoxLayout" >
5768
<property name="margin" >
5869
<number>0</number>
5970
</property>
6071
<property name="spacing" >
6172
<number>6</number>
6273
</property>
74+
<item>
75+
<widget class="QPushButton" name="pbnDescription" >
76+
<property name="text" >
77+
<string>Description...</string>
78+
</property>
79+
</widget>
80+
</item>
6381
<item>
6482
<spacer>
6583
<property name="orientation" >
@@ -70,8 +88,8 @@
7088
</property>
7189
<property name="sizeHint" >
7290
<size>
73-
<width>441</width>
74-
<height>21</height>
91+
<width>141</width>
92+
<height>36</height>
7593
</size>
7694
</property>
7795
</spacer>
@@ -85,69 +103,9 @@
85103
</item>
86104
</layout>
87105
</item>
88-
<item rowspan="3" row="0" column="1" >
89-
<widget class="Line" name="line1" >
90-
<property name="maximumSize" >
91-
<size>
92-
<width>2</width>
93-
<height>32767</height>
94-
</size>
95-
</property>
96-
<property name="frameShape" >
97-
<enum>QFrame::VLine</enum>
98-
</property>
99-
<property name="frameShadow" >
100-
<enum>QFrame::Sunken</enum>
101-
</property>
102-
<property name="orientation" >
103-
<enum>Qt::Vertical</enum>
104-
</property>
105-
</widget>
106-
</item>
107-
<item row="2" column="3" colspan="2" >
108-
<widget class="QPushButton" name="pbnEnterWorldCoords" >
109-
<property name="text" >
110-
<string>Enter world coordinates</string>
111-
</property>
112-
</widget>
113-
</item>
114-
<item row="1" column="4" >
115-
<widget class="QPushButton" name="pbnSelectRaster" >
116-
<property name="sizePolicy" >
117-
<sizepolicy>
118-
<hsizetype>0</hsizetype>
119-
<vsizetype>0</vsizetype>
120-
<horstretch>0</horstretch>
121-
<verstretch>0</verstretch>
122-
</sizepolicy>
123-
</property>
124-
<property name="text" >
125-
<string>Browse...</string>
126-
</property>
127-
</widget>
128-
</item>
129-
<item row="1" column="3" >
130-
<widget class="QgsFileDropEdit" name="leSelectRaster" >
131-
<property name="sizePolicy" >
132-
<sizepolicy>
133-
<hsizetype>7</hsizetype>
134-
<vsizetype>0</vsizetype>
135-
<horstretch>0</horstretch>
136-
<verstretch>0</verstretch>
137-
</sizepolicy>
138-
</property>
139-
</widget>
140-
</item>
141106
</layout>
142107
</widget>
143108
<layoutdefault spacing="6" margin="11" />
144-
<customwidgets>
145-
<customwidget>
146-
<class>QgsFileDropEdit</class>
147-
<extends>QLineEdit</extends>
148-
<header>qgsfiledropedit.h</header>
149-
</customwidget>
150-
</customwidgets>
151109
<resources>
152110
<include location="georeferencer.qrc" />
153111
</resources>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/***************************************************************************
2+
qgsgeorefdescriptiondialog.cpp - description
3+
------------------------------
4+
begin : Oct 2007
5+
copyright : (C) 2007 by Marco Hugentobler
6+
email : marco dot hugentobler at karto dot baug dot ethz dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsgeorefdescriptiondialog.h"
19+
20+
QgsGeorefDescriptionDialog::QgsGeorefDescriptionDialog(QWidget* parent): QDialog(parent)
21+
{
22+
setupUi(this);
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/***************************************************************************
2+
qgsgeorefdescriptiondialog.h - description
3+
----------------------------
4+
begin : Oct 2007
5+
copyright : (C) 2007 by Marco Hugentobler
6+
email : marco dot hugentobler at karto dot baug dot ethz dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSGEOREFDESCRIPTIONDIALOG_H
19+
#define QGSGEOREFDESCRIPTIONDIALOG_H
20+
21+
#include "ui_qgsgeorefdescriptiondialogbase.h"
22+
#include <QDialog>
23+
24+
/**Dialog that shows logo and description of the georef plugin*/
25+
class QgsGeorefDescriptionDialog: public QDialog, private Ui::QgsGeorefDescriptionDialogBase
26+
{
27+
public:
28+
QgsGeorefDescriptionDialog(QWidget* parent);
29+
};
30+
31+
#endif
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<ui version="4.0" >
2+
<class>QgsGeorefDescriptionDialogBase</class>
3+
<widget class="QDialog" name="QgsGeorefDescriptionDialogBase" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>416</width>
9+
<height>268</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>Description georeferencer</string>
14+
</property>
15+
<property name="windowIcon" >
16+
<iconset resource="georeferencer.qrc" >:/icon.png</iconset>
17+
</property>
18+
<property name="modal" >
19+
<bool>true</bool>
20+
</property>
21+
<layout class="QGridLayout" >
22+
<property name="margin" >
23+
<number>9</number>
24+
</property>
25+
<property name="spacing" >
26+
<number>6</number>
27+
</property>
28+
<item row="1" column="0" colspan="2" >
29+
<widget class="QDialogButtonBox" name="buttonBox" >
30+
<property name="orientation" >
31+
<enum>Qt::Horizontal</enum>
32+
</property>
33+
<property name="standardButtons" >
34+
<set>QDialogButtonBox::Ok</set>
35+
</property>
36+
</widget>
37+
</item>
38+
<item row="0" column="1" >
39+
<widget class="QTextEdit" name="textEdit" >
40+
<property name="readOnly" >
41+
<bool>true</bool>
42+
</property>
43+
<property name="html" >
44+
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
45+
p, li { white-space: pre-wrap; }
46+
&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:12pt; font-weight:400; font-style:normal; text-decoration:none;">
47+
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:11pt; font-weight:600;">Description&lt;/span>&lt;/p>
48+
&lt;p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:9pt;">This plugin can generate world files for rasters. You select points on the raster and give their world coordinates, and the plugin will compute the world file parameters. The more coordinates you can provide the better the result will be.&lt;/p>&lt;/body>&lt;/html></string>
49+
</property>
50+
</widget>
51+
</item>
52+
<item row="0" column="0" >
53+
<widget class="QLabel" name="label" >
54+
<property name="text" >
55+
<string/>
56+
</property>
57+
<property name="pixmap" >
58+
<pixmap resource="georeferencer.qrc" >:/georef.png</pixmap>
59+
</property>
60+
<property name="scaledContents" >
61+
<bool>true</bool>
62+
</property>
63+
</widget>
64+
</item>
65+
</layout>
66+
</widget>
67+
<resources>
68+
<include location="georeferencer.qrc" />
69+
</resources>
70+
<connections>
71+
<connection>
72+
<sender>buttonBox</sender>
73+
<signal>accepted()</signal>
74+
<receiver>QgsGeorefDescriptionDialogBase</receiver>
75+
<slot>accept()</slot>
76+
<hints>
77+
<hint type="sourcelabel" >
78+
<x>248</x>
79+
<y>254</y>
80+
</hint>
81+
<hint type="destinationlabel" >
82+
<x>157</x>
83+
<y>274</y>
84+
</hint>
85+
</hints>
86+
</connection>
87+
<connection>
88+
<sender>buttonBox</sender>
89+
<signal>rejected()</signal>
90+
<receiver>QgsGeorefDescriptionDialogBase</receiver>
91+
<slot>reject()</slot>
92+
<hints>
93+
<hint type="sourcelabel" >
94+
<x>316</x>
95+
<y>260</y>
96+
</hint>
97+
<hint type="destinationlabel" >
98+
<x>286</x>
99+
<y>274</y>
100+
</hint>
101+
</hints>
102+
</connection>
103+
</connections>
104+
</ui>

‎src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,47 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#include "qgsgeorefwarpoptionsdialog.h"
1617

1718

1819
QgsGeorefWarpOptionsDialog::QgsGeorefWarpOptionsDialog(QWidget* parent)
1920
: QgsGeorefWarpOptionsDialogBase()
2021
{
2122
setupUi(this);
23+
QStringList compressionMethods;
24+
compressionMethods << "NONE";
25+
compressionMethods << "LZW (" + tr("unstable") + ")";
26+
compressionMethods << "PACKBITS (" + tr("unstable") + ")";
27+
compressionMethods << "DEFLATE (" + tr("unstable") + ")";
28+
mCompressionComboBox->addItems(compressionMethods);
2229
}
2330

2431

2532
void QgsGeorefWarpOptionsDialog::
2633
getWarpOptions(QgsImageWarper::ResamplingMethod& resampling,
27-
bool& useZeroForTransparency) {
34+
bool& useZeroForTransparency, QString& compression)
35+
{
2836
resampling = this->resampling;
2937
useZeroForTransparency = this->useZeroAsTransparency;
38+
39+
QString compressionString = mCompressionComboBox->currentText();
40+
if(compressionString.startsWith("NONE"))
41+
{
42+
compression = "NONE";
43+
}
44+
else if(compressionString.startsWith("LZW"))
45+
{
46+
compression = "LZW";
47+
}
48+
else if(compressionString.startsWith("PACKBITS"))
49+
{
50+
compression = "PACKBITS";
51+
}
52+
else if(compressionString.startsWith("DEFLATE"))
53+
{
54+
compression = "DEFLATE";
55+
}
3056
}
3157

3258

‎src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Q_OBJECT
2424

2525
QgsGeorefWarpOptionsDialog(QWidget* parent);
2626
void getWarpOptions(QgsImageWarper::ResamplingMethod& resampling,
27-
bool& useZeroForTransparency);
27+
bool& useZeroForTransparency, QString& compression);
2828

2929
public slots:
3030

‎src/plugins/georeferencer/qgsgeorefwarpoptionsdialogbase.ui

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@
55
<rect>
66
<x>0</x>
77
<y>0</y>
8-
<width>348</width>
9-
<height>103</height>
8+
<width>366</width>
9+
<height>130</height>
1010
</rect>
1111
</property>
1212
<property name="windowTitle" >
1313
<string>Warp options</string>
1414
</property>
1515
<layout class="QGridLayout" >
1616
<property name="margin" >
17-
<number>10</number>
17+
<number>9</number>
1818
</property>
1919
<property name="spacing" >
2020
<number>6</number>
2121
</property>
22+
<item row="1" column="1" colspan="2" >
23+
<widget class="QComboBox" name="mCompressionComboBox" />
24+
</item>
25+
<item row="1" column="0" >
26+
<widget class="QLabel" name="mCompressionLabel" >
27+
<property name="text" >
28+
<string>Compression:</string>
29+
</property>
30+
</widget>
31+
</item>
2232
<item row="0" column="0" >
2333
<widget class="QLabel" name="textLabel1" >
2434
<property name="text" >
@@ -48,23 +58,23 @@
4858
</item>
4959
</widget>
5060
</item>
51-
<item row="2" column="2" >
52-
<widget class="QPushButton" name="pbnOK" >
61+
<item row="2" column="0" colspan="2" >
62+
<widget class="QCheckBox" name="cbxZeroAsTrans" >
5363
<property name="text" >
54-
<string>OK</string>
64+
<string>Use 0 for transparency when needed</string>
5565
</property>
56-
<property name="default" >
57-
<bool>true</bool>
66+
<property name="checked" >
67+
<bool>false</bool>
5868
</property>
5969
</widget>
6070
</item>
61-
<item row="1" column="0" colspan="2" >
62-
<widget class="QCheckBox" name="cbxZeroAsTrans" >
71+
<item row="2" column="2" >
72+
<widget class="QPushButton" name="pbnOK" >
6373
<property name="text" >
64-
<string>Use 0 for transparency when needed</string>
74+
<string>OK</string>
6575
</property>
66-
<property name="checked" >
67-
<bool>false</bool>
76+
<property name="default" >
77+
<bool>true</bool>
6878
</property>
6979
</widget>
7080
</item>

‎src/plugins/georeferencer/qgsimagewarper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#include <cmath>
1617
#include <iostream>
1718

@@ -28,7 +29,7 @@
2829

2930
void QgsImageWarper::warp(const QString& input, const QString& output,
3031
double& xOffset, double& yOffset,
31-
ResamplingMethod resampling, bool useZeroAsTrans) {
32+
ResamplingMethod resampling, bool useZeroAsTrans, const QString& compression) {
3233
// Open input file
3334
GDALAllRegister();
3435
GDALDataset* hSrcDS = static_cast<GDALDataset*>(GDALOpen(QFile::encodeName(input).constData(),
@@ -75,6 +76,7 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
7576
GDALDriver* driver = static_cast<GDALDriver*>(GDALGetDriverByName("GTiff"));
7677
char **papszOptions = NULL;
7778
papszOptions = CSLSetNameValue(papszOptions, "INIT_DEST", "NO_DATA");
79+
papszOptions = CSLSetNameValue(papszOptions, "COMPRESS", compression);
7880
GDALDataset* hDstDS =
7981
driver->Create(QFile::encodeName(output).constData(), newXSize, newYSize,
8082
hSrcDS->GetRasterCount(),

‎src/plugins/georeferencer/qgsimagewarper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************
22
qgsimagewarper.h
33
--------------------------------------
4-
Date : Sun Sep 16 12:03:20 AKDT 2007
4+
Date : Sun Sep 16 12:03:20 AKDT 2007
55
Copyright : (C) 2007 by Gary E. Sherman
66
Email : sherman at mrcc dot com
77
***************************************************************************
@@ -12,6 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#ifndef QGSIMAGEWARPER_H
1617
#define QGSIMAGEWARPER_H
1718

@@ -33,7 +34,7 @@ class QgsImageWarper {
3334

3435
void warp(const QString& input, const QString& output,
3536
double& xOffset, double& yOffset,
36-
ResamplingMethod resampling = Bilinear, bool useZeroAsTrans = true);
37+
ResamplingMethod resampling = Bilinear, bool useZeroAsTrans = true, const QString& compression = "NONE");
3738

3839
private:
3940

‎src/plugins/georeferencer/qgsleastsquares.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#include <cmath>
1617
#include <stdexcept>
17-
#include "qgslogger.h"
18-
#include <gsl/gsl_linalg.h>
1918

19+
#include <gsl/gsl_linalg.h>
2020

2121
#include <QObject>
2222

@@ -35,8 +35,6 @@ void QgsLeastSquares::linear(std::vector<QgsPoint> mapCoords,
3535
double sumPx(0), sumPy(0), sumPx2(0), sumPy2(0), sumPxMx(0), sumPyMy(0),
3636
sumMx(0), sumMy(0);
3737
for (int i = 0; i < n; ++i) {
38-
QgsDebugMsg("Processing point Pixel(" + QString::number(pixelCoords[i].x()) + ":" + QString::number(pixelCoords[i].y()) +
39-
")\n Map(" + QString::number(mapCoords[i].x()) + ":" + QString::number(mapCoords[i].y()) + ")\n");
4038
sumPx += pixelCoords[i].x();
4139
sumPy += pixelCoords[i].y();
4240
sumPx2 += std::pow(pixelCoords[i].x(), 2);
@@ -57,6 +55,7 @@ void QgsLeastSquares::linear(std::vector<QgsPoint> mapCoords,
5755

5856
origin.setX(aX);
5957
origin.setY(aY);
58+
6059
pixelXSize = std::abs(bX);
6160
pixelYSize = std::abs(bY);
6261
}
@@ -165,3 +164,4 @@ void QgsLeastSquares::affine(std::vector<QgsPoint> mapCoords,
165164
gsl_permutation_free(p);
166165

167166
}
167+

‎src/plugins/georeferencer/qgsleastsquares.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#ifndef QGSLEASTSQUARES_H
1617
#define QGSLEASTSQUARES_H
1718

‎src/plugins/georeferencer/qgspointdialog.cpp

Lines changed: 183 additions & 158 deletions
Large diffs are not rendered by default.

‎src/plugins/georeferencer/qgspointdialog.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,27 @@
2525
class QAction;
2626
class QActionGroup;
2727
class QgsGeorefDataPoint;
28-
class QgisInterface;
2928
class QgsMapTool;
29+
class QgisInterface;
3030

3131
class QgsPointDialog : public QDialog, private Ui::QgsPointDialogBase
3232
{
3333
Q_OBJECT
3434
public:
3535
QgsPointDialog(QString layerPath, QgisInterface* theQgisInterface,
3636
QWidget* parent = 0, Qt::WFlags fl = 0);
37+
38+
QgsPointDialog(QgisInterface* theQgisInterface, QWidget* parent = 0, Qt::WFlags fl = 0);
3739
~QgsPointDialog();
3840

41+
/**Opens a new image file in mCanvas*/
42+
void openImageFile(QString layerPath);
3943
void showCoordDialog(QgsPoint& pixelCoords);
4044
void deleteDataPoint(QgsPoint& pixelCoords);
4145

4246
public slots:
4347

4448
void addPoint(const QgsPoint& pixelCoords, const QgsPoint& mapCoords);
45-
void on_pbnCancel_clicked();
4649
void on_pbnGenerateWorldFile_clicked();
4750
void on_pbnGenerateAndLoad_clicked();
4851
void on_pbnSelectWorldFile_clicked();
@@ -58,6 +61,7 @@ public slots:
5861

5962
private:
6063

64+
void initialize();
6165
bool generateWorldFile();
6266
QString guessWorldFileName(const QString& raster);
6367

@@ -85,6 +89,7 @@ public slots:
8589
// std::vector<QString> mAcetateIDs;
8690
std::vector<QgsGeorefDataPoint*> mPoints;
8791
QgisInterface* mIface;
92+
int mAcetateCounter;
8893
};
8994

9095
#endif

‎src/plugins/georeferencer/qgspointdialogbase.ui

Lines changed: 76 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
<ui version="4.0" >
2-
<author></author>
3-
<comment></comment>
4-
<exportmacro></exportmacro>
52
<class>QgsPointDialogBase</class>
63
<widget class="QDialog" name="QgsPointDialogBase" >
74
<property name="geometry" >
85
<rect>
96
<x>0</x>
107
<y>0</y>
11-
<width>703</width>
12-
<height>410</height>
8+
<width>335</width>
9+
<height>433</height>
1310
</rect>
1411
</property>
1512
<property name="windowTitle" >
16-
<string>Georeferencer</string>
13+
<string>Reference points</string>
14+
</property>
15+
<property name="windowIcon" >
16+
<iconset resource="georeferencer.qrc" >:/icon.png</iconset>
17+
</property>
18+
<property name="autoFillBackground" >
19+
<bool>true</bool>
1720
</property>
1821
<layout class="QGridLayout" >
1922
<property name="margin" >
@@ -22,23 +25,58 @@
2225
<property name="spacing" >
2326
<number>6</number>
2427
</property>
25-
<item row="0" column="4" colspan="4" >
26-
<spacer>
27-
<property name="orientation" >
28-
<enum>Qt::Horizontal</enum>
28+
<item row="4" column="3" >
29+
<widget class="QPushButton" name="pbnSelectWorldFile" >
30+
<property name="text" >
31+
<string>...</string>
2932
</property>
30-
<property name="sizeType" >
31-
<enum>QSizePolicy::Expanding</enum>
33+
</widget>
34+
</item>
35+
<item row="3" column="3" >
36+
<widget class="QPushButton" name="pbnSelectModifiedRaster" >
37+
<property name="text" >
38+
<string>...</string>
3239
</property>
33-
<property name="sizeHint" >
34-
<size>
35-
<width>300</width>
36-
<height>20</height>
37-
</size>
40+
</widget>
41+
</item>
42+
<item row="3" column="0" colspan="2" >
43+
<widget class="QLabel" name="lblSelectModifiedRaster" >
44+
<property name="text" >
45+
<string>Modified raster:</string>
3846
</property>
39-
</spacer>
47+
</widget>
4048
</item>
41-
<item row="0" column="2" colspan="2" >
49+
<item row="4" column="0" colspan="2" >
50+
<widget class="QLabel" name="textLabel1" >
51+
<property name="text" >
52+
<string>World file:</string>
53+
</property>
54+
</widget>
55+
</item>
56+
<item row="3" column="2" >
57+
<widget class="QLineEdit" name="leSelectModifiedRaster" />
58+
</item>
59+
<item row="4" column="2" >
60+
<widget class="QLineEdit" name="leSelectWorldFile" />
61+
</item>
62+
<item row="2" column="0" colspan="2" >
63+
<widget class="QLabel" name="textLabel2" >
64+
<property name="text" >
65+
<string>Transform type:</string>
66+
</property>
67+
</widget>
68+
</item>
69+
<item row="2" column="2" colspan="2" >
70+
<widget class="QComboBox" name="cmbTransformType" />
71+
</item>
72+
<item row="5" column="0" >
73+
<widget class="QPushButton" name="pbnGenerateWorldFile" >
74+
<property name="text" >
75+
<string>Create</string>
76+
</property>
77+
</widget>
78+
</item>
79+
<item row="0" column="2" >
4280
<widget class="QFrame" name="frame5" >
4381
<property name="sizePolicy" >
4482
<sizepolicy>
@@ -56,7 +94,7 @@
5694
</property>
5795
<layout class="QHBoxLayout" >
5896
<property name="margin" >
59-
<number>0</number>
97+
<number>11</number>
6098
</property>
6199
<property name="spacing" >
62100
<number>0</number>
@@ -129,7 +167,7 @@
129167
</property>
130168
<layout class="QHBoxLayout" >
131169
<property name="margin" >
132-
<number>0</number>
170+
<number>11</number>
133171
</property>
134172
<property name="spacing" >
135173
<number>0</number>
@@ -225,55 +263,27 @@
225263
</layout>
226264
</widget>
227265
</item>
228-
<item row="2" column="7" >
229-
<widget class="QPushButton" name="pbnSelectModifiedRaster" >
230-
<property name="text" >
231-
<string>Save As...</string>
232-
</property>
233-
</widget>
234-
</item>
235-
<item row="3" column="7" >
236-
<widget class="QPushButton" name="pbnSelectWorldFile" >
237-
<property name="text" >
238-
<string>Save As...</string>
239-
</property>
240-
</widget>
241-
</item>
242-
<item row="4" column="6" colspan="2" >
243-
<widget class="QPushButton" name="pbnGenerateAndLoad" >
244-
<property name="text" >
245-
<string>Generate world file and load layer</string>
266+
<item row="1" column="0" colspan="4" >
267+
<widget class="QFrame" name="canvasFrame" >
268+
<property name="autoFillBackground" >
269+
<bool>false</bool>
246270
</property>
247-
</widget>
248-
</item>
249-
<item row="2" column="5" colspan="2" >
250-
<widget class="QLineEdit" name="leSelectModifiedRaster" />
251-
</item>
252-
<item row="3" column="5" colspan="2" >
253-
<widget class="QLineEdit" name="leSelectWorldFile" />
254-
</item>
255-
<item row="4" column="5" >
256-
<widget class="QPushButton" name="pbnGenerateWorldFile" >
257-
<property name="text" >
258-
<string>Generate world file</string>
271+
<property name="frameShape" >
272+
<enum>QFrame::StyledPanel</enum>
259273
</property>
260-
</widget>
261-
</item>
262-
<item row="2" column="4" >
263-
<widget class="QLabel" name="lblSelectModifiedRaster" >
264-
<property name="text" >
265-
<string>Modified raster:</string>
274+
<property name="frameShadow" >
275+
<enum>QFrame::Raised</enum>
266276
</property>
267277
</widget>
268278
</item>
269-
<item row="3" column="4" >
270-
<widget class="QLabel" name="textLabel1" >
279+
<item row="5" column="1" colspan="3" >
280+
<widget class="QPushButton" name="pbnGenerateAndLoad" >
271281
<property name="text" >
272-
<string>World file:</string>
282+
<string>Create and load layer</string>
273283
</property>
274284
</widget>
275285
</item>
276-
<item row="4" column="3" colspan="2" >
286+
<item row="0" column="3" >
277287
<spacer>
278288
<property name="orientation" >
279289
<enum>Qt::Horizontal</enum>
@@ -283,46 +293,17 @@
283293
</property>
284294
<property name="sizeHint" >
285295
<size>
286-
<width>150</width>
287-
<height>20</height>
296+
<width>41</width>
297+
<height>53</height>
288298
</size>
289299
</property>
290300
</spacer>
291301
</item>
292-
<item row="2" column="1" colspan="3" >
293-
<widget class="QComboBox" name="cmbTransformType" />
294-
</item>
295-
<item row="2" column="0" >
296-
<widget class="QLabel" name="textLabel2" >
297-
<property name="text" >
298-
<string>Transform type:</string>
299-
</property>
300-
</widget>
301-
</item>
302-
<item row="4" column="0" colspan="3" >
303-
<widget class="QPushButton" name="pbnCancel" >
304-
<property name="text" >
305-
<string>Cancel</string>
306-
</property>
307-
</widget>
308-
</item>
309-
<item row="1" column="0" colspan="8" >
310-
<widget class="QFrame" name="canvasFrame" >
311-
<property name="autoFillBackground" >
312-
<bool>true</bool>
313-
</property>
314-
<property name="frameShape" >
315-
<enum>QFrame::StyledPanel</enum>
316-
</property>
317-
<property name="frameShadow" >
318-
<enum>QFrame::Raised</enum>
319-
</property>
320-
</widget>
321-
</item>
322302
</layout>
323303
</widget>
324304
<layoutdefault spacing="6" margin="11" />
325-
<pixmapfunction></pixmapfunction>
326-
<resources/>
305+
<resources>
306+
<include location="georeferencer.qrc" />
307+
</resources>
327308
<connections/>
328309
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.