1、重构组件库;

feature/struct-menu-20241023
simonyan 2 weeks ago
parent e9aca257eb
commit 12c7aa2293

1
.gitignore vendored

@ -17,3 +17,4 @@ FlowApp/FlowApp_resource.rc
*.exp *.exp
CFDStruct/CFDStructDataManager/debug/ CFDStruct/CFDStructDataManager/debug/
CFDStruct/CFDStructDataManager/release/ CFDStruct/CFDStructDataManager/release/
FlowApp.pro.user*

@ -1,32 +0,0 @@
#include "CUICommon.h"
#include<QLayout>
#include<QString>
#include<QVBoxLayout>
#include<QHBoxLayout>
#include<QFormLayout>
#include<CUIConfig.h>
//CUICommon::CUICommon()
//{
//}
/**
* @brief CUICommon::appLayout layoutlayout
* @param conf
* @return layout
*/
QLayout* CUICommon::appLayout(CUIConfig* conf)
{
QLayout* res_layout;
// QString confLayout = conf->property["layout"];
QString confLayout = conf->getPropertyValue("layout");
if(confLayout == "QVBoxLayout")
res_layout = new QVBoxLayout;
else if (confLayout == "QHBoxLayout") {
res_layout = new QHBoxLayout;
}else {
res_layout = new QVBoxLayout;
}
return res_layout;
}

@ -1,17 +0,0 @@
#ifndef CUICOMMON_H
#define CUICOMMON_H
class QLayout;
class QString;
class CUIConfig;
class CUICommon
{
public:
// CUICommon();
protected:
virtual QLayout* appLayout(CUIConfig* conf);
};
#endif // CUICOMMON_H

@ -1,6 +1,6 @@
#include "CUIComponentBase.h" #include "CUIComponentBase.h"
CUIComponentBase::CUIComponentBase(QWidget *parent) : QWidget(parent) CUIComponentBase::CUIComponentBase()
{ {
this->initSetting(); this->initSetting();
} }

