~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/grid_maker/plugingui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2003 by Tim Sutton                                      *
3
 
 *   tim@linfiniti.com                                                     *
4
 
 *                                                                         *
5
 
 *   This is a plugin generated from the QGIS plugin template              *
6
 
 *                                                                         *
7
 
 *   This program is free software; you can redistribute it and/or modify  *
8
 
 *   it under the terms of the GNU General Public License as published by  *
9
 
 *   the Free Software Foundation; either version 2 of the License, or     *
10
 
 *   (at your option) any later version.                                   *
11
 
 ***************************************************************************/
12
 
#include "plugingui.h"
13
 
 
14
 
//qt includes
15
 
#include <QFileDialog>
16
 
#include <QMessageBox>
17
 
 
18
 
#include "graticulecreator.h"
19
 
#include <qgslogger.h>
20
 
 
21
 
//standard includes
22
 
#include <iostream>
23
 
 
24
 
QgsGridMakerPluginGui::QgsGridMakerPluginGui() : QgsGridMakerPluginGuiBase()
25
 
{
26
 
  setupUi(this);
27
 
}
28
 
QgsGridMakerPluginGui::QgsGridMakerPluginGui(QWidget* parent, Qt::WFlags fl)
29
 
  : QDialog(parent, fl)
30
 
{
31
 
  setupUi(this);
32
 
}
33
 
QgsGridMakerPluginGui::~QgsGridMakerPluginGui()
34
 
{}
35
 
 
36
 
void QgsGridMakerPluginGui::on_pbnOK_clicked()
37
 
{
38
 
  //check input file exists
39
 
  //
40
 
  QgsLogger::debug("GrativuleCreator called with: " +
41
 
      leOutputShapeFile->text() + " " +
42
 
      leLongitudeInterval->text() + " " +
43
 
      leLatitudeInterval->text() + " " +
44
 
      leOriginLongitude->text() + " " +
45
 
      leOriginLatitude->text() + " " +
46
 
      leEndPointLongitude->text() + " " +
47
 
      leEndPointLatitude->text());
48
 
 
49
 
  if (leOutputShapeFile->text().isEmpty())
50
 
  {
51
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
52
 
            QString(tr("Please enter the file name before pressing OK!") ));
53
 
    return;
54
 
  }
55
 
 
56
 
  bool myFlag=false; //presumed guilty
57
 
 
58
 
  double myLongitudeInterval =  leLongitudeInterval->text().toDouble(&myFlag);
59
 
  if (!myFlag)
60
 
  {
61
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
62
 
            QString(tr("Longitude Interval is invalid - please correct and try again." )));
63
 
    return;
64
 
  }
65
 
  myFlag=false;//reset test flag
66
 
  double myLatitudeInterval =  leLatitudeInterval->text().toDouble(&myFlag);
67
 
  if (!myFlag)
68
 
  {
69
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
70
 
            QString(tr("Latitude Interval is invalid - please correct and try again." )));
71
 
    return;
72
 
  }
73
 
  myFlag=false;//reset test flag
74
 
  double myLongitudeOrigin =  leOriginLongitude->text().toDouble(&myFlag);
75
 
  if (!myFlag)
76
 
  {
77
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
78
 
            QString(tr("Longitude Origin is invalid - please correct and try again.." )));
79
 
    return;
80
 
  }
81
 
  myFlag=false;//reset test flag
82
 
  double myLatitudeOrigin =  leOriginLatitude->text().toDouble(&myFlag);
83
 
  if (!myFlag)
84
 
  {
85
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
86
 
            QString(tr("Latitude Origin is invalid - please correct and try again." )));
87
 
    return;
88
 
  }
89
 
  myFlag=false;//reset test flag
90
 
  double myEndPointLongitude = leEndPointLongitude->text().toDouble(&myFlag);
91
 
  if (!myFlag)
