Qt Virtual Chart Table (QVCT)
CLandmarkContainerDetailView.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 <QFileInfo>
21 #include <QHBoxLayout>
22 #include <QLabel>
23 #include <QPushButton>
24 #include <QScrollArea>
25 #include <QStackedWidget>
26 #include <QTabWidget>
27 #include <QVBoxLayout>
28 #include <QWidget>
29 
30 // QVCT
31 #include "QVCTRuntime.hpp"
32 #include "data/CDataPosition.hpp"
37 
38 
39 //------------------------------------------------------------------------------
40 // CONSTRUCTORS / DESTRUCTOR
41 //------------------------------------------------------------------------------
42 
44  : COverlayObjectDetailView( _pqParent )
45 {
47 }
48 
50 {
51  // Create the buttons
52  // ... visible
53  pqPushButtonVisible = new QPushButton( QIcon( ":icons/32x32/visible.png" ), "" );
54  pqPushButtonVisible->setMaximumSize( 36, 34 );
55  pqPushButtonVisible->setToolTip( tr("Toggle this landmarks set's visibility") );
56  pqPushButtonVisible->setEnabled( false );
57  QWidget::connect( pqPushButtonVisible, SIGNAL( clicked() ), this, SLOT( slotToggleVisible() ) );
58  // ... center
59  pqPushButtonCenter = new QPushButton( QIcon( ":icons/32x32/center.png" ), "" );
60  pqPushButtonCenter->setMaximumSize( 36, 34 );
61  pqPushButtonCenter->setToolTip( tr("Center chart on this landmarks set's mean position") );
62  pqPushButtonCenter->setEnabled( false );
63  QWidget::connect( pqPushButtonCenter, SIGNAL( clicked() ), this, SLOT( slotPositionCenter() ) );
64  // ... edit
65  pqPushButtonEdit = new QPushButton( QIcon( ":icons/32x32/edit.png" ), "" );
66  pqPushButtonEdit->setMaximumSize( 36, 34 );
67  pqPushButtonEdit->setToolTip( tr("Edit this landmarks set") );
68  pqPushButtonEdit->setEnabled( false );
69  QWidget::connect( pqPushButtonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
70  // ... save
71  pqPushButtonSave = new QPushButton( QIcon( ":icons/32x32/save.png" ), "" );
72  pqPushButtonSave->setMaximumSize( 36, 34 );
73  pqPushButtonSave->setToolTip( tr("Save this landmarks set to disk") );
74  pqPushButtonSave->setEnabled( false );
75  QWidget::connect( pqPushButtonSave, SIGNAL( clicked() ), this, SLOT( slotSave() ) );
76  // ... delete
77  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
78  pqPushButtonDelete->setMaximumSize( 36, 34 );
79  pqPushButtonDelete->setToolTip( tr("Delete this landmarks set") );
80  pqPushButtonDelete->setEnabled( false );
81  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
82  // ... add point
83  pqPushButtonAddPoint = new QPushButton( QIcon( ":icons/32x32/point_add.png" ), "" );
84  pqPushButtonAddPoint->setMaximumSize( 36, 34 );
85  pqPushButtonAddPoint->setToolTip( tr("Add a new landmark to this landmarks set") );
86  pqPushButtonAddPoint->setEnabled( false );
87  QWidget::connect( pqPushButtonAddPoint, SIGNAL( clicked() ), this, SLOT( slotAddPoint() ) );
88 
89  // Create layout
90  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
91 
92  // Add header
93  QFont __qFontHeader;
94  __qFontHeader.setPixelSize( 16 );
95  __qFontHeader.setBold( true );
96  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
97  QLabel* __pqLabelIcon = new QLabel();
98  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/landmark.png" ) );
99  __pqLabelIcon->setToolTip( tr("Landmarks set") );
100  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
101  poTextName = new COverlayText();
102  poTextName->setToolTip( tr("Name") );
103  poTextName->setFont( __qFontHeader );
104  poTextName->setWordWrap( true );
105  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
106  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
107 
108  // Add data
109  QFont __qFontData;
110  QTabWidget* __poTabWidget = new QTabWidget();
111  __poTabWidget->setTabPosition( QTabWidget::South );
112  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
113 
114  // ... summary
115  QWidget* __poWidgetSummary = new QWidget();
116  QVBoxLayout* __pqVBoxLayoutSummary = new QVBoxLayout();
117  __qFontData.setPixelSize( 20 );
118  poTextContent = new COverlayText();
119  poTextContent->setToolTip( tr("Landmarks count") );
120  poTextContent->setFont( __qFontData );
121  poTextContent->setIndent( 10 );
122  poTextContent->setAlignment( Qt::AlignHCenter );
124  __pqVBoxLayoutSummary->addWidget( poTextContent, 1 );
125  __poWidgetSummary->setLayout( __pqVBoxLayoutSummary );
126  __poTabWidget->addTab( __poWidgetSummary, tr("Summary") );
127 
128  // ... [end]
129  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
130 
131  // Add separator
132  QFrame* __pqFrameSeparator = new QFrame();
133  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
134  __pqVBoxLayout->addWidget( __pqFrameSeparator );
135 
136  // Add buttons
137  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
138  __pqHBoxLayoutButtons->addWidget( pqPushButtonVisible, 0, Qt::AlignLeft );
139  __pqHBoxLayoutButtons->addWidget( pqPushButtonCenter, 1, Qt::AlignLeft );
140  __pqHBoxLayoutButtons->addWidget( pqPushButtonEdit, 0, Qt::AlignHCenter );
141  __pqHBoxLayoutButtons->addWidget( pqPushButtonSave, 0, Qt::AlignHCenter );
142  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 0, Qt::AlignHCenter );
143  __pqHBoxLayoutButtons->addWidget( pqPushButtonAddPoint, 1, Qt::AlignRight );
144  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
145 
146  // Set the layout
147  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
148 
149 }
150 
151 
152 //------------------------------------------------------------------------------
153 // METHODS: COverlayObjectDetailView (implement/override)
154 //------------------------------------------------------------------------------
155 
157 {
158  if( !poOverlayObject ) return;
159  CLandmarkContainer* __poLandmarkContainer = (CLandmarkContainer*)poOverlayObject;
160  poTextName->setText( __poLandmarkContainer->getName() );
161  poTextContent->setText( QString::number( __poLandmarkContainer->childCount() )+" "+tr("Landmark(s)") );
162 }
163 
165 {
168 }
169 
171 {
172  if( poOverlayObject )
173  {
174  pqPushButtonVisible->setEnabled( true );
175  pqPushButtonCenter->setEnabled( true );
176  pqPushButtonEdit->setEnabled( true );
177  pqPushButtonSave->setEnabled( true );
178  pqPushButtonDelete->setEnabled( true );
179  pqPushButtonAddPoint->setEnabled( true );
180  }
181 }
182 
184 {
185  pqPushButtonVisible->setEnabled( false );
186  pqPushButtonCenter->setEnabled( false );
187  pqPushButtonEdit->setEnabled( false );
188  pqPushButtonSave->setEnabled( false );
189  pqPushButtonDelete->setEnabled( false );
190  pqPushButtonAddPoint->setEnabled( false );
191 }
192 
193 
194 //------------------------------------------------------------------------------
195 // METHODS
196 //------------------------------------------------------------------------------
197 
198 //
199 // SLOTS
200 //
201 
203 {
204  if( !poOverlayObject ) return;
205  CLandmarkContainer* __poLandmarkContainer = (CLandmarkContainer*)poOverlayObject;
206  bool __bVisible = __poLandmarkContainer->isVisible();
207  __poLandmarkContainer->toggleVisibility();
208  if( __bVisible != __poLandmarkContainer->isVisible() )
209  {
210  __poLandmarkContainer->setCheckState( CLandmarkOverlay::VISIBLE, __bVisible ? Qt::Unchecked : Qt::Checked );
211  }
212  __poLandmarkContainer->useOverlay()->forceRedraw();
214 }
215 
217 {
218  if( !poOverlayObject ) return;
219  CDataPosition __oDataPositionLower, __oDataPositionUpper;
220  int __iCount = COverlayPoint::getPositionBox( poOverlayObject, &__oDataPositionLower, &__oDataPositionUpper );
221  if( __iCount > 1 ) QVCTRuntime::useChartTable()->setScaleArea( __oDataPositionLower, __oDataPositionUpper, 0.9 );
222  else if( __iCount == 1 ) QVCTRuntime::useChartTable()->setGeoPosition( __oDataPositionLower );
224 }
225 
227 {
228  if( !poOverlayObject ) return;
229  ((CLandmarkContainer*)poOverlayObject)->showEdit();
231 }
232 
234 {
235  if( !poOverlayObject ) return;
236  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::SAVE, tr("Save Landmarks"), tr("GPX Files")+" (*.gpx);;"+tr("QVCT Files")+" (*.qvct)" );
237  if( __qsFilename.isEmpty() ) return;
238  QFileInfo __qFileInfo( __qsFilename );
239  if( __qFileInfo.suffix().isEmpty() ) __qsFilename += ".qvct";
240  QStringList __qsListExtensions; __qsListExtensions << "qvct" << "gpx";
241  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::SAVE, __qsFilename, &__qsListExtensions ) ) return;
243 }
244 
246 {
247  if( !poOverlayObject ) return;
248  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
249  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
250  CLandmarkOverlay* __poLandmarkOverlay = (CLandmarkOverlay*)poOverlayObject->useOverlay();
251  CLandmarkContainer* __poLandmarkContainer = (CLandmarkContainer*)poOverlayObject;
252  __pqMutexDataChange->lock();
253  __poLandmarkOverlay->removeChild( __poLandmarkContainer );
254  __pqMutexDataChange->unlock();
255  delete __poLandmarkContainer;
256  QTreeWidgetItem* __pqTreeWidgetItem = __poLandmarkOverlay->currentItem();
257  if( __pqTreeWidgetItem ) __poLandmarkOverlay->showDetail( __pqTreeWidgetItem );
258  __poLandmarkOverlay->forceRedraw();
261 }
262 
264 {
265  if( !poOverlayObject ) return;
266  QString __qsName = poOverlayObject->newChildName( tr("Landmark"), 1, true );
267  CLandmarkPoint* __poLandmarkPoint = ((CLandmarkContainer*)poOverlayObject)->addPoint( __qsName );
268  if( !__poLandmarkPoint ) return;
269  QVCTRuntime::useLandmarkOverlay()->setCurrentItem( __poLandmarkPoint );
270  __poLandmarkPoint->showEdit();
272 }
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
void setScaleArea(const CDataPosition &_roGeoPosition1, const CDataPosition &_roGeoPosition2, double _fdScaleCorrection=1.0)
Sets the reference scale factor to display the given (geographical) area (defined by its opposite cor...
void updateChart()
Update the (current) chart content (on screen)
void setGeoPosition(const CDataPosition &_roGeoPosition, bool _bSkipCurrent=false)
Sets the reference chart (geographical) position.
(Geographical) Position data [long,lat,elev]
void slotSave()
[UI:Slot] Slot to save this container to file
QPushButton * pqPushButtonCenter
[UI:Button] Center (on chart)
QPushButton * pqPushButtonDelete
[UI:Button] Delete
void slotEdit()
[UI:Slot] Slot to display edit view
QPushButton * pqPushButtonVisible
[UI:Button] Visibility status
void slotAddPoint()
[UI:Slot] Slot to add new (landmark) point
void slotDelete()
[UI:Slot] Slot to delete (this container)
COverlayText * poTextName
[UI:Label] Name
QPushButton * pqPushButtonEdit
[UI:Button] Edit
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonSave
[UI:Button] Save
CLandmarkContainerDetailView(QWidget *_pqParent=0)
void slotToggleVisible()
[UI:Slot] Slot to modify the visibility status
COverlayText * poTextContent
[UI:Label] Content (items summary)
virtual void enableContent()
Enables the content (controls) of the underlying widget.
void slotPositionCenter()
[UI:Slot] Slot to center chart (on container's items position)
QPushButton * pqPushButtonAddPoint
[UI:Button] Add new (landmark) point
virtual void resetContent()
Resets (clears) the content of the underlying widget.
virtual void disableContent()
Disables the content (controls) of the underlying widget.
virtual void refreshContent()
Refreshes the content of the underlying widget.
[UI] Landmark overlay container
virtual void toggleVisibility()
virtual COverlay * useOverlay()
Returns this object's (base) overlay.
[UI] Landmark overlay container
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
void save(const QString &_rqsFilename, CLandmarkContainer *_poLandmarkContainer=0) const
Save this object's content (container) to the given file (all selected items if no container is given...
@ VISIBLE
Landmark visibility status.
[UI] Landmark overlay point (item)
virtual void showEdit()
Displays this object's edit widget/view.
QString fileDialog(QVCT::EFileOperation _eFileOperation, const QString &_rqsTitle, const QString &_rqsFilter)
Displays a generic dialog to pick a file for the given operation (open/save)
[UI] Generic overlay object's detail view
COverlayObject * poOverlayObject
Overlay object being displayed.
virtual COverlay * useOverlay()=0
Returns this object's (base) overlay.
QString getName() const
Returns this object's name.
QString newChildName(const QString &_rqsName, int _iZeroPrefix=0, bool _bForceSuffix=false) const
Returns a valid (non-duplicate) name for a new sibling of this object.
static int getPositionBox(const QTreeWidgetItem *_pqTreeWidgetItem, CDataPosition *_poDataPositionLower, CDataPosition *_poDataPositionUpper, int _iIndexMin=0, int _iIndexMax=-1)
Returns the minimal geographical positions box containing the points in the given overlay/container.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
void resetText()
Resets (clears) the underlying QLabel's text.
bool isVisible() const
Returns the point's (marker) visibility status.
void forceRedraw()
Forces this overlay's rendering (not matter its cache content)
Definition: COverlay.hpp:115
static QMutex * useMutexDataChange()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
static CLandmarkOverlay * useLandmarkOverlay()
@ SAVE
Definition: QVCT.hpp:42