Qt Virtual Chart Table (QVCT)
CDeviceSampleEditView.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( _poDeviceSample )
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  CDeviceSample* __poDeviceSample = (CDeviceSample*)poOverlayObject;
65  QFormLayout* __pqFormLayout = new QFormLayout();
66  // ... name
67  COverlayText* __poTextName = new COverlayText();
68  __poTextName->setText( __poDeviceSample->getName() );
69  __pqFormLayout->addRow( tr("Name")+":", __poTextName );
70  // ... host
71  pqLineEditHost = new QLineEdit();
72  pqLineEditHost->setText( __poDeviceSample->getHost() );
73  __pqFormLayout->addRow( tr("Host")+":", pqLineEditHost );
74  // ... port
75  pqLineEditPort = new QLineEdit();
76  pqLineEditPort->setText( QString::number( __poDeviceSample->getPort() ) );
77  __pqFormLayout->addRow( tr("Port")+":", pqLineEditPort );
78  // ... [end]
79  __pqVBoxLayout->addLayout( __pqFormLayout );
80 
81  // Add buttons
82  QDialogButtonBox* __pqDialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal );
83  QDialog::connect( __pqDialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()) );
84  QDialog::connect( __pqDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()) );
85  __pqVBoxLayout->addWidget( __pqDialogButtonBox );
86 
87  // Set the layout
88  COverlayObjectEditView::setLayout( __pqVBoxLayout );
89 
90 }
91 
92 
93 //------------------------------------------------------------------------------
94 // METHODS: QDialog (override)
95 //------------------------------------------------------------------------------
96 
98 {
99  CDeviceSample* __poDeviceSample = (CDeviceSample*)poOverlayObject;
100 
101  // Check data
102  bool __bOK;
103  int __iPort = -1;
104  __iPort = pqLineEditPort->text().toInt( &__bOK );
105  if( !__bOK || __iPort <= 0 || __iPort > 65535 )
106  {
108  return;
109  }
110 
111  // Set data
112  __poDeviceSample->setOperatingMode( CDevice::STOP );
113  // ... host
114  __poDeviceSample->setHost( pqLineEditHost->text() );
115  // ... port
116  __poDeviceSample->setPort( __iPort );
117 
118  // Done
119  QDialog::accept();
120 }
void constructLayout()
Constructs the layout of the user-interface.
QLineEdit * pqLineEditPort
[UI:LineEdit] Port
CDeviceSampleEditView(CDeviceSample *_poDeviceSample)
QLineEdit * pqLineEditHost
[UI:LineEdit] Host
SAMPLE_DRIVER.
void setHost(const QString &_rqsHost)
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
void setPort(int _iPort)
QString getHost()
@ 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()