Qt Virtual Chart Table (QVCT)
CDeviceGpsdGpsEditView.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( _poDeviceGpsdGps )
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  CDeviceGpsdGps* __poDeviceGpsdGps = (CDeviceGpsdGps*)poOverlayObject;
65  QFormLayout* __pqFormLayout = new QFormLayout();
66  // ... name
67  COverlayText* __poTextName = new COverlayText();
68  __poTextName->setText( __poDeviceGpsdGps->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( __poDeviceGpsdGps->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( __poDeviceGpsdGps->getPort() ) );
79  __pqFormLayout->addRow( tr("Port")+":", pqLineEditPort );
80  // ... source
81  pqLineEditSource = new QLineEdit();
82  pqLineEditSource->setToolTip( tr("GPS daemon source (device pathname) filter (exact match)") );
83  pqLineEditSource->setText( __poDeviceGpsdGps->getSource() );
84  __pqFormLayout->addRow( tr("Source")+":", pqLineEditSource );
85  // ... [end]
86  __pqVBoxLayout->addLayout( __pqFormLayout );
87 
88  // Add buttons
89  QDialogButtonBox* __pqDialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal );
90  QDialog::connect( __pqDialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()) );
91  QDialog::connect( __pqDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()) );
92  __pqVBoxLayout->addWidget( __pqDialogButtonBox );
93 
94  // Set the layout
95  COverlayObjectEditView::setLayout( __pqVBoxLayout );
96 
97 }
98 
99 
100 //------------------------------------------------------------------------------
101 // METHODS: QDialog (override)
102 //------------------------------------------------------------------------------
103 
105 {
106  CDeviceGpsdGps* __poDeviceGpsdGps = (CDeviceGpsdGps*)poOverlayObject;
107 
108  // Check data
109  bool __bOK;
110  int __iPort = -1;
111  __iPort = pqLineEditPort->text().toInt( &__bOK );
112  if( !__bOK || __iPort <= 0 || __iPort > 65535 )
113  {
115  return;
116  }
117 
118  // Set data
119  __poDeviceGpsdGps->setOperatingMode( CDevice::STOP );
120  // ... host
121  __poDeviceGpsdGps->setHost( pqLineEditHost->text() );
122  // ... port
123  __poDeviceGpsdGps->setPort( __iPort );
124  // ... source
125  __poDeviceGpsdGps->setSource( pqLineEditSource->text() );
126 
127  // Done
128  QDialog::accept();
129 }
QLineEdit * pqLineEditPort
[UI:LineEdit] Port
QLineEdit * pqLineEditSource
[UI:LineEdit] Source
CDeviceGpsdGpsEditView(CDeviceGpsdGps *_poDeviceGpsdGps)
void constructLayout()
Constructs the layout of the user-interface.
QLineEdit * pqLineEditHost
[UI:LineEdit] Host
GPSD daemon (GPS mode) navigation device.
void setPort(int _iPort)
void setHost(const QString &_rqsHost)
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
void setSource(const QString &_rqsSource)
@ 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()