Qt Virtual Chart Table (QVCT)
CLandmarkOverlayListView.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 <QHBoxLayout>
21 #include <QPushButton>
22 #include <QStackedWidget>
23 #include <QVBoxLayout>
24 #include <QWidget>
25 
26 // QVCT
27 #include "QVCTRuntime.hpp"
31 
32 
33 //------------------------------------------------------------------------------
34 // CONSTRUCTORS / DESTRUCTOR
35 //------------------------------------------------------------------------------
36 
38  : QWidget( _pqParent )
39 {
41 }
42 
44 {
45  // Create the overlay/tree
48 
49  // Create the buttons
50  // ... add
51  pqPushButtonAdd = new QPushButton( QIcon( ":icons/32x32/add.png" ), "" );
52  pqPushButtonAdd->setToolTip( tr("Create a new landmarks set") );
53  pqPushButtonAdd->setMaximumSize( 36, 34 );
54  QWidget::connect( pqPushButtonAdd, SIGNAL( clicked() ), this, SLOT( slotAdd() ) );
55  // ... load
56  pqPushButtonLoad = new QPushButton( QIcon( ":icons/32x32/load.png" ), "" );
57  pqPushButtonLoad->setToolTip( tr("Load landmarks set from disk") );
58  pqPushButtonLoad->setMaximumSize( 36, 34 );
59  QWidget::connect( pqPushButtonLoad, SIGNAL( clicked() ), this, SLOT( slotLoad() ) );
60  // ... up
61  pqPushButtonUp = new QPushButton( QIcon( ":icons/32x32/move_up.png" ), "" );
62  pqPushButtonUp->setToolTip( tr("[landmarks set/landmark] Move up") );
63  pqPushButtonUp->setMaximumSize( 36, 34 );
64  QWidget::connect( pqPushButtonUp, SIGNAL( clicked() ), this, SLOT( slotUp() ) );
65  // ... down
66  pqPushButtonDown = new QPushButton( QIcon( ":icons/32x32/move_down.png" ), "" );
67  pqPushButtonDown->setToolTip( tr("[landmarks set/landmark] Move down") );
68  pqPushButtonDown->setMaximumSize( 36, 34 );
69  QWidget::connect( pqPushButtonDown, SIGNAL( clicked() ), this, SLOT( slotDown() ) );
70  // ... actions
71  pqPushButtonActions = new QPushButton( QIcon( ":icons/32x32/more.png" ), "" );
72  pqPushButtonActions->setToolTip( tr("Additional actions")+"..." );
73  pqPushButtonActions->setMaximumSize( 36, 34 );
74  QWidget::connect( pqPushButtonActions, SIGNAL( clicked() ), this, SLOT( slotActions() ) );
75 
76  // Create layout
77  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
78 
79  // Add the overlay/tree
80  __pqVBoxLayout->addWidget( poLandmarkOverlay, 1 );
81 
82  // Add separator
83  QFrame* __pqFrameSeparator = new QFrame();
84  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
85  __pqVBoxLayout->addWidget( __pqFrameSeparator );
86 
87  // Add buttons
88  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
89  __pqHBoxLayoutButtons->addWidget( pqPushButtonAdd, 0, Qt::AlignLeft );
90  __pqHBoxLayoutButtons->addWidget( pqPushButtonLoad, 1, Qt::AlignLeft );
91  __pqHBoxLayoutButtons->addWidget( pqPushButtonUp, 0, Qt::AlignHCenter );
92  __pqHBoxLayoutButtons->addWidget( pqPushButtonDown, 0, Qt::AlignHCenter );
93  __pqHBoxLayoutButtons->addWidget( pqPushButtonActions, 1, Qt::AlignRight );
94  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
95 
96  // Set the layout
97  QWidget::setLayout( __pqVBoxLayout );
98 
99 }
100 
101 
102 //------------------------------------------------------------------------------
103 // METHODS
104 //------------------------------------------------------------------------------
105 
106 //
107 // SLOTS
108 //
109 
111 {
112  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
113  QString __qsName = __poLandmarkOverlay->newChildName( tr("Landmarks"), 1, true );
114  CLandmarkContainer* __poLandmarkContainer = __poLandmarkOverlay->addContainer( __qsName );
115  if( !__poLandmarkContainer ) return;
116  __poLandmarkOverlay->setCurrentItem( __poLandmarkContainer );
117  __poLandmarkContainer->showEdit();
119 }
120 
122 {
123  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::OPEN, tr("Load Landmarks"), tr("GPX Files")+" (*.gpx);;"+tr("QVCT Files")+" (*.qvct)" );
124  if( __qsFilename.isEmpty() ) return;
125  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::OPEN, __qsFilename ) ) return;
126  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
127  CLandmarkContainer* __poLandmarkContainer = __poLandmarkOverlay->load( __qsFilename );
128  if( !__poLandmarkContainer ) return;
129  __poLandmarkOverlay->setCurrentItem( __poLandmarkContainer );
130  __poLandmarkOverlay->forceRedraw();
133 }
134 
136 {
137  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
138  QTreeWidgetItem* __pqTreeWidgetItem_current = __poLandmarkOverlay->currentItem();
139  if( !__pqTreeWidgetItem_current ) return;
140  switch( __pqTreeWidgetItem_current->type() )
141  {
142 
145  {
146  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
147  if( !__pqTreeWidgetItem_parent ) return;
148  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
149  if( __iIndex <= 0 ) return;
150  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
151  __pqTreeWidgetItem_parent->insertChild( __iIndex-1, __pqTreeWidgetItem_current );
152  __poLandmarkOverlay->setCurrentItem( __pqTreeWidgetItem_current );
154  }
155  break;
156 
157  default:;
158 
159  }
160 }
161 
163 {
164  CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay();
165  QTreeWidgetItem* __pqTreeWidgetItem_current = __poLandmarkOverlay->currentItem();
166  if( !__pqTreeWidgetItem_current ) return;
167  switch( __pqTreeWidgetItem_current->type() )
168  {
169 
172  {
173  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
174  if( !__pqTreeWidgetItem_parent ) return;
175  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
176  if( __iIndex >= __pqTreeWidgetItem_parent->childCount()-1 ) return;
177  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
178  __pqTreeWidgetItem_parent->insertChild( __iIndex+1, __pqTreeWidgetItem_current );
179  __poLandmarkOverlay->setCurrentItem( __pqTreeWidgetItem_current );
181  }
182  break;
183 
184  default:;
185 
186  }
187 }
188 
190 {
191  CLandmarkOverlayActionsView* __poLandmarkOverlayActionsView = new CLandmarkOverlayActionsView();
192  __poLandmarkOverlayActionsView->exec();
193  delete __poLandmarkOverlayActionsView;
194 }
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
void updateChart()
Update the (current) chart content (on screen)
[UI] Landmark overlay container
virtual void showEdit()
Displays this object's edit widget/view.
[UI] Landmark overlay's actions view
void slotAdd()
[UI:Slot] Slot to add a new container
QPushButton * pqPushButtonLoad
[UI:Button] Load
CLandmarkOverlayListView(QWidget *_pqParent=0)
void slotLoad()
[UI:Slot] Slot to load overlay's content from file
CLandmarkOverlay * poLandmarkOverlay
Landmark overlay.
QPushButton * pqPushButtonUp
[UI:Button] Up
void slotActions()
[UI:Slot] Slot to show additional actions
QPushButton * pqPushButtonActions
[UI:Button] Actions
QPushButton * pqPushButtonDown
[UI:Button] Down
QPushButton * pqPushButtonAdd
[UI:Button] Add
void slotDown()
[UI:Slot] Slot to move overlay's content down
void slotUp()
[UI:Slot] Slot to move overlay's content up
void constructLayout()
Constructs the layout of the user-interface.
[UI] Landmark overlay container
CLandmarkContainer * addContainer(const QString &_rqsName)
Add a new landmarks set (container) to this overlay.
CLandmarkContainer * load(const QString &_rqsFilename)
Load this object's content from the given file and returns the last loaded container (0 if none)
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)
@ CONTAINER
Container.
QString newChildName(const QString &_rqsName, int __iZeroPrefix=0, bool __bForceSuffix=false) const
Returns a valid name for a new sibling of this object.
Definition: COverlay.cpp:123
void forceRedraw()
Forces this overlay's rendering (not matter its cache content)
Definition: COverlay.hpp:115
static void registerLandmarkOverlay(CLandmarkOverlay *_poLandmarkOverlay)
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
static CLandmarkOverlay * useLandmarkOverlay()
@ OPEN
Definition: QVCT.hpp:42