1 Star 0 Fork 19

yycmmc/qcom

forked from fensnote/qcom 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
widgetconfigcomm.cpp 5.83 KB
一键复制 编辑 原始数据 按行查看 历史
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "widgetconfigcomm.h"
#include "config.h"
#include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtWidgets/QtWidgets>
#endif
WidgetConfigComm::WidgetConfigComm(QObject *parent)
: QObject(parent)
{
}
WidgetConfigComm::~WidgetConfigComm()
{
}
bool WidgetConfigComm::SaveWidgetConfig(const QWidget * widgetParent, const QWidget * widgetConfigGroup)
{
bool bRet = false;
do
{
if (!widgetParent)
break;
if (!widgetConfigGroup)
break;
if (widgetConfigGroup->objectName().isNull() || widgetConfigGroup->objectName().isEmpty())
break;
bRet = SaveWidgetConfig(widgetParent, widgetConfigGroup->objectName());
} while (false);
return bRet;
}
bool WidgetConfigComm::SaveWidgetConfig(const QWidget * widgetParent, const QString szConfigGroup)
{
bool bRet = false;
do
{
if (!widgetParent)
break;
if (szConfigGroup.isNull() || szConfigGroup.isEmpty())
break;
const QObjectList list = widgetParent->children();
if (list.empty())
break;
QStringList qslKeys, qslValues;
foreach(QObject* obj, list)
{
if (obj->objectName().isNull() || obj->objectName().isEmpty())
continue;
QString szClassName = (obj->metaObject()->className());
if (szClassName == "QCheckBox")
{
QCheckBox* cb = static_cast<QCheckBox*>(obj);
qslKeys << cb->objectName();
qslValues << (cb->isChecked() ? "1" : "0");
if ( cb->objectName() == "cbAutoForSend" )
continue;
}
else if (szClassName == "QLineEdit")
{
QLineEdit* le = static_cast<QLineEdit*>(obj);
qslKeys << le->objectName();
qslValues << le->text();
}
else if (szClassName == "QComboBox")
{
QComboBox* comboBox = static_cast<QComboBox*>(obj);
qslKeys << comboBox->objectName() + "No";
qslValues << QString::number(comboBox->currentIndex());
qslKeys << comboBox->objectName();
qslValues << comboBox->currentText();
}
else if (szClassName == "QRadioButton")
{
QRadioButton* rb = static_cast<QRadioButton*>(obj);
qslKeys << rb->objectName();
qslValues << (rb->isChecked() ? "1" : "0");
}
else if (szClassName == "QSlider")
{
QSlider* slider = static_cast<QSlider*>(obj);
qslKeys << slider->objectName();
qslValues << QString::number(slider->value());
}
else if (szClassName == "QSpinBox")
{
QSpinBox* spinBox = static_cast<QSpinBox*>(obj);
qslKeys << spinBox->objectName();
qslValues << QString::number(spinBox->value());
}
else
{
continue;
}
}
saveConfig(szConfigGroup, qslKeys, qslValues);
bRet = true;
} while (false);
return bRet;;
}
bool WidgetConfigComm::LoadWidgetConfig(QWidget* widgetParent, QWidget* widgetConfigGroup)
{
bool bRet = false;
do
{
if (!widgetParent)
break;
if (!widgetConfigGroup)
break;
if (widgetConfigGroup->objectName().isNull() || widgetConfigGroup->objectName().isEmpty())
break;
bRet = LoadWidgetConfig(widgetParent, widgetConfigGroup->objectName());
} while (false);
return bRet;
}
bool WidgetConfigComm::LoadWidgetConfig(QWidget* widgetParent, QString szConfigGroup)
{
bool bRet = false;
do
{
if (!widgetParent)
break;
if (szConfigGroup.isNull() || szConfigGroup.isEmpty())
break;
const QObjectList list = widgetParent->children();
if (list.empty())
break;
QStringList qslKeys;
foreach(QObject* obj, list)
{
if (obj->objectName().isNull() || obj->objectName().isEmpty())
continue;
QString szClassName = (obj->metaObject()->className());
if (szClassName == "QCheckBox")
{
QCheckBox* cb = static_cast<QCheckBox*>(obj);
qslKeys << cb->objectName();
if ( cb->objectName() == "cbAutoForSend" )
continue;
}
else if (szClassName == "QLineEdit")
{
QLineEdit* le = static_cast<QLineEdit*>(obj);
qslKeys << le->objectName();
}
else if (szClassName == "QComboBox")
{
QComboBox* comboBox = static_cast<QComboBox*>(obj);
qslKeys << comboBox->objectName() + "No";
qslKeys << comboBox->objectName();
}
else if (szClassName == "QRadioButton")
{
QRadioButton* rb = static_cast<QRadioButton*>(obj);
qslKeys << rb->objectName();
}
else if (szClassName == "QSlider")
{
QSlider* slider = static_cast<QSlider*>(obj);
qslKeys << slider->objectName();
}
else if (szClassName == "QSpinBox")
{
QSpinBox* spinBox = static_cast<QSpinBox*>(obj);
qslKeys << spinBox->objectName();
}
else
{
continue;
}
}
QMap<QString, QString> mapValues = loadConfig(szConfigGroup, qslKeys, 0);
if (mapValues.size() <= 0)
break;
foreach(QObject* obj, list)
{
if (obj->objectName().isNull() || obj->objectName().isEmpty())
continue;
QString szClassName = (obj->metaObject()->className());
if (szClassName == "QCheckBox")
{
QCheckBox* cb = static_cast<QCheckBox*>(obj);
cb->setChecked(mapValues[cb->objectName()] == "1" ? true : false);
}
else if (szClassName == "QLineEdit")
{
QLineEdit* le = static_cast<QLineEdit*>(obj);
le->setText(mapValues[le->objectName()]);
}
else if (szClassName == "QComboBox")
{
QComboBox* comboBox = static_cast<QComboBox*>(obj);
comboBox->setCurrentText(mapValues[comboBox->objectName()]);
}
else if (szClassName == "QRadioButton")
{
QRadioButton* rb = static_cast<QRadioButton*>(obj);
rb->setChecked(mapValues[rb->objectName()] == "1" ? true : false);
}
else if (szClassName == "QSlider")
{
QSlider* slider = static_cast<QSlider*>(obj);
slider->setValue(mapValues[slider->objectName()].toInt());
}
else if (szClassName == "QSpinBox")
{
QSpinBox* spinBox = static_cast<QSpinBox*>(obj);
spinBox->setValue(mapValues[spinBox->objectName()].toInt());
}
else
{
continue;
}
}
bRet = true;
} while (false);
return bRet;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yycmmc/qcom.git
git@gitee.com:yycmmc/qcom.git
yycmmc
qcom
qcom
master

搜索帮助