refs #681, adjusted form classes

* made server form a CForm, not a component
* adjusted other forms
This commit is contained in:
Klaus Basan
2016-06-26 20:04:17 +02:00
parent 2d00ff42fe
commit 75a7ca382c
15 changed files with 279 additions and 264 deletions

View File

@@ -126,8 +126,9 @@ namespace BlackGui
return icao;
}
CStatusMessageList CAircraftIcaoForm::validate() const
CStatusMessageList CAircraftIcaoForm::validate(bool nested) const
{
Q_UNUSED(nested);
CAircraftIcaoCode code(getValue());
CStatusMessageList msgs(code.validate());
this->ui->val_Indicator->setState(msgs);

View File

@@ -47,20 +47,18 @@ namespace BlackGui
//! Get value
BlackMisc::Aviation::CAircraftIcaoCode getValue() const;
//! Validate, empty list means OK
BlackMisc::CStatusMessageList validate() const;
//! Allow to drop
void allowDrop(bool allowDrop);
//! Is drop allowed?
bool isDropAllowed() const;
//! \copydoc CForm::setReadOnly
virtual void setReadOnly(bool readOnly) override;
//! \copydoc CForm::setSelectOnly
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual void setSelectOnly() override;
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
//! @}
//! Clear
void clear();

View File

@@ -87,8 +87,9 @@ namespace BlackGui
return code;
}
CStatusMessageList CAirlineIcaoForm::validate() const
CStatusMessageList CAirlineIcaoForm::validate(bool nested) const
{
Q_UNUSED(nested);
CAirlineIcaoCode code(getValue());
CStatusMessageList msgs(code.validate());
if (this->isReadOnly())

View File

@@ -50,20 +50,18 @@ namespace BlackGui
//! Get value
BlackMisc::Aviation::CAirlineIcaoCode getValue() const;
//! Validate, empty list means OK
BlackMisc::CStatusMessageList validate() const;
//! Allow to drop
void allowDrop(bool allowDrop);
//! Is drop allowed?
bool isDropAllowed() const;
//! \copydoc CForm::setReadOnly
virtual void setReadOnly(bool readOnly) override;
//! \copydoc CForm::setSelectOnly
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual void setSelectOnly() override;
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
//! @}
//! Clear
void clear();

View File

@@ -70,8 +70,9 @@ namespace BlackGui
return distributor;
}
CStatusMessageList CDistributorForm::validate() const
CStatusMessageList CDistributorForm::validate(bool nested) const
{
Q_UNUSED(nested);
CDistributor distributor(getValue());
CStatusMessageList msgs(distributor.validate());
if (this->isReadOnly())

View File

@@ -46,20 +46,18 @@ namespace BlackGui
//! Get value
BlackMisc::Simulation::CDistributor getValue() const;
//! Validate, empty list means OK
BlackMisc::CStatusMessageList validate() const;
//! Allow to drop
void allowDrop(bool allowDrop);
//! Is drop allowed?
bool isDropAllowed() const;
//! \copydoc CForm::setReadOnly
virtual void setReadOnly(bool readOnly) override;
//! \copydoc CForm::setSelectOnly
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual void setSelectOnly() override;
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
//! @}
//! Clear
void clear();

View File

@@ -33,8 +33,7 @@ namespace BlackGui
/*!
* Livery form class
*/
class BLACKGUI_EXPORT CLiveryForm :
public CForm
class BLACKGUI_EXPORT CLiveryForm : public CForm
{
Q_OBJECT
@@ -51,9 +50,6 @@ namespace BlackGui
//! Embedded ariline
BlackMisc::Aviation::CAirlineIcaoCode getValueAirlineIcao() const;
//! Validate, empty list means OK
BlackMisc::CStatusMessageList validate(bool withNestedForms) const;
//! Validate airline ICAO code only
BlackMisc::CStatusMessageList validateAirlineIcao() const;
@@ -63,11 +59,12 @@ namespace BlackGui
//! Is drop allowed?
bool isDropAllowed() const;
//! \copydoc CForm::setReadOnly
virtual void setReadOnly(bool readOnly) override;
//! \copydoc CForm::setSelectOnly
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual void setSelectOnly() override;
virtual BlackMisc::CStatusMessageList validate(bool withNestedForms) const override;
//! @}
//! Clear data
void clear();

View File

@@ -46,13 +46,13 @@ namespace BlackGui
BlackMisc::Simulation::CAircraftModel getValue() const;
//! Validate
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
//! \copydoc CForm::setReadOnly
virtual void setReadOnly(bool readOnly) override;
//! \copydoc CForm::setSelectOnly
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual void setSelectOnly() override;
virtual BlackMisc::CStatusMessageList validate(bool withNestedObjects) const override;
//! @}
public slots:
//! Set model

View File

@@ -68,7 +68,6 @@ namespace BlackGui
//! \name Form functions, here not used
//! \@{
virtual void setReadOnly(bool readOnly) override { Q_UNUSED(readOnly); }
virtual void setSelectOnly() override {}
//! \@}
signals:

View File

@@ -0,0 +1,102 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackgui/editors/serverform.h"
#include "blackmisc/network/user.h"
#include "ui_serverform.h"
#include <QIntValidator>
#include <QLabel>
#include <QLineEdit>
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Editors
{
CServerForm::CServerForm(QWidget *parent) :
CForm(parent),
ui(new Ui::CNetworkServerForm)
{
ui->setupUi(this);
this->ui->le_Port->setValidator(new QIntValidator(1, 65535, this));
}
CServerForm::~CServerForm()
{ }
void CServerForm::setServer(const CServer &server)
{
CUser user = server.getUser();
this->ui->le_NetworkId->setText(user.getId());
this->ui->le_RealName->setText(user.getRealName());
this->ui->le_Name->setText(server.getName());
this->ui->le_Password->setText(user.getPassword());
this->ui->le_Description->setText(server.getDescription());
this->ui->le_Address->setText(server.getAddress());
this->ui->le_Port->setText(QString::number(server.getPort()));
this->ui->form_ServerFsd->setValue(server.getFsdSetup());
}
BlackMisc::Network::CServer CServerForm::getServer() const
{
CUser user(
this->ui->le_NetworkId->text().trimmed(),
this->ui->le_RealName->text().trimmed().simplified(),
"",
this->ui->le_Password->text().trimmed()
);
CServer server(
this->ui->le_Name->text().trimmed().simplified(),
this->ui->le_Description->text().trimmed().simplified(),
this->ui->le_Address->text().trimmed(),
this->ui->le_Port->text().trimmed().toInt(),
user
);
CFsdSetup setup(this->ui->form_ServerFsd->getValue());
server.setFsdSetup(setup);
return server;
}
void CServerForm::setReadOnly(bool readOnly)
{
this->ui->le_NetworkId->setReadOnly(readOnly);
this->ui->le_RealName->setReadOnly(readOnly);
this->ui->le_Name->setReadOnly(readOnly);
this->ui->le_Description->setReadOnly(readOnly);
this->ui->le_Address->setReadOnly(readOnly);
this->ui->le_Port->setReadOnly(readOnly);
this->ui->le_Password->setReadOnly(readOnly);
this->ui->form_ServerFsd->setReadOnly(readOnly);
}
void CServerForm::showPasswordField(bool show)
{
if (this->ui->le_Password->isVisible() == show) { return; }
if (m_passwordNameLabel.isEmpty()) { m_passwordNameLabel = ui->lbl_IdPassword->text(); }
if (show)
{
ui->lbl_IdPassword->setText(m_passwordNameLabel);
}
else
{
ui->lbl_IdPassword->setText("Id");
}
this->ui->le_Password->setVisible(show);
}
BlackMisc::CStatusMessageList CServerForm::validate(bool nested) const
{
Q_UNUSED(nested);
const CServer server = getServer();
return server.validate();
}
} // ns
} // ns

View File

@@ -0,0 +1,67 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_NETWORKSERVERFORM_H
#define BLACKGUI_COMPONENTS_NETWORKSERVERFORM_H
#include "blackgui/blackguiexport.h"
#include "blackgui/editors/form.h"
#include "blackmisc/network/server.h"
#include "blackmisc/statusmessagelist.h"
#include <QFrame>
#include <QObject>
#include <QScopedPointer>
#include <QString>
class QWidget;
namespace Ui { class CNetworkServerForm; }
namespace BlackGui
{
namespace Editors
{
//! Server form
class BLACKGUI_EXPORT CServerForm : public CForm
{
Q_OBJECT
public:
//! Constructor
explicit CServerForm(QWidget *parent = nullptr);
//! Destructor
~CServerForm();
//! Set server
void setServer(const BlackMisc::Network::CServer &server);
//! Get server
BlackMisc::Network::CServer getServer() const;
//! \name Form class implementations
//! @{
virtual void setReadOnly(bool readonly) override;
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
//! @}
//! Show the password field
void showPasswordField(bool show);
private:
QScopedPointer<Ui::CNetworkServerForm> ui;
QString m_passwordNameLabel;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,225 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CNetworkServerForm</class>
<widget class="QFrame" name="CNetworkServerForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<height>171</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_NetworkServerForm">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tw_ServerForm">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tb_ServerGeneral">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QVBoxLayout" name="vl_ServerGeneral">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QFrame" name="fr_ServerGeneral">
<layout class="QGridLayout" name="gl_ServerForm">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
<number>4</number>
</property>
<item row="2" column="1">
<widget class="QLineEdit" name="le_Address">
<property name="placeholderText">
<string>e.g. &quot;server.foo.com&quot;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="le_Description">
<property name="placeholderText">
<string>server description</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="le_RealName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>your name if required</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="le_Port">
<property name="text">
<string>6809</string>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_RealName">
<property name="text">
<string>Real name:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Address">
<property name="text">
<string>Addr./ port:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Description">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="le_Name">
<property name="placeholderText">
<string>server name</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_IdPassword">
<property name="text">
<string>Id/Password:</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="le_Password">
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="le_NetworkId">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>id</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_ServerFsd">
<attribute name="title">
<string>FSD</string>
</attribute>
<layout class="QVBoxLayout" name="vl_ServerFsd">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="BlackGui::Editors::CFsdSetupForm" name="form_ServerFsd">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Editors::CFsdSetupForm</class>
<extends>QFrame</extends>
<header>blackgui/editors/fsdsetupform.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>