Qt Virtual Chart Table (QVCT)
CDeviceTcpSbs1EditView.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 <QCheckBox>
21 #include <QDialogButtonBox>
22 #include <QFormLayout>
23 #include <QHBoxLayout>
24 #include <QLabel>
25 #include <QLineEdit>
26 #include <QVBoxLayout>
27 
28 // QVCT
29 #include "QVCTRuntime.hpp"
33 
34 
35 //------------------------------------------------------------------------------
36 // CONSTRUCTORS / DESTRUCTOR
37 //------------------------------------------------------------------------------
38 
40  : COverlayObjectEditView( _poDeviceTcpSbs1 )
41 {
43 }
44 
46 {
47  // Create layout
48  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
49 
50  // Add header
51  QFont __qFontHeader;
52  __qFontHeader.setPixelSize( 16 );
53  __qFontHeader.setBold( true );
54  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
55  QLabel* __pqLabelIcon = new QLabel();
56  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/device.png" ) );
57  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
58  QLabel* __pqLabelEdit = new QLabel( tr("Edit")+"..." );
59  __pqLabelEdit->setFont( __qFontHeader );
60  __pqHBoxLayoutHeader->addWidget( __pqLabelEdit, 1 );
61  // ... [end]
62  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
63 
64  // Add data
65  CDeviceTcpSbs1* __poDeviceTcpSbs1 = (CDeviceTcpSbs1*)poOverlayObject;
66  QFormLayout* __pqFormLayout = new QFormLayout();
67  // ... name
68  COverlayText* __poTextName = new COverlayText();
69  __poTextName->setText( __poDeviceTcpSbs1->getName() );
70  __pqFormLayout->addRow( tr("Name")+":", __poTextName );
71  // ... host
72  pqLineEditHost = new QLineEdit();
73  pqLineEditHost->setToolTip( tr("SBS-1 service host (hostname or IP address)") );
74  pqLineEditHost->setText( __poDeviceTcpSbs1->getHost() );
75  __pqFormLayout->addRow( tr("Host")+":", pqLineEditHost );
76  // ... port
77  pqLineEditPort = new QLineEdit();
78  pqLineEditPort->setToolTip( tr("SBS-1 service port") );
79  pqLineEditPort->setText( QString::number( __poDeviceTcpSbs1->getPort() ) );
80  __pqFormLayout->addRow( tr("Port")+":", pqLineEditPort );
81  // ... time zone
82  pqComboBoxTimeZone = new QComboBox();
83  pqComboBoxTimeZone->setToolTip( tr("Whether this SBS-1 service uses UTC or local date/time data") );
84  pqComboBoxTimeZone->addItems( QStringList( CUnitTimeZone::symbols().values() ) );
85  pqComboBoxTimeZone->setCurrentIndex( pqComboBoxTimeZone->findText( CUnitTimeZone::toSymbol( __poDeviceTcpSbs1->getTimeZone() ) ) );
86  __pqFormLayout->addRow( tr("Time Zone")+":", pqComboBoxTimeZone );
87  // ... callsign lookup
88  pqCheckBoxCallsignLookup = new QCheckBox();
89  pqCheckBoxCallsignLookup->setToolTip( tr("Whether to perform aircrafts callsign lookup (based on previous ad-hoc SBS-1 messages)\nor display the aircrafts hexadecimal identifier") );
90  pqCheckBoxCallsignLookup->setCheckState( __poDeviceTcpSbs1->isCallsignLookup() ? Qt::Checked : Qt::Unchecked );
91  __pqFormLayout->addRow( tr("Use Callsign")+":", pqCheckBoxCallsignLookup );
92  // ... ground traffic (inclusion/track)
93  pqCheckBoxGroundTraffic = new QCheckBox();
94  pqCheckBoxGroundTraffic->setToolTip( tr("Whether to listen for and display ground traffic") );
95  pqCheckBoxGroundTraffic->setCheckState( __poDeviceTcpSbs1->isGroundTraffic() ? Qt::Checked : Qt::Unchecked );
96  __pqFormLayout->addRow( tr("Ground Traffic")+":", pqCheckBoxGroundTraffic );
97  // ... [end]
98  __pqVBoxLayout->addLayout( __pqFormLayout );
99 
100  // Add buttons
101  QDialogButtonBox* __pqDialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal );
102  QDialog::connect( __pqDialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()) );
103  QDialog::connect( __pqDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()) );
104  __pqVBoxLayout->addWidget( __pqDialogButtonBox );
105 
106  // Set the layout
107  COverlayObjectEditView::setLayout( __pqVBoxLayout );
108 
109 }
110 
111 
112 //------------------------------------------------------------------------------
113 // METHODS: QDialog (override)
114 //------------------------------------------------------------------------------
115 
117 {
118  CDeviceTcpSbs1* __poDeviceTcpSbs1 = (CDeviceTcpSbs1*)poOverlayObject;
119 
120  // Check data
121  bool __bOK;
122  int __iPort = -1;
123  __iPort = pqLineEditPort->text().toInt( &__bOK );
124  if( !__bOK || __iPort <= 0 || __iPort > 65535 )
125  {
127  return;
128  }
129 
130  // Set data
131  __poDeviceTcpSbs1->setOperatingMode( CDevice::STOP );
132  // ... host
133  __poDeviceTcpSbs1->setHost( pqLineEditHost->text() );
134  // ... port
135  __poDeviceTcpSbs1->setPort( __iPort );
136  // ... time zone
137  __poDeviceTcpSbs1->setTimeZone( CUnitTimeZone::fromSymbol( pqComboBoxTimeZone->currentText() ) );
138  // ... callsign lookup
139  __poDeviceTcpSbs1->setCallsignLookup( pqCheckBoxCallsignLookup->checkState() == Qt::Checked );
140  // ... ground traffic (inclusion/track)
141  __poDeviceTcpSbs1->setGroundTraffic( pqCheckBoxGroundTraffic->checkState() == Qt::Checked );
142 
143  // Done
144  QDialog::accept();
145 }
QLineEdit * pqLineEditPort
[UI:LineEdit] Port
void constructLayout()
Constructs the layout of the user-interface.
QLineEdit * pqLineEditHost
[UI:LineEdit] Host
QCheckBox * pqCheckBoxGroundTraffic
[UI:CheckBox] Ground traffic
CDeviceTcpSbs1EditView(CDeviceTcpSbs1 *_poDeviceTcpSbs1)
QComboBox * pqComboBoxTimeZone
[UI:ComboBox] Time zone
QCheckBox * pqCheckBoxCallsignLookup
[UI:CheckBox] Callsign lookup
SBS-1 protocol (TCP socket) navigation device.
void setPort(int _iPort)
void setGroundTraffic(bool _bGroundTraffic)
void setHost(const QString &_rqsHost)
CUnitTimeZone::EUnit getTimeZone()
void setTimeZone(CUnitTimeZone::EUnit _eTimeZone)
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
void setCallsignLookup(bool _bCallsignLookup)
@ STOP
Definition: CDevice.hpp:58
void parseError(const QString &_rqsString)
Displays a generic error message for an invalid parsing operation.
[UI] Generic overlay object's edit view
const COverlayObject * poOverlayObject
Overlay object being edited.
QString getName() const
Returns this object's name.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
static EUnit fromSymbol(const QString &_rqsSymbol)
Returns the format/unit ID corresponding to the given human-readable symbol.
static QString toSymbol(EUnit _eUnit)
Returns the human-readable symbol corresponding to the given format/unit ID.
static const QMap< EUnit, QString > & symbols()
Returns the list of supported human-readable format/unit symbols.
static CMainWindow * useMainWindow()