Skip to content
Permalink
Browse files

Added usability enhancements for georef plugin to trunk

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7309 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 1, 2007
1 parent d3c1288 commit e4b6f30b933e1919c2d783cc18434a2bffbf0618
@@ -9,6 +9,7 @@ SET (GEOREF_SRCS
qgsimagewarper.cpp
qgsleastsquares.cpp
qgspointdialog.cpp
qgsgeorefdescriptiondialog.cpp
qgsgeorefwarpoptionsdialog.cpp
mapcoordsdialog.cpp
)
@@ -17,6 +18,7 @@ SET (GEOREF_UIS
pluginguibase.ui
qgspointdialogbase.ui
mapcoordsdialogbase.ui
qgsgeorefdescriptiondialogbase.ui
qgsgeorefwarpoptionsdialogbase.ui
)

@@ -12,6 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/

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

@@ -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()));
@@ -79,3 +81,4 @@ void MapCoordsDialog::on_btnPointFromCanvas_clicked()
mPrevMapTool = mQgisCanvas->mapTool();
mQgisCanvas->setMapTool(mToolEmitPoint);
}

@@ -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)
{
}
@@ -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
@@ -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
@@ -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>
@@ -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);
}
}
}


@@ -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;
@@ -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"),
@@ -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;
}
@@ -16,6 +16,7 @@
#include <QDialog>

class QgisInterface;
class QgsPointDialog;

/**
@author Tim Sutton
@@ -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 e4b6f30

Please sign in to comment.
You can’t perform that action at this time.