@ -1,17 +1,16 @@
#ifndef CUICOMPONENTBASE_H #ifndef CUICOMPONENTBASE_H
#define CUICOMPONENTBASE_H #define CUICOMPONENTBASE_H
#include <QWidget> #include <QObject>
#include <QVariant> #include <QVariant>
#include "CUIPropertyAPI.h" #include "CUIPropertyAPI.h"
#include "CUIConfig.h" #include "CUIConfig.h"
#include "CUIDefine.h" #include "CUIDefine.h"
class CUIPropertyAPI CUIComponentBase : public QWidget class CUIPropertyAPI CUIComponentBase
{ {
Q_OBJECT
public: public:
explicit CUIComponentBase(QWidget *parent = nullptr); explicit CUIComponentBase();
protected: protected:
// 初始化配置 // 初始化配置

@ -0,0 +1,26 @@
#include "CUIComponentBaseContainerWidget.h"
#include "CUIConfig.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
CUIComponentBaseContainerWidget::CUIComponentBaseContainerWidget(QWidget *parent) : QWidget(parent)
{
}
QLayout *CUIComponentBaseContainerWidget::getLayout(CUIConfig *conf)
{
if (!conf) {
return new QVBoxLayout;
}
QLayout* layout;
QString layoutConf = conf->getPropertyValue("layout");
if (layoutConf == "QVBoxLayout") {
layout = new QVBoxLayout;
} else if (layoutConf == "QVBoxLayout") {
layout = new QHBoxLayout;
} else {
layout = new QHBoxLayout;
}
return layout;
}

@ -0,0 +1,21 @@
#ifndef CUICOMPONENTBASECONTAINERWIDGET_H
#define CUICOMPONENTBASECONTAINERWIDGET_H
#include <QWidget>
class CUIConfig;
class QLayout;
class CUIComponentBaseContainerWidget : public QWidget
{
Q_OBJECT
public:
explicit CUIComponentBaseContainerWidget(QWidget *parent = nullptr);
protected:
virtual QLayout* getLayout(CUIConfig* conf);
protected:
QLayout* m_layout;
signals:
};
#endif // CUICOMPONENTBASECONTAINERWIDGET_H

@ -0,0 +1,26 @@
#include "CUIComponentBaseWidget.h"
#include "CUIConfig.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
CUIComponentBaseWidget::CUIComponentBaseWidget(QWidget *parent) : QWidget(parent)
{
}
QLayout *CUIComponentBaseWidget::getLayout(CUIConfig *conf)
{
if (!conf) {
return new QVBoxLayout;
}
QLayout* layout;
QString layoutConf = conf->getPropertyValue("layout");
if (layoutConf == "QVBoxLayout") {
layout = new QVBoxLayout;
} else if (layoutConf == "QVBoxLayout") {
layout = new QHBoxLayout;
} else {
layout = new QHBoxLayout;
}
return layout;
}

@ -0,0 +1,21 @@
#ifndef CUICOMPONENTBASEWIDGET_H
#define CUICOMPONENTBASEWIDGET_H
#include <QWidget>
class CUIConfig;
class CUIComponentBaseWidget : public QWidget
{
Q_OBJECT
public:
explicit CUIComponentBaseWidget(QWidget *parent = nullptr);
protected:
virtual QLayout* getLayout(CUIConfig* conf);
protected:
signals:
};
#endif // CUICOMPONENTBASEWIDGET_H

@ -11,7 +11,7 @@
* @param conf * @param conf
* @param parent * @param parent
*/ */
CUIGroupBox::CUIGroupBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : QGroupBox(parent) CUIGroupBox::CUIGroupBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : CUIComponentBaseContainerWidget(parent)
{ {
this->conf = conf; this->conf = conf;
iniUI(subCUI); iniUI(subCUI);
@ -23,27 +23,18 @@ CUIGroupBox::CUIGroupBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent
*/ */
void CUIGroupBox::iniUI(QVector<CUI*> &subCUI) void CUIGroupBox::iniUI(QVector<CUI*> &subCUI)
{ {
this->setTitle(conf->getPropertyValue("name")); m_groupBox = new QGroupBox;
// appLayout(); m_groupBox->setTitle(conf->getPropertyValue("name"));
layout = appLayout(conf); m_layout = this->getLayout(conf);
this->setLayout(layout); m_groupBox->setLayout(m_layout);
qDebug() << this->conf->getSub().size(); qDebug() << this->conf->getSub().size();
for(auto conf : this->conf->getSub()) { for(auto conf : this->conf->getSub()) {
CUI* tmp = new CUI(nullptr, conf); CUI* tmp = new CUI(nullptr, conf);
subCUI.push_back(tmp); subCUI.push_back(tmp);
layout->addWidget(tmp->getUI()); m_layout->addWidget(tmp->getUI());
} }
}
/**
* @brief CUIGroupBox::appLayout layout
*/
//void CUIGroupBox::appLayout()
//{
// if(conf->property["layout"] == "QVBoxLayout")
// layout = new QVBoxLayout();
// layout = new QFormLayout(); QVBoxLayout* mainLayout = new QVBoxLayout;
// this->setLayout(layout); mainLayout->addWidget(m_groupBox);
//} this->setLayout(mainLayout);
}

@ -2,23 +2,23 @@
#define CUIGROUPBOX_H #define CUIGROUPBOX_H
#include <QGroupBox> #include <QGroupBox>
#include <CUICommon.h> #include <CUIComponentBaseContainerWidget.h>
class CUI; class CUI;
class CUIConfig; class CUIConfig;
class QGroupBox;
class CUIGroupBox : public CUIComponentBaseContainerWidget
class CUIGroupBox : public QGroupBox, public CUICommon
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CUIGroupBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent = nullptr); explicit CUIGroupBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent = nullptr);
private: private:
CUIConfig* conf; CUIConfig* conf;
// void appLayout();
// QVector<CUI> subUI;
protected: protected:
QLayout* layout; QLayout* m_layout;
QGroupBox* m_groupBox;
protected:
void iniUI(QVector<CUI*> &subCUI); void iniUI(QVector<CUI*> &subCUI);

@ -13,7 +13,7 @@
* @param conf * @param conf
* @param parent * @param parent
*/ */
CUILineEdit::CUILineEdit(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : CUIComponentBase(parent) CUILineEdit::CUILineEdit(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : CUIComponentBaseWidget(parent)
{ {
this->m_conf = conf; this->m_conf = conf;
this->iniUI(subCUI); this->iniUI(subCUI);

@ -1,16 +1,18 @@
#ifndef CUILINEEDIT_H #ifndef CUILINEEDIT_H
#define CUILINEEDIT_H #define CUILINEEDIT_H
#include <QWidget>
#include <QLineEdit> #include <QLineEdit>
#include "CUIPropertyAPI.h" #include "CUIPropertyAPI.h"
#include "CUIComponentBase.h" #include "CUIComponentBase.h"
#include "CUIComponentBaseWidget.h"
class CUIConfig; class CUIConfig;
class QLabel; class QLabel;
class QHBoxLayout; class QHBoxLayout;
class CUI; class CUI;
class CUIPropertyAPI CUILineEdit : public CUIComponentBase class CUIPropertyAPI CUILineEdit : public CUIComponentBaseWidget, public CUIComponentBase
{ {
Q_OBJECT Q_OBJECT
public: public:

@ -1,11 +1,12 @@
HEADERS += \ HEADERS += \
$$PWD/CUIComponentBase.h \ $$PWD/CUIComponentBase.h \
$$PWD/CUIComponentBaseContainerWidget.h \
$$PWD/CUIComponentBaseWidget.h \
$$PWD/CUIDefine.h \ $$PWD/CUIDefine.h \
CUI.h \ CUI.h \
CUIButtonBox.h \ CUIButtonBox.h \
CUICheckBox.h \ CUICheckBox.h \
CUIComboBox.h \ CUIComboBox.h \
CUICommon.h \
CUIGroupBox.h \ CUIGroupBox.h \
CUILineEdit.h \ CUILineEdit.h \
CUIPushButton.h \ CUIPushButton.h \
@ -18,11 +19,12 @@ HEADERS += \
SOURCES += \ SOURCES += \
$$PWD/CUIComponentBase.cpp \ $$PWD/CUIComponentBase.cpp \
$$PWD/CUIComponentBaseContainerWidget.cpp \
$$PWD/CUIComponentBaseWidget.cpp \
CUI.cpp \ CUI.cpp \
CUIButtonBox.cpp \ CUIButtonBox.cpp \
CUICheckBox.cpp \ CUICheckBox.cpp \
CUIComboBox.cpp \ CUIComboBox.cpp \
CUICommon.cpp \
CUIGroupBox.cpp \ CUIGroupBox.cpp \
CUILineEdit.cpp \ CUILineEdit.cpp \
CUIPushButton.cpp \ CUIPushButton.cpp \

@ -2,7 +2,6 @@
#include "CUIConfig.h" #include "CUIConfig.h"
#include "QVBoxLayout" #include "QVBoxLayout"
#include <QLayout> #include <QLayout>
#include <CUICommon.h>
#include <CUI.h> #include <CUI.h>
#include<QDebug> #include<QDebug>
@ -12,9 +11,9 @@
* @param conf * @param conf
* @param parent * @param parent
*/ */
CUIWidget::CUIWidget(CUIConfig *conf, QVector<CUI*> &subCUI, QWidget *parent): QWidget(parent) CUIWidget::CUIWidget(CUIConfig *conf, QVector<CUI*> &subCUI, QWidget *parent): CUIComponentBaseContainerWidget(parent)
{ {
this->conf = conf; this->m_conf = conf;
iniUI(subCUI); iniUI(subCUI);
} }
@ -23,24 +22,13 @@ CUIWidget::CUIWidget(CUIConfig *conf, QVector<CUI*> &subCUI, QWidget *parent): Q
*/ */
void CUIWidget::iniUI(QVector<CUI*> &subCUI) void CUIWidget::iniUI(QVector<CUI*> &subCUI)
{ {
layout = appLayout(conf); m_layout = this->getLayout(m_conf);
this->setLayout(layout); this->setLayout(m_layout);
// qDebug()<<"widget add layout"; for(auto &conf : this->m_conf->getSub()) {
for(auto &conf : this->conf->getSub()) {
CUI* tmp = new CUI(nullptr, conf); CUI* tmp = new CUI(nullptr, conf);
subCUI.push_back(tmp); subCUI.push_back(tmp);
layout->addWidget(tmp->getUI()); m_layout->addWidget(tmp->getUI());
} }
} }
/**
* @brief CUIWidget::getProperty
* @param key
* @return val
*/
QString CUIWidget::getProperty(QString key)
{
return conf->getPropertyValue(key);
}

@ -1,23 +1,19 @@
#ifndef CUIWIDGET_H #ifndef CUIWIDGET_H
#define CUIWIDGET_H #define CUIWIDGET_H
#include<CUICommon.h>
class CUIConfig; class CUIConfig;
class CUI; class CUI;
#include <QWidget> #include <QWidget>
#include "CUIComponentBaseContainerWidget.h"
#include "CUIComponentBase.h"
class CUIWidget : public QWidget, public CUICommon class CUIWidget : public CUIComponentBaseContainerWidget, CUIComponentBase
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CUIWidget(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent = nullptr); explicit CUIWidget(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent = nullptr);
private: private:
void iniUI(QVector<CUI*> &subCUI); void iniUI(QVector<CUI*> &subCUI);
// void appLayout();
QString getProperty(QString p);
CUIConfig* conf;
QLayout* layout;
// QVector<CUI> subUI;
signals: signals:
}; };

Loading…
Cancel
Save