Qt Virtual Chart Table (QVCT)
CVesselOverlayListView.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 flotilla") );
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 flotilla 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("[flotilla/vessel] 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("[flotilla/vessel] 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( poVesselOverlay, 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  CVesselOverlay* __poVesselOverlay = QVCTRuntime::useVesselOverlay();
113  QString __qsName = __poVesselOverlay->newChildName( tr("Flotilla"), 1, true );
114  CVesselContainer* __poVesselContainer = __poVesselOverlay->addContainer( __qsName );
115  if( !__poVesselContainer ) return;
116  __poVesselOverlay->setCurrentItem( __poVesselContainer );
117  __poVesselContainer->showEdit();
119 }
120 
122 {
123  QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::OPEN, tr("Load Vessel"), tr("QVCT Files")+" (*.qvct)" );
124  if( __qsFilename.isEmpty() ) return;
125  if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::OPEN, __qsFilename ) ) return;
126  CVesselOverlay* __poVesselOverlay = QVCTRuntime::useVesselOverlay();
127  CVesselContainer* __poVesselContainer = __poVesselOverlay->load( __qsFilename );
128  if( !__poVesselContainer ) return;
129  __poVesselOverlay->setCurrentItem( __poVesselContainer );
130  __poVesselOverlay->forceRedraw();
133 }
134 
136 {
137  CVesselOverlay* __poVesselOverlay = QVCTRuntime::useVesselOverlay();
138  QTreeWidgetItem* __pqTreeWidgetItem_current = __poVesselOverlay->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  bool __bDynamic = __pqTreeWidgetItem_current->type() == COverlayObject::ITEM
149  ? ((CVesselContainer*)__pqTreeWidgetItem_parent)->isDynamic() : false;
150  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
151  if( __iIndex <= __bDynamic ? 1 : 0 ) return;
152  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
153  __pqTreeWidgetItem_parent->insertChild( __iIndex-1, __pqTreeWidgetItem_current );
154  __poVesselOverlay->setCurrentItem( __pqTreeWidgetItem_current );
155  if( __pqTreeWidgetItem_current->type() == COverlayObject::ITEM )
156  {
157  __poVesselOverlay->forceRedraw();
159  }
160  if( !__bDynamic ) QVCTRuntime::useChartTable()->setProjectModified();
161  }
162  break;
163 
164  default:;
165 
166  }
167 }
168 
170 {
171  CVesselOverlay* __poVesselOverlay = QVCTRuntime::useVesselOverlay();
172  QTreeWidgetItem* __pqTreeWidgetItem_current = __poVesselOverlay->currentItem();
173  if( !__pqTreeWidgetItem_current ) return;
174  switch( __pqTreeWidgetItem_current->type() )
175  {
176 
179  {
180  QTreeWidgetItem* __pqTreeWidgetItem_parent = __pqTreeWidgetItem_current->parent();
181  if( !__pqTreeWidgetItem_parent ) return;
182  bool __bDynamic = __pqTreeWidgetItem_current->type() == COverlayObject::ITEM
183  ? ((CVesselContainer*)__pqTreeWidgetItem_parent)->isDynamic() : false;
184  int __iIndex = __pqTreeWidgetItem_parent->indexOfChild( __pqTreeWidgetItem_current );
185  if( __iIndex >= __pqTreeWidgetItem_parent->childCount()-1 ) return;
186  __pqTreeWidgetItem_parent->removeChild( __pqTreeWidgetItem_current );
187  __pqTreeWidgetItem_parent->insertChild( __iIndex+1, __pqTreeWidgetItem_current );
188  __poVesselOverlay->setCurrentItem( __pqTreeWidgetItem_current );
189  if( __pqTreeWidgetItem_current->type() == COverlayObject::ITEM )
190  {
191  __poVesselOverlay->forceRedraw();
193  }
194  if( !__bDynamic ) QVCTRuntime::useChartTable()->setProjectModified();
195  }
196  break;
197 
198  default:;
199 
200  }
201 }
202 
204 {
205  CVesselOverlayActionsView* __poVesselOverlayActionsView = new CVesselOverlayActionsView();
206  __poVesselOverlayActionsView->exec();
207  delete __poVesselOverlayActionsView;
208 }
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] Vessel overlay container / flotilla
virtual void showEdit()
Displays this object's edit widget/view.
[UI] Vessel overlay's actions view
void slotActions()
[UI:Slot] Slot to show additional actions
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonLoad
[UI:Button] Load
void slotDown()
[UI:Slot] Slot to move overlay's content down
void slotLoad()
[UI:Slot] Slot to load overlay's content from file
void slotAdd()
[UI:Slot] Slot to add a new container
QPushButton * pqPushButtonActions
[UI:Button] Actions
QPushButton * pqPushButtonAdd
[UI:Button] Add
QPushButton * pqPushButtonUp
[UI:Button] Up
QPushButton * pqPushButtonDown
[UI:Button] Down
void slotUp()
[UI:Slot] Slot to move overlay's content up
CVesselOverlayListView(QWidget *_pqParent=0)
CVesselOverlay * poVesselOverlay
Vessel overlay.
[UI] Vessel overlay container
CVesselContainer * addContainer(const QString &_rqsName)
Add a new vessel (container) to this overlay.
CVesselContainer * load(const QString &_rqsFilename)
Load this object's content from the given file and returns the last loaded container (0 if none)
static void registerVesselOverlay(CVesselOverlay *_poVesselOverlay)
static CVesselOverlay * useVesselOverlay()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()
@ OPEN
Definition: QVCT.hpp:42