92
 
  {
93
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
94
 
            QString(tr("End Point Longitude is invalid - please correct and try again." )));
95
 
    return;
96
 
  }
97
 
  myFlag=false;//reset test flag
98
 
  double myEndPointLatitude = leEndPointLatitude->text().toDouble(&myFlag);
99
 
  if (!myFlag)
100
 
  {
101
 
    QMessageBox::warning( 0, tr("QGIS - Grid Maker"),
102
 
            QString(tr("End Point Latitude is invalid - please correct and try again." )));
103
 
    return;
104
 
  }
105
 
 
106
 
 
107
 
  if (radPoint->isChecked())
108
 
  {
109
 
    GraticuleCreator  myGraticuleCreator ( leOutputShapeFile->text(),GraticuleCreator::POINT );
110
 
    myGraticuleCreator.generatePointGraticule(
111
 
            myLongitudeInterval,
112
 
            myLatitudeInterval,
113
 
            myLongitudeOrigin,
114
 
            myLatitudeOrigin,
115
 
            myEndPointLongitude,
116
 
            myEndPointLatitude
117
 
            );
118
 
  }
119
 
  else if (radLine->isChecked())
120
 
  {
121
 
    GraticuleCreator  myGraticuleCreator ( leOutputShapeFile->text(),GraticuleCreator::LINE );
122
 
    myGraticuleCreator.generateLineGraticule(
123
 
            myLongitudeInterval,
124
 
            myLatitudeInterval,
125
 
            myLongitudeOrigin,
126
 
            myLatitudeOrigin,
127
 
            myEndPointLongitude,
128
 
            myEndPointLatitude
129
 
            );
130
 
  }
131
 
  else
132
 
  {
133
 
    GraticuleCreator  myGraticuleCreator ( leOutputShapeFile->text(),GraticuleCreator::POLYGON);
134
 
    myGraticuleCreator.generatePolygonGraticule(
135
 
            myLongitudeInterval,
136
 
            myLatitudeInterval,
137
 
            myLongitudeOrigin,
138
 
            myLatitudeOrigin,
139
 
            myEndPointLongitude,
140
 
            myEndPointLatitude
141
 
            );
142
 
  }
143
 
  //
144
 
  // If you have a produced a raster layer using your plugin, you can ask qgis to
145
 
  // add it to the view using:
146
 
  // emit drawRasterLayer(QString("layername"));
147
 
  // or for a vector layer
148
 
  //emit drawVectorLayer(QString("pathname"),QString("layername"),QString("provider name (either ogr or postgres"));
149
 
  //
150
 
 
151
 
  emit drawVectorLayer(leOutputShapeFile->text(),QString("Graticule"),QString("ogr"));
152
 
  //close the dialog
153
 
  done(1);
154
 
}
155
 
 
156
 
 
157
 
void QgsGridMakerPluginGui::on_pbnSelectOutputFile_clicked()
158
 
{
159
 
 QgsLogger::debug(" Gps File Importer Gui::pbnSelectOutputFile_clicked()");
160
 
  QString myOutputFileNameQString = QFileDialog::getSaveFileName(
161
 
          this,
162
 
          tr("Choose a filename to save under"),
163
 
          ".",
164
 
          tr("ESRI Shapefile (*.shp)"));
165
 
 
166
 
  if (myOutputFileNameQString.right(4) != ".shp")
167
 
    myOutputFileNameQString += ".shp";
168
 
 
169
 
  leOutputShapeFile->setText(myOutputFileNameQString);
170
 
  if ( leOutputShapeFile->text()==""  )
171
 
  {
172
 
    pbnOK->setEnabled(false);
173
 
  }
174
 
  else
175
 
  {
176
 
    pbnOK->setEnabled(true);
177
 
  }
178
 
}
179
 
 
180
 
 
181
 
void QgsGridMakerPluginGui::on_pbnCancel_clicked()
182
 
{
183
 
  close(1);
184
 
}
185