Qt Virtual Chart Table (QVCT)
CLandmarkPointEditView.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QDialogButtonBox>
21 #include <QFormLayout>
22 #include <QHBoxLayout>
23 #include <QLabel>
24 #include <QLineEdit>
25 #include <QTextEdit>
26 #include <QVBoxLayout>
27 
28 // QVCT
29 #include "QVCTRuntime.hpp"
32 
33 
34 //------------------------------------------------------------------------------
35 // CONSTRUCTORS / DESTRUCTOR
36 //------------------------------------------------------------------------------
37 
39  : COverlayObjectEditView( _poLandmarkPoint )
40 {
42 }
43 
45 {
46  // Create layout
47  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
48 
49  // Add header
50  QFont __qFontHeader;
51  __qFontHeader.setPixelSize( 16 );
52  __qFontHeader.setBold( true );
53  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
54  QLabel* __pqLabelIcon = new QLabel();
55  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/landmark_point.png" ) );
56  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
57  QLabel* __pqLabelEdit = new QLabel( tr("Edit")+"..." );
58  __pqLabelEdit->setFont( __qFontHeader );
59  __pqHBoxLayoutHeader->addWidget( __pqLabelEdit, 1 );
60  // ... [end]
61  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
62 
63  // Add data
64  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
65  QFormLayout* __pqFormLayout = new QFormLayout();
66 
67  // ... name
68  pqLineEditName = new QLineEdit();
69  pqLineEditName->setToolTip( tr("Name") );
70  pqLineEditName->setText( __poLandmarkPoint->getName() );
71  __pqFormLayout->addRow( tr("Name")+":", pqLineEditName );
72  bool __bPositionDefined = __poLandmarkPoint->CDataPosition::operator!=( CDataPosition::UNDEFINED );
73 
74  // ... position
75  QHBoxLayout* __pqHBoxLayoutPosition = new QHBoxLayout();
76  pqLineEditLongitude = new QLineEdit();
77  pqLineEditLongitude->setToolTip( tr("Longitude") );
78  if( __bPositionDefined ) pqLineEditLongitude->setText( CUnitPosition::toString( __poLandmarkPoint->getLongitude(), CUnitPosition::LONGITUDE ) );
79  __pqHBoxLayoutPosition->addWidget( pqLineEditLongitude );
80  pqLineEditLatitude = new QLineEdit();
81  pqLineEditLatitude->setToolTip( tr("Latitude") );
82  if( __bPositionDefined ) pqLineEditLatitude->setText( CUnitPosition::toString( __poLandmarkPoint->getLatitude(), CUnitPosition::LATITUDE ) );
83  __pqHBoxLayoutPosition->addWidget( pqLineEditLatitude );
84  pqLineEditElevation = new QLineEdit();
85  pqLineEditElevation->setToolTip( tr("Elevation") );
86  if( __poLandmarkPoint->getElevation() != CDataPosition::UNDEFINED_ELEVATION ) pqLineEditElevation->setText( CUnitElevation::toString( __poLandmarkPoint->getElevation() ) );
87  __pqHBoxLayoutPosition->addWidget( pqLineEditElevation );
88  __pqFormLayout->addRow( tr("Position")+":", __pqHBoxLayoutPosition );
89 
90  // ... type/symbol
91  QHBoxLayout* __pqHBoxLayoutTypeSymbol = new QHBoxLayout();
92  pqLineEditType = new QLineEdit();
93  pqLineEditType->setToolTip( tr("Type") );
94  pqLineEditType->setText( __poLandmarkPoint->getType() );
95  __pqHBoxLayoutTypeSymbol->addWidget( pqLineEditType );
96  pqLineEditSymbol = new QLineEdit();
97  pqLineEditSymbol->setToolTip( tr("Symbol") );
98  pqLineEditSymbol->setText( __poLandmarkPoint->getSymbol() );
99  __pqHBoxLayoutTypeSymbol->addWidget( pqLineEditSymbol );
100  __pqFormLayout->addRow( tr("Type & Symbol")+":", __pqHBoxLayoutTypeSymbol );
101 
102  // ... description
103  pqTextEditDescription = new QTextEdit();
104  pqTextEditDescription->setToolTip( tr("Comment") );
105  pqTextEditDescription->setAcceptRichText( false );
106  pqTextEditDescription->setPlainText( __poLandmarkPoint->getDescription() );
107  __pqFormLayout->addRow( tr("Description")+":", pqTextEditDescription );
108 
109  // ... comment
110  pqTextEditComment = new QTextEdit();
111  pqTextEditComment->setToolTip( tr("Comment") );
112  pqTextEditComment->setAcceptRichText( false );
113  pqTextEditComment->setPlainText( __poLandmarkPoint->getComment() );
114  __pqFormLayout->addRow( tr("Comment")+":", pqTextEditComment );
115 
116  // ... url
117  pqLineEditUrl = new QLineEdit();
118  pqLineEditUrl->setToolTip( tr("URL") );
119  pqLineEditUrl->setText( __poLandmarkPoint->getUrl() );
120  __pqFormLayout->addRow( tr("URL")+":", pqLineEditUrl );
121 
122  // ... [end]
123  __pqVBoxLayout->addLayout( __pqFormLayout );
124 
125  // Add buttons
126  QDialogButtonBox* __pqDialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal );
127  QDialog::connect( __pqDialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()) );
128  QDialog::connect( __pqDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()) );
129  __pqVBoxLayout->addWidget( __pqDialogButtonBox );
130 
131  // Set the layout
132  COverlayObjectEditView::setLayout( __pqVBoxLayout );
133 
134 }
135 
136 
137 //------------------------------------------------------------------------------
138 // METHODS: QDialog (override)
139 //------------------------------------------------------------------------------
140 
142 {
143  CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)poOverlayObject;
144 
145  // Check data
146  bool __bOK;
147  double __fdLongitude = CDataPosition::UNDEFINED_LONGITUDE;
148  double __fdLatitude = CDataPosition::UNDEFINED_LATITUDE;
149  double __fdElevation = CDataPosition::UNDEFINED_ELEVATION;
150  if( !pqLineEditLongitude->text().isEmpty() && !pqLineEditLatitude->text().isEmpty() )
151  {
152  __fdLongitude = CUnitPosition::fromString( pqLineEditLongitude->text(), &__bOK );
153  if( !__bOK )
154  {
156  return;
157  }
158  __fdLatitude = CUnitPosition::fromString( pqLineEditLatitude->text(), &__bOK );
159  if( !__bOK )
160  {
162  return;
163  }
164  }
165  if( !pqLineEditElevation->text().isEmpty() )
166  {
167  __fdElevation = CUnitElevation::fromString( pqLineEditElevation->text(), &__bOK );
168  if( !__bOK )
169  {
171  return;
172  }
173  }
174 
175  // Set data
176  // ... name
177  __poLandmarkPoint->setText( CLandmarkOverlay::NAME, pqLineEditName->text() ); // NOTE: Item's name will be updated via QTreeWidget::itemChanged()
178  // ... position/elevation
179  __poLandmarkPoint->setPosition( __fdLongitude, __fdLatitude, __fdElevation );
180  // ... type
181  __poLandmarkPoint->setType( pqLineEditType->text() );
182  // ... description
183  __poLandmarkPoint->setDescription( pqTextEditDescription->toPlainText() );
184  // ... comment
185  __poLandmarkPoint->setComment( pqTextEditComment->toPlainText() );
186  // ... symbol
187  __poLandmarkPoint->setSymbol( pqLineEditSymbol->text() );
188  // ... url
189  __poLandmarkPoint->setUrl( pqLineEditUrl->text() );
190 
191  // Done
192  QDialog::accept();
193 }
double getLongitude() const
Returns this position's longitude, in degrees.
static constexpr double UNDEFINED_LATITUDE
Specific value for an undefined latitude.
double getElevation() const
Returns this position's elevation, in meters.
double getLatitude() const
Returns this position's latitude, in degrees.
static const CDataPosition UNDEFINED
Specific value for an undefined position.
static constexpr double UNDEFINED_LONGITUDE
Specific value for an undefined longitude.
void setPosition(double _fdLongitude, double _fdLatitude, double _fdElevation=UNDEFINED_ELEVATION)
Sets new coordinates.
static constexpr double UNDEFINED_ELEVATION
Specific value for an undefined elevation.
@ NAME
Landmark name.
QLineEdit * pqLineEditType
[UI:LineEdit] Type
QLineEdit * pqLineEditName
[UI:LineEdit] Name
QTextEdit * pqTextEditDescription
[UI:TextEdit] Description
QLineEdit * pqLineEditUrl
[UI:LineEdit] URL
QLineEdit * pqLineEditLatitude
[UI:LineEdit] Latitude
CLandmarkPointEditView(CLandmarkPoint *_poLandmarkPoint)
QLineEdit * pqLineEditElevation
[UI:LineEdit] Elevation
QTextEdit * pqTextEditComment
[UI:TextEdit] Comment
QLineEdit * pqLineEditLongitude
[UI:LineEdit] Longitude
QLineEdit * pqLineEditSymbol
[UI:LineEdit] Symbol
void constructLayout()
Constructs the layout of the user-interface.
[UI] Landmark overlay point (item)
QString getSymbol() const
Returns this landmark's symbol.
void setType(const QString &_rqsType)
Sets this landmark's type.
QString getComment() const
Returns this landmark's comment.
QString getType() const
Returns this landmark's type.
void setDescription(const QString &_rqsDescription)
Sets this landmark's description.
void setComment(const QString &_rqsComment)
Sets this landmark's comment.
void setSymbol(const QString &_rqsSymbol)
Sets this landmark's symbol.
void setUrl(const QString &_rqsUrl)
Sets this landmark's URL.
QString getUrl() const
Returns this landmark's URL.
QString getDescription() const
Returns this landmark's description.
void parseError(const QString &_rqsString)
Displays a generic error message for an invalid parsing operation.
[UI] Generic overlay object's edit view
const COverlayObject * poOverlayObject
Overlay object being edited.
QString getName() const
Returns this object's name.
static QString toString(double _fdValue, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static double fromString(const QString &_rqString, EUnit _eUnit=UNDEFINED, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
static QString toString(double _fdValue, EType _eType, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
static double fromString(const QString &_rqString, bool *_pbOK=0)
Returns the numeric value corresponding (parsed) from the string.
static CMainWindow * useMainWindow()