Qt Virtual Chart Table (QVCT)
CTrackOverlayListView.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 (dummy)
51  QPushButton* __pqPushButtonAdd = new QPushButton( QIcon( ":icons/32x32/add.png" ), "" );
52  __pqPushButtonAdd->setMaximumSize( 36, 34 );
53  __pqPushButtonAdd->setEnabled( false );
54  // ... load
55  pqPushButtonLoad = new QPushButton( QIcon( ":icons/32x32/load.png" ), "" );
56  pqPushButtonLoad->setToolTip( tr("Load track from disk") );
57  pqPushButtonLoad->setMaximumSize( 36, 34 );
58  QWidget::connect( pqPushButtonLoad, SIGNAL( clicked() ), this, SLOT( slotLoad() ) );
59  // ... up
60  pqPushButtonUp = new QPushButton( QIcon( ":icons/32x32/move_up.png" ), "" );
61  pqPushButtonUp->setToolTip( tr("[track] Move up") );
62  pqPushButtonUp->setMaximumSize( 36, 34 );
63  QWidget::connect( pqPushButtonUp, SIGNAL( clicked() ), this, SLOT( slotUp() ) );
64  // ... down
65  pqPushButtonDown = new QPushButton( QIcon( ":icons/32x32/move_down.png" ), "" );
66  pqPushButtonDown->setToolTip( tr("[track] Move down") );
67  pqPushButtonDown->setMaximumSize( 36, 34 );
68  QWidget::connect( pqPushButtonDown, SIGNAL( clicked() ), this, SLOT( slotDown() ) );
69  // ... actions
70  pqPushButtonActions = new QPushButton( QIcon( ":icons/32x32/more.png" ), "" );
71  pqPushButtonActions->setToolTip( tr("Additional actions")+"..." );
72  pqPushButtonActions->setMaximumSize( 36, 34 );
73  QWidget::connect( pqPushButtonActions, SIGNAL( clicked() ), this, SLOT( slotActions() ) );
74 
75  // Create layout
76  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
77 
78  // Add the overlay/tree
79  __pqVBoxLayout->addWidget( poTrackOverlay, 1 );
80 
81  // Add separator
82  QFrame* __pqFrameSeparator = new QFrame();
83  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
84  __pqVBoxLayout->addWidget( __pqFrameSeparator );
85 
86  // Add buttons
87  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
88  __pqHBoxLayoutButtons->addWidget( __pqPushButtonAdd, 0, Qt::AlignLeft );
89  __pqHBoxLayoutButtons->addWidget( pqPushButtonLoad, 1, Qt::AlignLeft );
90  __pqHBoxLayoutButtons->addWidget( pqPushButtonUp, 0, Qt::AlignHCenter );
91  __pqHBoxLayoutButtons->addWidget( pqPushButtonDown, 0, Qt::AlignHCenter );
92  __pqHBoxLayoutButtons->addWidget( pqPushButtonActions, 1, Qt::AlignRight );
93  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
94 
95  // Set the layout
96  QWidget::setLayout( __pqVBoxLayout );
97 
98 }
99 
100 
101 //------------------------------------------------------------------------------
102 // METHODS
103 //------------------------------------------------------------------------------
104 
105 //
106 // SLOTS
107 //
108 
110 {
111  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::OPEN, tr("Load Track"), tr("GPX Files")+" (*.gpx);;"+tr("QVCT Files")+" (*.qvct)" );
112  if( __qsFilename.isEmpty() ) return;
113  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::OPEN, __qsFilename ) ) return;
114  CTrackOverlay* __poTrackOverlay = QVCTRuntime::useTrackOverlay();
115  CTrackContainer* __poTrackContainer = __poTrackOverlay->load( __qsFilename );
116  if( !__poTrackContainer ) return;
117  __poTrackOverlay->setCurrentItem( __poTrackContainer );
118  __poTrackOverlay->forceRedraw();
121 }
122 
124 {
125  CTrackOverlay* __poTrackOverlay = QVCTRuntime::useTrackOverlay();
126  QTreeWidgetItem* __pqTreeWidgetItem_current = __poTrackOverlay->currentItem();
127  if( !__pqTreeWidgetItem_current ) return;
128  switch( __pqTreeWidgetItem_current->type() )
129  {
130 
132  {
133  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
134  if( !__pqTreeWidgetItem_parent ) return;
135  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
136  if( __iIndex <= 0 ) return;
137  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
138  __pqTreeWidgetItem_parent->insertChild( __iIndex-1, __pqTreeWidgetItem_current );
139  __poTrackOverlay->setCurrentItem( __pqTreeWidgetItem_current );
140  if( __pqTreeWidgetItem_current->type() == COverlayObject::ITEM )
141  {
142  __poTrackOverlay->forceRedraw();
144  }
146  }
147  break;
148 
149  default:;
150 
151  }
152 }
153 
155 {
156  CTrackOverlay* __poTrackOverlay = QVCTRuntime::useTrackOverlay();
157  QTreeWidgetItem* __pqTreeWidgetItem_current = __poTrackOverlay->currentItem();
158  if( !__pqTreeWidgetItem_current ) return;
159  switch( __pqTreeWidgetItem_current->type() )
160  {
161 
163  {
164  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
165  if( !__pqTreeWidgetItem_parent ) return;
166  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
167  if( __iIndex >= __pqTreeWidgetItem_parent->childCount()-1 ) return;
168  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
169  __pqTreeWidgetItem_parent->insertChild( __iIndex+1, __pqTreeWidgetItem_current );
170  __poTrackOverlay->setCurrentItem( __pqTreeWidgetItem_current );
171  if( __pqTreeWidgetItem_current->type() == COverlayObject::ITEM )
172  {
173  __poTrackOverlay->forceRedraw();
175  }
177  }
178  break;
179 
180  default:;
181 
182  }
183 }
184 
186 {
187  CTrackOverlayActionsView* __poTrackOverlayActionsView = new CTrackOverlayActionsView();
188  __poTrackOverlayActionsView->exec();
189  delete __poTrackOverlayActionsView;
190 }
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.
void forceRedraw()
Forces this overlay's rendering (not matter its cache content)
Definition: COverlay.hpp:115
[UI] Track overlay container
[UI] Track overlay's actions view
void slotLoad()
[UI:Slot] Slot to load overlay's content from file
QPushButton * pqPushButtonUp
[UI:Button] Up
void slotDown()
[UI:Slot] Slot to move overlay's content down
CTrackOverlayListView(QWidget *_pqParent=0)
QPushButton * pqPushButtonDown
[UI:Button] Down
CTrackOverlay * poTrackOverlay
Track overlay.
void slotActions()
[UI:Slot] Slot to show additional actions
void constructLayout()
Constructs the layout of the user-interface.
void slotUp()
[UI:Slot] Slot to move overlay's content up
QPushButton * pqPushButtonLoad
[UI:Button] Load
QPushButton * pqPushButtonActions
[UI:Button] Actions
[UI] Track overlay container
CTrackContainer * load(const QString &_rqsFilename)
Load this object's content from the given file and returns the last loaded container (0 if none)
static void registerTrackOverlay(CTrackOverlay *_poTrackOverlay)
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
static CTrackOverlay * useTrackOverlay()
@ OPEN
Definition: QVCT.hpp:42