Qt Virtual Chart Table (QVCT)
CDeviceOverlayListView.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"
28 #include "devices/CDevice.hpp"
32 
33 
34 //------------------------------------------------------------------------------
35 // CONSTRUCTORS / DESTRUCTOR
36 //------------------------------------------------------------------------------
37 
39  : QWidget( _pqParent )
40 {
42 }
43 
45 {
46  // Create the overlay/tree
49 
50  // Create the buttons
51  // ... load
52  pqPushButtonLoad = new QPushButton( QIcon( ":icons/32x32/load.png" ), "" );
53  pqPushButtonLoad->setToolTip( tr("Load device from disk") );
54  pqPushButtonLoad->setMaximumSize( 36, 34 );
55  QWidget::connect( pqPushButtonLoad, SIGNAL( clicked() ), this, SLOT( slotLoad() ) );
56  // ... add
57  pqPushButtonAdd = new QPushButton( QIcon( ":icons/32x32/add.png" ), "" );
58  pqPushButtonAdd->setToolTip( tr("Create a new device") );
59  pqPushButtonAdd->setMaximumSize( 36, 34 );
60  QWidget::connect( pqPushButtonAdd, SIGNAL( clicked() ), this, SLOT( slotAdd() ) );
61  // ... up
62  pqPushButtonUp = new QPushButton( QIcon( ":icons/32x32/move_up.png" ), "" );
63  pqPushButtonUp->setToolTip( tr("[device] Move up") );
64  pqPushButtonUp->setMaximumSize( 36, 34 );
65  QWidget::connect( pqPushButtonUp, SIGNAL( clicked() ), this, SLOT( slotUp() ) );
66  // ... down
67  pqPushButtonDown = new QPushButton( QIcon( ":icons/32x32/move_down.png" ), "" );
68  pqPushButtonDown->setToolTip( tr("[device] Move down") );
69  pqPushButtonDown->setMaximumSize( 36, 34 );
70  QWidget::connect( pqPushButtonDown, SIGNAL( clicked() ), this, SLOT( slotDown() ) );
71  // ... actions
72  pqPushButtonActions = new QPushButton( QIcon( ":icons/32x32/more.png" ), "" );
73  pqPushButtonActions->setToolTip( tr("Additional actions")+"..." );
74  pqPushButtonActions->setMaximumSize( 36, 34 );
75  QWidget::connect( pqPushButtonActions, SIGNAL( clicked() ), this, SLOT( slotActions() ) );
76 
77  // Create layout
78  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
79 
80  // Add the overlay/tree
81  __pqVBoxLayout->addWidget( poDeviceOverlay, 1 );
82 
83  // Add separator
84  QFrame* __pqFrameSeparator = new QFrame();
85  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
86  __pqVBoxLayout->addWidget( __pqFrameSeparator );
87 
88  // Add buttons
89  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
90  __pqHBoxLayoutButtons->addWidget( pqPushButtonAdd, 0, Qt::AlignLeft );
91  __pqHBoxLayoutButtons->addWidget( pqPushButtonLoad, 1, Qt::AlignLeft );
92  __pqHBoxLayoutButtons->addWidget( pqPushButtonUp, 0, Qt::AlignHCenter );
93  __pqHBoxLayoutButtons->addWidget( pqPushButtonDown, 0, Qt::AlignHCenter );
94  __pqHBoxLayoutButtons->addWidget( pqPushButtonActions, 1, Qt::AlignRight );
95  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
96 
97  // Set the layout
98  QWidget::setLayout( __pqVBoxLayout );
99 
100 }
101 
102 
103 //------------------------------------------------------------------------------
104 // METHODS
105 //------------------------------------------------------------------------------
106 
107 //
108 // SLOTS
109 //
110 
112 {
113  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::OPEN, tr("Load Device"), tr("QVCT Files")+" (*.qvct)" );
114  if( __qsFilename.isEmpty() ) return;
115  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::OPEN, __qsFilename ) ) return;
116  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
117  CDevice* __poDevice = __poDeviceOverlay->load( __qsFilename );
118  if( !__poDevice ) return;
119  __poDeviceOverlay->setCurrentItem( __poDevice );
121 }
122 
124 {
125  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
126  CDevice* __poDevice = 0;
127  CDeviceCreateView* __poDeviceCreateView = new CDeviceCreateView( &__poDevice );
128  __poDeviceCreateView->exec();
129  if( __poDevice )
130  {
131  __poDeviceOverlay->addChild( __poDevice );
132  __poDeviceOverlay->setCurrentItem( __poDevice );
133  __poDevice->showEdit();
135  }
136  delete __poDeviceCreateView;
137 }
138 
140 {
141  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
142  QTreeWidgetItem* __pqTreeWidgetItem_current = __poDeviceOverlay->currentItem();
143  if( !__pqTreeWidgetItem_current ) return;
144  switch( __pqTreeWidgetItem_current->type() )
145  {
146 
148  {
149  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
150  if( !__pqTreeWidgetItem_parent ) return;
151  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
152  if( __iIndex <= 0 ) return;
153  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
154  __pqTreeWidgetItem_parent->insertChild( __iIndex-1, __pqTreeWidgetItem_current );
155  __poDeviceOverlay->setCurrentItem( __pqTreeWidgetItem_current );
157  }
158  break;
159 
160  default:;
161 
162  }
163 }
164 
166 {
167  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
168  QTreeWidgetItem* __pqTreeWidgetItem_current = __poDeviceOverlay->currentItem();
169  if( !__pqTreeWidgetItem_current ) return;
170  switch( __pqTreeWidgetItem_current->type() )
171  {
172 
174  {
175  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
176  if( !__pqTreeWidgetItem_parent ) return;
177  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
178  if( __iIndex >= __pqTreeWidgetItem_parent->childCount()-1 ) return;
179  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
180  __pqTreeWidgetItem_parent->insertChild( __iIndex+1, __pqTreeWidgetItem_current );
181  __poDeviceOverlay->setCurrentItem( __pqTreeWidgetItem_current );
183  }
184  break;
185 
186  default:;
187 
188  }
189 }
190 
192 {
193  CDeviceOverlayActionsView* __poDeviceOverlayActionsView = new CDeviceOverlayActionsView();
194  __poDeviceOverlayActionsView->exec();
195  delete __poDeviceOverlayActionsView;
196 }
void setProjectModified()
Sets the status of the project to modified (data have changed and need saving)
[UI] Generic overlay object's pick (select) view
[UI] Device overlay's actions view
QPushButton * pqPushButtonActions
[UI:Button] Actions
QPushButton * pqPushButtonLoad
[UI:Button] Load
QPushButton * pqPushButtonAdd
[UI:Button] Add
void constructLayout()
Constructs the layout of the user-interface.
void slotActions()
[UI:Slot] Slot to show additional actions
QPushButton * pqPushButtonUp
[UI:Button] Up
void slotDown()
[UI:Slot] Slot to move overlay's content down
QPushButton * pqPushButtonDown
[UI:Button] Down
void slotAdd()
[UI:Slot] Slot to add a new container
CDeviceOverlay * poDeviceOverlay
Device overlay.
void slotLoad()
[UI:Slot] Slot to load overlay's content from file
CDeviceOverlayListView(QWidget *_pqParent=0)
void slotUp()
[UI:Slot] Slot to move overlay's content up
[UI] Device overlay container
CDevice * load(const QString &_rqsFilename, bool _bSilent=false)
Load this object's content from the given file and returns the last loaded device (0 if none)
Generic navigation device (GPS, speedometer, compass, etc.)
Definition: CDevice.hpp:43
virtual void showEdit()=0
Displays the device's edit (configuration) 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)
static CDeviceOverlay * useDeviceOverlay()
static void registerDeviceOverlay(CDeviceOverlay *_poDeviceOverlay)
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
@ OPEN
Definition: QVCT.hpp:42