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
CFDStruct/CFDStructDataManager/debug/
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"
CUIComponentBase::CUIComponentBase(QWidget *parent) : QWidget(parent)
CUIComponentBase::CUIComponentBase()
{
this->initSetting();
}

@ -1,17 +1,16 @@
#ifndef CUICOMPONENTBASE_H
#define CUICOMPONENTBASE_H
#include <QWidget>
#include <QObject>
#include <QVariant>
#include "CUIPropertyAPI.h"
#include "CUIConfig.h"
#include "CUIDefine.h"
class CUIPropertyAPI CUIComponentBase : public QWidget
class CUIPropertyAPI CUIComponentBase
{
Q_OBJECT
public:
explicit CUIComponentBase(QWidget *parent = nullptr);
explicit CUIComponentBase();
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 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;
iniUI(subCUI);
@ -23,27 +23,18 @@ CUIGroupBox::CUIGroupBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent
*/
void CUIGroupBox::iniUI(QVector<CUI*> &subCUI)
{
this->setTitle(conf->getPropertyValue("name"));
// appLayout();
layout = appLayout(conf);
this->setLayout(layout);
m_groupBox = new QGroupBox;
m_groupBox->setTitle(conf->getPropertyValue("name"));
m_layout = this->getLayout(conf);
m_groupBox->setLayout(m_layout);
qDebug() << this->conf->getSub().size();
for(auto conf : this->conf->getSub()) {
CUI* tmp = new CUI(nullptr, conf);
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();
// this->setLayout(layout);
//}
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget(m_groupBox);
this->setLayout(mainLayout);
}

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

@ -13,7 +13,7 @@
* @param conf
* @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->iniUI(subCUI);

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

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

@ -2,7 +2,6 @@
#include "CUIConfig.h"
#include "QVBoxLayout"
#include <QLayout>
#include <CUICommon.h>
#include <CUI.h>
#include<QDebug>
@ -12,9 +11,9 @@
* @param conf
* @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);
}
@ -23,24 +22,13 @@ CUIWidget::CUIWidget(CUIConfig *conf, QVector<CUI*> &subCUI, QWidget *parent): Q
*/
void CUIWidget::iniUI(QVector<CUI*> &subCUI)
{
layout = appLayout(conf);
this->setLayout(layout);
// qDebug()<<"widget add layout";
for(auto &conf : this->conf->getSub()) {
m_layout = this->getLayout(m_conf);
this->setLayout(m_layout);
for(auto &conf : this->m_conf->getSub()) {
CUI* tmp = new CUI(nullptr, conf);
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
#define CUIWIDGET_H
#include<CUICommon.h>
class CUIConfig;
class CUI;
#include <QWidget>
#include "CUIComponentBaseContainerWidget.h"
#include "CUIComponentBase.h"
class CUIWidget : public QWidget, public CUICommon
class CUIWidget : public CUIComponentBaseContainerWidget, CUIComponentBase
{
Q_OBJECT
public:
explicit CUIWidget(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent = nullptr);
private:
void iniUI(QVector<CUI*> &subCUI);
// void appLayout();
QString getProperty(QString p);
CUIConfig* conf;
QLayout* layout;
// QVector<CUI> subUI;
signals:
};

Loading…
Cancel
Save