Skip to content

Commit

Permalink
Added usability enhancements for georef plugin to trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@7309 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 1, 2007
1 parent 80f090a commit 19f2bb3
Show file tree
Hide file tree
Showing 20 changed files with 722 additions and 390 deletions.
2 changes: 2 additions & 0 deletions src/plugins/georeferencer/CMakeLists.txt
Expand Up @@ -9,6 +9,7 @@ SET (GEOREF_SRCS
qgsimagewarper.cpp
qgsleastsquares.cpp
qgspointdialog.cpp
qgsgeorefdescriptiondialog.cpp
qgsgeorefwarpoptionsdialog.cpp
mapcoordsdialog.cpp
)
Expand All @@ -17,6 +18,7 @@ SET (GEOREF_UIS
pluginguibase.ui
qgspointdialogbase.ui
mapcoordsdialogbase.ui
qgsgeorefdescriptiondialogbase.ui
qgsgeorefwarpoptionsdialogbase.ui
)

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/georeferencer/mapcoordsdialog.cpp
Expand Up @@ -12,6 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/

#include <QValidator>
#include <mapcoordsdialog.h>

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

mToolEmitPoint = new QgsMapToolEmitPoint(qgisCanvas);
mToolEmitPoint->setButton(btnPointFromCanvas);
connect(mToolEmitPoint, SIGNAL(gotPoint(QgsPoint&,Qt::MouseButton)), this, SLOT(setXY(QgsPoint&)));
connect((QgsMapToolEmitPoint*)mToolEmitPoint, SIGNAL(gotPoint(QgsPoint&,Qt::MouseButton)),
this, SLOT(setXY(QgsPoint&)));

connect(leXCoord, SIGNAL(textChanged(const QString&)), this, SLOT(updateOK()));
connect(leYCoord, SIGNAL(textChanged(const QString&)), this, SLOT(updateOK()));
Expand Down Expand Up @@ -79,3 +81,4 @@ void MapCoordsDialog::on_btnPointFromCanvas_clicked()
mPrevMapTool = mQgisCanvas->mapTool();
mQgisCanvas->setMapTool(mToolEmitPoint);
}

5 changes: 3 additions & 2 deletions src/plugins/georeferencer/plugin.cpp
Expand Up @@ -78,7 +78,7 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
* @param theQGisInterface - Pointer to the QGIS interface object
*/
QgsGeorefPlugin::QgsGeorefPlugin(QgisInterface * theQgisInterface):
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
mQGisIface(theQgisInterface)
{
}
Expand Down Expand Up @@ -113,8 +113,9 @@ void QgsGeorefPlugin::help()
// Slot called when the buffer menu item is activated
void QgsGeorefPlugin::run()
{
QgsGeorefPluginGui *myPluginGui=new QgsGeorefPluginGui(mQGisIface, mQGisIface->getMainWindow());
QgsGeorefPluginGui *myPluginGui=new QgsGeorefPluginGui(mQGisIface, QgsGeorefPluginGui::findMainWindow());
myPluginGui->show();
myPluginGui->setFocus();
}

// Unload the plugin by cleaning up the GUI
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/georeferencer/plugin.h
Expand Up @@ -68,9 +68,10 @@ class QgsGeorefPlugin:public QObject, public QgisPlugin
//////////////////////////////////////////////////////////////////////

/**
* Constructor for a plugin. The QgisInterface pointer is passed by
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
* QGIS when it attempts to instantiate the plugin.
* @param Pointer to the QgisInterface object.
* @param Pointer to the QgisApp object
* @param Pointer to the QgisIface object.
*/
QgsGeorefPlugin(QgisInterface * );
//! Destructor
Expand Down
191 changes: 169 additions & 22 deletions src/plugins/georeferencer/plugingui.cpp
Expand Up @@ -10,13 +10,16 @@
* (at your option) any later version. *
***************************************************************************/
#include "plugingui.h"
#include "qgsgeorefdescriptiondialog.h"
#include "qgsleastsquares.h"
#include "qgspointdialog.h"
#include "qgsrasterlayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"

//qt includes
#include <QApplication>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QLineEdit>
#include <QMessageBox>
Expand All @@ -32,14 +35,31 @@ QgsGeorefPluginGui::QgsGeorefPluginGui() : QgsGeorefPluginGuiBase()

QgsGeorefPluginGui::QgsGeorefPluginGui(QgisInterface* theQgisInterface,
QWidget* parent, Qt::WFlags fl)
: QDialog(parent, fl), mIface(theQgisInterface)
: QDialog(parent, fl), mIface(theQgisInterface), mPluginWindowsArranged(false)
{
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
mPointDialog = new QgsPointDialog(mIface, parent);
//move point dialog to the left of the screen so that both windows are visible
mPointDialog->move(0, mPointDialog->pos().y());
mPointDialog->show();
}


