From c0f009c44a7c2d84b1a71b5ae7c7499dcf8f367c Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Thu, 13 Mar 2014 06:29:56 +0530 Subject: [PATCH] NOX: Eth2 - Separated protocol and widget as per new framework --- common/eth2.cpp | 43 ----------------------------- common/eth2.h | 18 +++---------- common/eth2config.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ common/eth2config.h | 41 ++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 58 deletions(-) create mode 100644 common/eth2config.cpp create mode 100644 common/eth2config.h diff --git a/common/eth2.cpp b/common/eth2.cpp index 73038b7..63f361a 100644 --- a/common/eth2.cpp +++ b/common/eth2.cpp @@ -17,26 +17,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -#include -#include - #include "eth2.h" -Eth2ConfigForm::Eth2ConfigForm(QWidget *parent) - : QWidget(parent) -{ - setupUi(this); -} - Eth2Protocol::Eth2Protocol(StreamBase *stream, AbstractProtocol *parent) : AbstractProtocol(stream, parent) { - configForm = NULL; } Eth2Protocol::~Eth2Protocol() { - delete configForm; } AbstractProtocol* Eth2Protocol::createInstance(StreamBase *stream, @@ -197,35 +186,3 @@ bool Eth2Protocol::setFieldData(int index, const QVariant &value, } return isOk; } - -QWidget* Eth2Protocol::configWidget() -{ - if (configForm == NULL) - { - configForm = new Eth2ConfigForm; - loadConfigWidget(); - } - return configForm; -} - -void Eth2Protocol::loadConfigWidget() -{ - configWidget(); - - configForm->cbOverrideType->setChecked( - fieldData(eth2_is_override_type, FieldValue).toBool()); - configForm->leType->setText(uintToHexStr( - fieldData(eth2_type, FieldValue).toUInt(), 2)); -} - -void Eth2Protocol::storeConfigWidget() -{ - bool isOk; - - configWidget(); - - setFieldData(eth2_is_override_type, - configForm->cbOverrideType->isChecked()); - data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16)); -} - diff --git a/common/eth2.h b/common/eth2.h index 5694339..5846d14 100644 --- a/common/eth2.h +++ b/common/eth2.h @@ -23,20 +23,11 @@ along with this program. If not, see #include "abstractprotocol.h" #include "eth2.pb.h" -#include "ui_eth2.h" -class Eth2ConfigForm : public QWidget, public Ui::eth2 -{ - Q_OBJECT -public: - Eth2ConfigForm(QWidget *parent = 0); -}; class Eth2Protocol : public AbstractProtocol { -private: - OstProto::Eth2 data; - Eth2ConfigForm *configForm; +public: enum eth2field { eth2_type = 0, @@ -46,7 +37,6 @@ private: eth2_fieldCount }; -public: Eth2Protocol(StreamBase *stream, AbstractProtocol *parent = 0); virtual ~Eth2Protocol(); @@ -69,10 +59,8 @@ public: int streamIndex = 0) const; virtual bool setFieldData(int index, const QVariant &value, FieldAttrib attrib = FieldValue); - - virtual QWidget* configWidget(); - virtual void loadConfigWidget(); - virtual void storeConfigWidget(); +private: + OstProto::Eth2 data; }; #endif diff --git a/common/eth2config.cpp b/common/eth2config.cpp new file mode 100644 index 0000000..7cf3bd5 --- /dev/null +++ b/common/eth2config.cpp @@ -0,0 +1,63 @@ +/* +Copyright (C) 2010,2014 Srivats P. + +This file is part of "Ostinato" + +This is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +#include "eth2config.h" +#include "eth2.h" + +Eth2ConfigForm::Eth2ConfigForm(QWidget *parent) + : AbstractProtocolConfigForm(parent) +{ + setupUi(this); +} + +Eth2ConfigForm::~Eth2ConfigForm() +{ +} + +Eth2ConfigForm* Eth2ConfigForm::createInstance() +{ + return new Eth2ConfigForm; +} + +void Eth2ConfigForm::loadWidget(AbstractProtocol *proto) +{ + cbOverrideType->setChecked( + proto->fieldData( + Eth2Protocol::eth2_is_override_type, + AbstractProtocol::FieldValue + ).toBool()); + leType->setText(uintToHexStr( + proto->fieldData( + Eth2Protocol::eth2_type, + AbstractProtocol::FieldValue + ).toUInt(), 2)); +} + +void Eth2ConfigForm::storeWidget(AbstractProtocol *proto) +{ + bool isOk; + + proto->setFieldData( + Eth2Protocol::eth2_is_override_type, + cbOverrideType->isChecked()); + proto->setFieldData( + Eth2Protocol::eth2_type, + leType->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX)); +} + diff --git a/common/eth2config.h b/common/eth2config.h new file mode 100644 index 0000000..918a855 --- /dev/null +++ b/common/eth2config.h @@ -0,0 +1,41 @@ +/* +Copyright (C) 2010,2014 Srivats P. + +This file is part of "Ostinato" + +This is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +#ifndef _ETH2_CONFIG_H +#define _ETH2_CONFIG_H + +#include "abstractprotocolconfig.h" + +#include "eth2.pb.h" +#include "ui_eth2.h" + +class Eth2ConfigForm : + public AbstractProtocolConfigForm, + public Ui::eth2 +{ + Q_OBJECT +public: + Eth2ConfigForm(QWidget *parent = 0); + virtual ~Eth2ConfigForm(); + + static Eth2ConfigForm* createInstance(); + virtual void loadWidget(AbstractProtocol *proto); + virtual void storeWidget(AbstractProtocol *proto); +}; +#endif