Qt Virtual Chart Table (QVCT)
CRouteOverlayListView.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 route") );
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 route 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("[route/waypoint] 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("[route/waypoint] 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( poRouteOverlay, 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  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
113  QString __qsName = __poRouteOverlay->newChildName( tr("Route"), 1, true );
114  CRouteContainer* __poRouteContainer = __poRouteOverlay->addContainer( __qsName );
115  if( !__poRouteContainer ) return;
116  __poRouteOverlay->setCurrentItem( __poRouteContainer );
117  __poRouteContainer->showEdit();
119 }
120 
122 {
123  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::OPEN, tr("Load Route"), tr("GPX Files")+" (*.gpx);;"+tr("QVCT Files")+" (*.qvct)" );
124  if( __qsFilename.isEmpty() ) return;
125  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::OPEN, __qsFilename ) ) return;
126  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
127  CRouteContainer* __poRouteContainer = __poRouteOverlay->load( __qsFilename );
128  if( !__poRouteContainer ) return;
129  __poRouteOverlay->setCurrentItem( __poRouteContainer );
130  __poRouteOverlay->forceRedraw();
133 }
134 
136 {
137  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
138  QTreeWidgetItem* __pqTreeWidgetItem_current = __poRouteOverlay->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  __poRouteOverlay->setCurrentItem( __pqTreeWidgetItem_current );
153  if( __pqTreeWidgetItem_current->type() == COverlayObject::ITEM )
154  {
155  __poRouteOverlay->forceRedraw();
157  }
159  }
160  break;
161 
162  default:;
163 
164  }
165 }
166 
168 {
169  CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay();
170  QTreeWidgetItem* __pqTreeWidgetItem_current = __poRouteOverlay->currentItem();
171  if( !__pqTreeWidgetItem_current ) return;
172  switch( __pqTreeWidgetItem_current->type() )
173  {
174 
177  {
178  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
179  if( !__pqTreeWidgetItem_parent ) return;
180  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
181  if( __iIndex >= __pqTreeWidgetItem_parent->childCount()-1 ) return;
182  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
183  __pqTreeWidgetItem_parent->insertChild( __iIndex+1, __pqTreeWidgetItem_current );
184  __poRouteOverlay->setCurrentItem( __pqTreeWidgetItem_current );
185  if( __pqTreeWidgetItem_current->type() == COverlayObject::ITEM )
186  {
187  __poRouteOverlay->forceRedraw();
189  }
191  }
192  break;
193 
194  default:;
195 
196  }
197 }
198 
200 {
201  CRouteOverlayActionsView* __poRouteOverlayActionsView = new CRouteOverlayActionsView();
202  __poRouteOverlayActionsView->exec();
203  delete __poRouteOverlayActionsView;
204 }
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)
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
[UI] Route overlay container
virtual void showEdit()
Displays this object's edit widget/view.
[UI] Route overlay's actions view
void slotUp()
[UI:Slot] Slot to move overlay's content up
QPushButton * pqPushButtonLoad
[UI:Button] Load
void slotDown()
[UI:Slot] Slot to move overlay's content down
QPushButton * pqPushButtonActions
[UI:Button] Actions
void slotActions()
[UI:Slot] Slot to show additional actions
QPushButton * pqPushButtonDown
[UI:Button] Down
QPushButton * pqPushButtonAdd
[UI:Button] Add
void slotAdd()
[UI:Slot] Slot to add a new container
QPushButton * pqPushButtonUp
[UI:Button] Up
void constructLayout()
Constructs the layout of the user-interface.
void slotLoad()
[UI:Slot] Slot to load overlay's content from file
CRouteOverlayListView(QWidget *_pqParent=0)
CRouteOverlay * poRouteOverlay
Route overlay.
[UI] Route overlay container
CRouteContainer * load(const QString &_rqsFilename)
Load this object's content from the given file and returns the last loaded container (0 if none)
CRouteContainer * addContainer(const QString &_rqsName)
Add a new route (container) to this overlay.
static void registerRouteOverlay(CRouteOverlay *_poRouteOverlay)
static CRouteOverlay * useRouteOverlay()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
@ OPEN
Definition: QVCT.hpp:42