QgsGeorefPluginGui::~QgsGeorefPluginGui()
{
delete mPointDialog;

//restore size of qgis main window if arrange button was used
if(mPluginWindowsArranged)
{
QWidget* mainWindow = QgsGeorefPluginGui::findMainWindow();
if(mainWindow)
{
mainWindow->resize(origSize);
mainWindow->move(origPos);
}
}
}


Expand All @@ -48,6 +68,12 @@ void QgsGeorefPluginGui::on_pbnClose_clicked()
close(1);
}

void QgsGeorefPluginGui::on_pbnDescription_clicked()
{
QgsGeorefDescriptionDialog d(0);
d.exec();
}


void QgsGeorefPluginGui::on_pbnSelectRaster_clicked() {
QSettings settings;
Expand All @@ -59,20 +85,13 @@ void QgsGeorefPluginGui::on_pbnSelectRaster_clicked() {
tr("Choose a raster file"),
dir,
tr("Raster files (*.*)"));
leSelectRaster->setText(filename);
}


void QgsGeorefPluginGui::on_pbnEnterWorldCoords_clicked() {

// Is there a filename
if (leSelectRaster->text().isEmpty())
{
QMessageBox::critical(this, tr("Error"),
tr("You need to specify a file to georeference first."));
if(filename.isNull())
{
return;
}
leSelectRaster->setText(filename);

return;
}
// do we think that this is a valid raster?
if (!QgsRasterLayer::isValidRasterFileName(leSelectRaster->text())) {
QMessageBox::critical(this, tr("Error"),
Expand All @@ -94,26 +113,154 @@ void QgsGeorefPluginGui::on_pbnEnterWorldCoords_clicked() {
QString worldfile;
if (point != -1 && point != raster.length() - 1) {
worldfile = raster.left(point + 1);
worldfile += raster.at(point + 1);
worldfile += raster.at(raster.length() - 1);
worldfile += 'w';
worldfile += ("wld");
}

// check if there already is a world file
if (!worldfile.isEmpty()) {
if (QFile::exists(worldfile)) {
QMessageBox::StandardButton r = QMessageBox::question(this, tr("World file exists"),
int r = QMessageBox::question(this, tr("World file exists"),
tr("<p>The selected file already seems to have a ")+
tr("world file! Do you want to replace it with the ")+
tr("new world file?</p>"),
QMessageBox::Ok | QMessageBox::Cancel);
if (r == QMessageBox::Cancel)
tr("new world file?</p>"),
QMessageBox::Yes|QMessageBox::Default,
QMessageBox::No|QMessageBox::Escape);
if (r == QMessageBox::No)
return;
else
QFile::remove(worldfile);
}
}

QgsPointDialog* dlg = new QgsPointDialog(raster, mIface, this);
dlg->show();
// XXX This is horrible, but it works and I'm tired / ll
{
QSettings settings;
QgsProject* prj = QgsProject::instance();
mProjBehaviour = settings.readEntry("/Projections/defaultBehaviour");
mProjectSRS = prj->readEntry("SpatialRefSys", "/ProjectSRSProj4String");
mProjectSRSID = prj->readNumEntry("SpatialRefSys", "/ProjectSRSID");

settings.writeEntry("/Projections/defaultBehaviour", "useProject");
prj->writeEntry("SpatialRefSys", "/ProjectSRSProj4String", GEOPROJ4);
prj->writeEntry("SpatialRefSys", "/ProjectSRSID", int(GEOSRS_ID));

settings.writeEntry("/Projections/defaultBehaviour", mProjBehaviour);
prj->writeEntry("SpatialRefSys", "/ProjectSRSProj4String", mProjectSRS);
prj->writeEntry("SpatialRefSys", "/ProjectSRSID", mProjectSRSID);
}

mPointDialog->openImageFile(filename);
mPointDialog->show();
}



void QgsGeorefPluginGui::on_mArrangeWindowsButton_clicked()
{
if(mPointDialog && mIface)
{
QWidget* mainWindow = QgsGeorefPluginGui::findMainWindow();
if(!mainWindow)
{
return;
}

int width, height; //width and height of screen

//store initial size and position of qgis window
mPluginWindowsArranged = true;
origSize = mainWindow->size();
origPos = mainWindow->pos();


//qt distinguishes between geometry with and without window frame
int widthIncrMainWindow, heightIncrMainWindow;
int widthIncrPointDialog, heightIncrPointDialog;
int widthIncrThis, heightIncrThis;

//read the desktop geometry
QDesktopWidget* desktop = QApplication::desktop();
QRect screenGeometry = desktop->availableGeometry();
width = screenGeometry.width();
height = screenGeometry.height();

int leftRightBorder; //border between plugin/point dialogs on the left and qgis main window on the right
int pluginPointDialogBorder; //border on y-axis between plugin dialog and point dialog


leftRightBorder = width/3;
pluginPointDialogBorder = height/5;

//consider minimum heights of plugin dialog and mPointDialog
int minPluginDialogHeight = minimumHeight() + (frameSize().height() - this->height());
int minPointDialogHeight = mPointDialog->minimumHeight() + \
(mPointDialog->frameSize().height() - mPointDialog->height());

if((height - pluginPointDialogBorder) < minPointDialogHeight)
{
pluginPointDialogBorder = (height - minPointDialogHeight);
}
if(pluginPointDialogBorder < minPluginDialogHeight)
{
pluginPointDialogBorder = minPluginDialogHeight;
}

//consider minimum widths of plugin/point dialogs and qgis main window
int minPluginDialogWidth = minimumWidth() + (frameSize().width() - this->width());
int minPointDialogWidth = mPointDialog->minimumWidth() + \
(mPointDialog->frameSize().width() - mPointDialog->width());
int minMainWindowWidth = mainWindow->minimumWidth() + \
(mainWindow->frameSize().width() - mainWindow->width());

if(leftRightBorder < minPointDialogWidth)
{
leftRightBorder = minPointDialogWidth;
}
if(leftRightBorder < minPluginDialogWidth)
{
leftRightBorder = minPluginDialogWidth;
}
if((width - leftRightBorder) < minMainWindowWidth)
{
leftRightBorder = width - minMainWindowWidth;
}

//place main window
widthIncrMainWindow = (width -leftRightBorder) - mainWindow->frameSize().width();
heightIncrMainWindow = height - mainWindow->frameSize().height();
mainWindow->setEnabled(false); //avoid getting two resize events for the main canvas
mainWindow->resize(mainWindow->width() + widthIncrMainWindow, mainWindow->height() + heightIncrMainWindow);
mainWindow->move(leftRightBorder, 0);
mainWindow->setEnabled(true);

//place point dialog
widthIncrPointDialog = leftRightBorder - mPointDialog->frameSize().width();
heightIncrPointDialog = height - pluginPointDialogBorder - mPointDialog->frameSize().height();
mPointDialog->resize(mPointDialog->width() + widthIncrPointDialog, mPointDialog->height() + heightIncrPointDialog);
mPointDialog->move(0, pluginPointDialogBorder);

//place this dialog
widthIncrThis = leftRightBorder - frameSize().width();
heightIncrThis = pluginPointDialogBorder - frameSize().height();
resize(this->width() + widthIncrThis, this->height() + heightIncrThis);
move(0, 0);
}
}


QWidget* QgsGeorefPluginGui::findMainWindow()
{
QWidget* result = 0;

QWidgetList topLevelWidgets = qApp->topLevelWidgets();
QWidgetList::iterator it = topLevelWidgets.begin();
for(; it != topLevelWidgets.end(); ++it)
{
if((*it)->objectName() == "QgisApp")
{
result = *it;
break;
}
}
return result;
}
15 changes: 13 additions & 2 deletions src/plugins/georeferencer/plugingui.h
Expand Up @@ -16,6 +16,7 @@
#include <QDialog>

class QgisInterface;
class QgsPointDialog;

/**
@author Tim Sutton
Expand All @@ -27,18 +28,28 @@ Q_OBJECT
QgsGeorefPluginGui();
QgsGeorefPluginGui(QgisInterface* theQgisInterface, QWidget* parent = 0, Qt::WFlags fl = 0);
~QgsGeorefPluginGui();

/**Finds the qgis main window
@return window pointer or 0 in case or error*/
static QWidget* findMainWindow();

public slots:
void on_pbnClose_clicked();
void on_pbnEnterWorldCoords_clicked();
void on_pbnDescription_clicked();
void on_pbnSelectRaster_clicked();
void on_mArrangeWindowsButton_clicked();

private:

QString mProjBehaviour, mProjectSRS;
int mProjectSRSID;
QgisInterface* mIface;

/**dialog to enter reference point*/
QgsPointDialog* mPointDialog;
/**Flag if plugin windows have been arranged with button*/
bool mPluginWindowsArranged;
QSize origSize;
QPoint origPos;
};

#endif

0 comments on commit 19f2bb3

Please sign in to comment.