Qt Virtual Chart Table (QVCT)
CVesselContainerDeviceDetailView.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 <QLabel>
22 #include <QPushButton>
23 #include <QScrollArea>
24 #include <QStackedWidget>
25 #include <QVBoxLayout>
26 #include <QWidget>
27 
28 // QVCT
29 #include "QVCTRuntime.hpp"
34 
35 
36 //------------------------------------------------------------------------------
37 // CONSTRUCTORS / DESTRUCTOR
38 //------------------------------------------------------------------------------
39 
41  : COverlayObjectDetailView( _pqParent )
42  , bIgnoreUpdate( true )
43 {
45 }
46 
48 {
49  // Create the buttons
50  // ... edit
51  pqPushButtonEdit = new QPushButton( QIcon( ":icons/32x32/edit.png" ), "" );
52  pqPushButtonEdit->setToolTip( tr("Edit this device") );
53  pqPushButtonEdit->setMaximumSize( 36, 34 );
54  pqPushButtonEdit->setEnabled( false );
55  QWidget::connect( pqPushButtonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
56  // ... delete
57  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
58  pqPushButtonDelete->setToolTip( tr("Delete this device") );
59  pqPushButtonDelete->setMaximumSize( 36, 34 );
60  pqPushButtonDelete->setEnabled( false );
61  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
62  // ... connect (device)
63  pqPushButtonConnect = new QPushButton( QIcon( ":icons/32x32/device_disconnect.png" ), "" );
64  pqPushButtonConnect->setToolTip( tr("Connect to the actual device/source") );
65  pqPushButtonConnect->setMaximumSize( 36, 34 );
66  pqPushButtonConnect->setEnabled( false );
67  pqPushButtonConnect->setCheckable( true );
68  QWidget::connect( pqPushButtonConnect, SIGNAL( toggled(bool) ), this, SLOT( slotConnect(bool) ) );
69 
70  // Create layout
71  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
72 
73  // Add header
74  QFont __qFontHeader;
75  __qFontHeader.setPixelSize( 16 );
76  __qFontHeader.setBold( true );
77  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
78  QLabel* __pqLabelIcon = new QLabel();
79  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/vessel_device.png" ) );
80  __pqLabelIcon->setToolTip( tr("Device") );
81  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
82  poTextName = new COverlayText();
83  poTextName->setToolTip( tr("Name/Source") );
84  poTextName->setFont( __qFontHeader );
85  poTextName->setWordWrap( true );
86  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
87  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
88 
89  // Add data
90  QFont __qFontData;
91  QTabWidget* __poTabWidget = new QTabWidget();
92  __poTabWidget->setTabPosition( QTabWidget::South );
93 
94  // ... device
95  QWidget* __poWidgetText = new QWidget();
96  QVBoxLayout* __pqVBoxLayoutText = new QVBoxLayout();
97  __qFontData.setPixelSize( 12 );
98  QLabel* __pqLabel = new QLabel();
99  __pqLabel->setToolTip( tr("Dynamic Flotilla Device") );
100  __pqLabel->setFont( __qFontData );
101  __pqLabel->setIndent( 10 );
102  __pqLabel->setWordWrap( true );
103  __pqLabel->setText( tr("This device is used to dynamically create vessels as they appear \"on the wire\"") );
104  __pqVBoxLayoutText->addWidget( __pqLabel );
105  __poWidgetText->setLayout( __pqVBoxLayoutText );
106  __poTabWidget->addTab( __poWidgetText, tr("Device") );
107 
108  // ... [end]
109  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
110 
111  // Add separator
112  QFrame* __pqFrameSeparator = new QFrame();
113  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
114  __pqVBoxLayout->addWidget( __pqFrameSeparator );
115 
116  // Add buttons
117  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
118  __pqHBoxLayoutButtons->addWidget( pqPushButtonEdit, 0, Qt::AlignLeft );
119  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 1, Qt::AlignLeft );
120  __pqHBoxLayoutButtons->addWidget( pqPushButtonConnect, 1, Qt::AlignRight );
121  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
122 
123  // Set the layout
124  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
125 
126 }
127 
128 
129 //------------------------------------------------------------------------------
130 // METHODS: COverlayObjectDetailView (implement/override)
131 //------------------------------------------------------------------------------
132 
134 {
135  if( !poOverlayObject ) return;
136  CVesselContainerDevice* __poVesselContainerDevice = (CVesselContainerDevice*)poOverlayObject;
137  poTextName->setText( __poVesselContainerDevice->getName() + " (TTL:"+QString::number(__poVesselContainerDevice->getTTL())+")" );
138 
139  // ... buttons
140  bIgnoreUpdate = true;
141  bool __bConnected = __poVesselContainerDevice->isDeviceConnected();
142  pqPushButtonConnect->setChecked( __bConnected );
143  pqPushButtonConnect->setIcon( QIcon( __bConnected ? ":icons/32x32/device_connect.png" : ":icons/32x32/device_disconnect.png" ) );
144  bIgnoreUpdate = false;
145 }
146 
148 {
150 }
151 
153 {
154  if( poOverlayObject )
155  {
156  pqPushButtonEdit->setEnabled( true );
157  pqPushButtonDelete->setEnabled( true );
158  pqPushButtonConnect->setEnabled( true );
159  QObject::connect( (CVesselContainerDevice*)poOverlayObject, SIGNAL( signalRefreshContent() ), this, SLOT( slotRefreshContent() ) );
160  bIgnoreUpdate = false;
161  }
162 }
163 
165 {
166  if( poOverlayObject ) QObject::disconnect( (CVesselContainerDevice*)poOverlayObject, 0, this, 0 );
167  pqPushButtonEdit->setEnabled( false );
168  pqPushButtonDelete->setEnabled( false );
169  pqPushButtonConnect->setEnabled( false );
170  bIgnoreUpdate = true;
171 }
172 
173 
174 //------------------------------------------------------------------------------
175 // METHODS
176 //------------------------------------------------------------------------------
177 
178 //
179 // SLOTS
180 //
181 
183 {
184  refreshContent();
185 }
186 
188 {
189  if( !poOverlayObject ) return;
190  ((CVesselContainerDevice*)poOverlayObject)->showEdit();
191 }
192 
194 {
195  if( !poOverlayObject ) return;
196  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
197  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
198  __pqMutexDataChange->lock();
199  CVesselOverlay* __poVesselOverlay = QVCTRuntime::useVesselOverlay();
200  CVesselContainer* __poVesselContainer = (CVesselContainer*)((QTreeWidgetItem*)poOverlayObject)->parent();
201  __poVesselContainer->clearDevice();
202  QTreeWidgetItem* __pqTreeWidgetItem = __poVesselOverlay->currentItem();
203  if( __pqTreeWidgetItem ) __poVesselOverlay->showDetail( __pqTreeWidgetItem );
204  __poVesselOverlay->forceRedraw();
206  __pqMutexDataChange->unlock();
207 }
208 
210 {
211  if( !poOverlayObject || bIgnoreUpdate ) return;
212  CVesselContainerDevice* __poVesselContainerDevice = (CVesselContainerDevice*)poOverlayObject;
213  if( _bConnect ) __poVesselContainerDevice->connectDevice();
214  else __poVesselContainerDevice->disconnectDevice();
215  refreshContent();
216 }
void updateChart()
Update the (current) chart content (on screen)
[UI] Generic overlay object's detail view
COverlayObject * poOverlayObject
Overlay object being displayed.
QString getName() const
Returns this object's name.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
void resetText()
Resets (clears) the underlying QLabel's text.
void forceRedraw()
Forces this overlay's rendering (not matter its cache content)
Definition: COverlay.hpp:115
void slotRefreshContent()
[UI:Slot] Slot to refresh the view content
virtual void resetContent()
Resets (clears) the content of the underlying widget.
QPushButton * pqPushButtonConnect
[UI:Button] Connect (device)
bool bIgnoreUpdate
Flag that disables checkable buttons update.
void slotEdit()
[UI:Slot] Slot to display edit view
virtual void disableContent()
Disables the content (controls) of the underlying widget.
void slotDelete()
[UI:Slot] Slot to delete (this container/container)
virtual void enableContent()
Enables the content (controls) of the underlying widget.
virtual void refreshContent()
Refreshes the content of the underlying widget.
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonDelete
[UI:Button] Delete
void slotConnect(bool)
[UI:Slot] Slot to connect (to the actual device)
int getTTL() const
Returns the (vessels) time-to-live.
bool connectDevice()
Connects to the actual device.
bool isDeviceConnected() const
Returns whether the actual device is connected.
void disconnectDevice()
Dicconnects from the actual device.
[UI] Vessel overlay container / flotilla
void clearDevice()
Clears the device set to dynamically generate this flotilla.
[UI] Vessel overlay container
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
static CVesselOverlay * useVesselOverlay()
static QMutex * useMutexDataChange()
static CMainWindow * useMainWindow()
static CChartTable * useChartTable()