Changeset 5420 in ntrip for trunk/GnssCenter
- Timestamp:
- Sep 12, 2013, 4:05:11 PM (11 years ago)
- Location:
- trunk/GnssCenter/map_stations
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GnssCenter/map_stations/map_stations.cpp
r5418 r5420 29 29 30 30 #include "map_stations.h" 31 #include "worldplot.h" 31 32 #include "thriftclient.h" 32 33 … … 38 39 // Constructor 39 40 ///////////////////////////////////////////////////////////////////////////// 40 t_map_stations::t_map_stations() : Q Dialog() {41 t_map_stations::t_map_stations() : QMainWindow() { 41 42 42 // Map in Scalable Vector Graphics (svg) Format 43 // -------------------------------------------- 44 _mapPlot = new QwtPlot(); 45 46 _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0); 47 _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0); 48 49 _mapPlotZoomer = new QwtPlotZoomer(_mapPlot->canvas()); 50 51 _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus); 52 53 QwtPlotSvgItem* mapItem = new QwtPlotSvgItem(); 54 mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg"); 55 mapItem->attach(_mapPlot); 56 57 // Buttons 58 // ------- 59 int ww = QFontMetrics(font()).width('w'); 60 61 _buttonClose = new QPushButton(tr("Close"), this); 62 _buttonClose->setMaximumWidth(10*ww); 63 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose())); 64 65 _buttonPrint = new QPushButton(tr("Print"), this); 66 _buttonPrint->setMaximumWidth(10*ww); 67 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint())); 68 69 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this); 70 _buttonWhatsThis->setMaximumWidth(10*ww); 71 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis())); 72 73 // Layout 74 // ------ 75 QHBoxLayout* buttonLayout = new QHBoxLayout; 76 buttonLayout->addWidget(_buttonClose); 77 buttonLayout->addWidget(_buttonPrint); 78 buttonLayout->addWidget(_buttonWhatsThis); 79 80 QVBoxLayout* mainLayout = new QVBoxLayout(this); 81 mainLayout->addWidget(_mapPlot); 82 mainLayout->addLayout(buttonLayout); 83 84 // WhatsThis 85 // --------- 86 _buttonClose->setWhatsThis(tr("<p>Close window.</p>")); 87 _buttonPrint->setWhatsThis(tr("<p>Print stream distribution map.</p>")); 88 89 // Minimal and Maximal Coordinates 90 // ------------------------------- 91 _minPointLat = 0.0; 92 _maxPointLat = 0.0; 93 _minPointLon = 0.0; 94 _maxPointLon = 0.0; 95 96 // Important 97 // --------- 98 _mapPlot->replot(); 43 // World Plot 44 // ---------- 45 _plot = new t_worldPlot(); 46 setCentralWidget(_plot); 99 47 100 48 // Thrift Client; … … 107 55 ///////////////////////////////////////////////////////////////////////////// 108 56 t_map_stations::~t_map_stations() { 109 delete _mapPlot;110 delete _buttonWhatsThis;111 57 _thriftClient->stop(); 112 58 } 113 59 114 //115 /////////////////////////////////////////////////////////////////////////////116 void t_map_stations::slotNewPoint(const QString& name, double latDeg, double lonDeg) {117 118 if (lonDeg > 180.0) lonDeg -= 360.0;119 120 QColor red(220,20,60);121 QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),122 QPen(red), QSize(2,2));123 QwtPlotMarker* marker = new QwtPlotMarker();124 marker->setValue(lonDeg, latDeg);125 if (lonDeg > 170.0) {126 marker->setLabelAlignment(Qt::AlignLeft);127 }128 else {129 marker->setLabelAlignment(Qt::AlignRight);130 }131 QwtText text(name.left(4));132 QFont font = text.font();133 font.setPointSize(font.pointSize()*0.8);134 text.setFont(font);135 marker->setLabel(text);136 marker->setSymbol(symbol);137 marker->attach(_mapPlot);138 139 // Remeber minimal and maximal coordinates140 // ---------------------------------------141 if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&142 _minPointLon == 0.0 && _maxPointLon == 0.0) {143 _minPointLat = latDeg;144 _maxPointLat = latDeg;145 _minPointLon = lonDeg;146 _maxPointLon = lonDeg;147 }148 else {149 if (_maxPointLat < latDeg) {150 _maxPointLat = latDeg;151 }152 else if (_minPointLat > latDeg) {153 _minPointLat = latDeg;154 }155 if (_maxPointLon < lonDeg) {156 _maxPointLon = lonDeg;157 }158 else if (_minPointLon > lonDeg) {159 _minPointLon = lonDeg;160 }161 }162 }163 60 164 61 // … … 169 66 << result->_x << ' ' << result->_y << ' ' << result->_z << endl; 170 67 } 171 172 // Close173 ////////////////////////////////////////////////////////////////////////////174 void t_map_stations::slotClose() {175 done(0);176 }177 178 // Close Dialog gracefully179 ////////////////////////////////////////////////////////////////////////////180 void t_map_stations::closeEvent(QCloseEvent* event) {181 QDialog::closeEvent(event);182 }183 184 //185 ////////////////////////////////////////////////////////////////////////////186 void t_map_stations::showEvent(QShowEvent* event) {187 double width = _maxPointLon - _minPointLon;188 double height = _maxPointLat - _minPointLat;189 if (width > 0 && height > 0) {190 191 // Extend plot area by 10 percent192 // ------------------------------193 double eps = 0.1;194 double epsLon = eps * (_maxPointLon - _minPointLon);195 double epsLat = eps * (_maxPointLat - _minPointLat);196 double widthExt = width + 2 * epsLon;197 double heightExt = height + 2 * epsLat;198 double minLon = _minPointLon - epsLon;199 double minLat = _minPointLat - epsLat;200 201 // Keep lat/lon relations202 // ----------------------203 double widthBorder = widthExt;204 double heightBorder = heightExt;205 double scale = widthExt/heightExt/2.;206 if ( scale < 1.) {207 widthBorder = widthExt / scale;208 minLon = minLon - (widthBorder - widthExt)/2.;209 }210 else {211 heightBorder = heightExt * scale;212 minLat = minLat - (heightBorder - heightExt)/2.;213 }214 215 // Borders shall not exceed min or max values216 // ------------------------------------------217 if (minLon < -180.) minLon = -180.;218 if (minLat < -90.) minLat = -90.;219 double maxLat = minLat + heightBorder;220 if ( maxLat > 90) minLat = minLat - (maxLat - 90.);221 double maxLon = minLon + widthBorder;222 if ( maxLon > 180) minLon = minLon - (maxLon - 180.);223 224 // Area large enough to justify world map225 // --------------------------------------226 if (widthBorder < 270.0 && heightBorder < 135.0) {227 QRectF rect(minLon, minLat, widthBorder, heightBorder);228 _mapPlotZoomer->zoom(rect);229 }230 }231 QDialog::showEvent(event);232 }233 234 // Print the widget235 ////////////////////////////////////////////////////////////////////////////236 void t_map_stations::slotPrint() {237 238 QPrinter printer;239 QPrintDialog* dialog = new QPrintDialog(&printer, this);240 dialog->setWindowTitle(tr("Print Map"));241 if (dialog->exec() != QDialog::Accepted) {242 return;243 }244 else {245 QwtPlotRenderer renderer;246 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);247 renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);248 renderer.renderTo(_mapPlot, printer);249 }250 }251 252 // Whats This Help253 ////////////////////////////////////////////////////////////////////////////254 void t_map_stations::slotWhatsThis() {255 QWhatsThis::enterWhatsThisMode();256 }257 -
trunk/GnssCenter/map_stations/map_stations.h
r5416 r5420 6 6 #include "plugininterface.h" 7 7 8 class QwtPlot; 9 class QwtPlotZoomer; 8 namespace GnssCenter { 9 class t_worldPlot; 10 } 11 10 12 class t_thriftClient; 11 13 class t_thriftResult; … … 13 15 namespace GnssCenter { 14 16 15 class t_map_stations : public Q Dialog{17 class t_map_stations : public QMainWindow { 16 18 Q_OBJECT 17 19 public: … … 20 22 21 23 public slots: 22 void slotNewPoint(const QString& name, double latDeg, double lonDeg);23 24 void slotNewThriftResult(t_thriftResult*); 24 25 25 private slots:26 void slotClose();27 void slotPrint();28 void slotWhatsThis();29 30 protected:31 virtual void closeEvent(QCloseEvent *);32 virtual void showEvent(QShowEvent *);33 34 26 private: 35 QwtPlot* _mapPlot; 36 QwtPlotZoomer* _mapPlotZoomer; 37 QPushButton* _buttonClose; 38 QPushButton* _buttonPrint; 39 QPushButton* _buttonWhatsThis; 40 double _minPointLat; 41 double _maxPointLat; 42 double _minPointLon; 43 double _maxPointLon; 44 27 t_worldPlot* _plot; 45 28 t_thriftClient* _thriftClient; 46 29 }; -
trunk/GnssCenter/map_stations/map_stations.pro
r5413 r5420 25 25 26 26 HEADERS = map_stations.h \ 27 worldplot.h \ 27 28 thriftclient.h 28 29 29 30 SOURCES = map_stations.cpp \ 31 worldplot.cpp \ 30 32 thriftclient.cpp \ 31 33 gen-cpp/RtnetData.cpp \
Note:
See TracChangeset
for help on using the changeset viewer.