Qt Virtual Chart Table (QVCT)
CDeviceGpsdAisEditView.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 <QDialogButtonBox>
21 #include <QFormLayout>
22 #include <QHBoxLayout>
23 #include <QLabel>
24 #include <QLineEdit>
25 #include <QVBoxLayout>
26 
27 // QVCT
28 #include "QVCTRuntime.hpp"
32 
33 
34 //------------------------------------------------------------------------------
35 // CONSTRUCTORS / DESTRUCTOR
36 //------------------------------------------------------------------------------
37 
39  : COverlayObjectEditView( _poDeviceGpsdAis )
40 {
42 }
43 
45 {
46  // Create layout
47  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
48 
49  // Add header
50  QFont __qFontHeader;
51  __qFontHeader.setPixelSize( 16 );
52  __qFontHeader.setBold( true );
53  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
54  QLabel* __pqLabelIcon = new QLabel();
55  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/device.png" ) );
56  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
57  QLabel* __pqLabelEdit = new QLabel( tr("Edit")+"..." );
58  __pqLabelEdit->setFont( __qFontHeader );
59  __pqHBoxLayoutHeader->addWidget( __pqLabelEdit, 1 );
60  // ... [end]
61  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
62 
63  // Add data
64  CDeviceGpsdAis* __poDeviceGpsdAis = (CDeviceGpsdAis*)poOverlayObject;
65  QFormLayout* __pqFormLayout = new QFormLayout();
66  // ... name
67  COverlayText* __poTextName = new COverlayText();
68  __poTextName->setText( __poDeviceGpsdAis->getName() );
69  __pqFormLayout->addRow( tr("Name")+":", __poTextName );
70  // ... host
71  pqLineEditHost = new QLineEdit();
72  pqLineEditHost->setToolTip( tr("GPS daemon host (hostname or IP address)") );
73  pqLineEditHost->setText( __poDeviceGpsdAis->getHost() );
74  __pqFormLayout->addRow( tr("Host")+":", pqLineEditHost );
75  // ... port
76  pqLineEditPort = new QLineEdit();
77  pqLineEditPort->setToolTip( tr("GPS daemon port") );
78  pqLineEditPort->setText( QString::number( __poDeviceGpsdAis->getPort() ) );
79  __pqFormLayout->addRow( tr("Port")+":", pqLineEditPort );
80  // ... [end]
81  __pqVBoxLayout->addLayout( __pqFormLayout );
82 
83  // Add buttons
84  QDialogButtonBox* __pqDialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal );
85  QDialog::connect( __pqDialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()) );
86  QDialog::connect( __pqDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()) );
87  __pqVBoxLayout->addWidget( __pqDialogButtonBox );
88 
89  // Set the layout
90  COverlayObjectEditView::setLayout( __pqVBoxLayout );
91 
92 }
93 
94 
95 //------------------------------------------------------------------------------
96 // METHODS: QDialog (override)
97 //------------------------------------------------------------------------------
98 
100 {
101  CDeviceGpsdAis* __poDeviceGpsdAis = (CDeviceGpsdAis*)poOverlayObject;
102 
103  // Check data
104  bool __bOK;
105  int __iPort = -1;
106  __iPort = pqLineEditPort->text().toInt( &__bOK );
107  if( !__bOK || __iPort <= 0 || __iPort > 65535 )
108  {
110  return;
111  }
112 
113  // Set data
114  __poDeviceGpsdAis->setOperatingMode( CDevice::STOP );
115  // ... host
116  __poDeviceGpsdAis->setHost( pqLineEditHost->text() );
117  // ... port
118  __poDeviceGpsdAis->setPort( __iPort );
119 
120  // Done
121  QDialog::accept();
122 }
QLineEdit * pqLineEditHost
[UI:LineEdit] Host
void constructLayout()
Constructs the layout of the user-interface.
QLineEdit * pqLineEditPort
[UI:LineEdit] Port
CDeviceGpsdAisEditView(CDeviceGpsdAis *_poDeviceGpsdAis)
GPSD daemon (GPS mode) navigation device.
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
void setPort(int _iPort)
void setHost(const QString &_rqsHost)
@ 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 CMainWindow * useMainWindow()