69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
// extraPropertyManager.cpp
|
|
#include "instance/extraPropertyManager.h"
|
|
#include "dataBase.h"
|
|
#include <QDebug>
|
|
|
|
ExtraPropertyManager::ExtraPropertyManager(QObject* parent) : QObject(parent) {
|
|
}
|
|
|
|
bool ExtraPropertyManager::loadAll() {
|
|
m_props.clear();
|
|
int count = 0;
|
|
|
|
QList<ExtraProperty> lstPro = DataBase::GetInstance()->getAllExtraProperty();
|
|
for(auto& pro:lstPro){
|
|
m_props[pro.code] = pro;
|
|
count++;
|
|
}
|
|
|
|
qInfo() << "加载了" << count << "个属性";
|
|
return true;
|
|
}
|
|
|
|
void ExtraPropertyManager::initial()
|
|
{
|
|
loadAll();
|
|
}
|
|
|
|
QVector<ExtraProperty> ExtraPropertyManager::getByFilter(const QVariantMap& filter,const QString& filterType) const {
|
|
QVector<ExtraProperty> result;
|
|
|
|
for (const ExtraProperty& prop : m_props) {
|
|
if (prop.matches(filter,filterType)) {
|
|
result.append(prop);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
ExtraProperty ExtraPropertyManager::getByCode(const QString& code) const {
|
|
return m_props.value(code);
|
|
}
|
|
|
|
int ExtraPropertyManager::add(const ExtraProperty& prop) {
|
|
if (prop.code.isEmpty()) {
|
|
qWarning() << "属性编码不能为空";
|
|
return -1;
|
|
}
|
|
|
|
if (m_props.contains(prop.code)) {
|
|
qWarning() << "属性编码已存在:" << prop.code;
|
|
return -1;
|
|
}
|
|
|
|
bool res = DataBase::GetInstance()->insertExtraProperty(prop);
|
|
|
|
return res;
|
|
}
|
|
|
|
QStringList ExtraPropertyManager::getGrids() const {
|
|
QSet<QString> grids;
|
|
for (const ExtraProperty& prop : m_props) {
|
|
if (!prop.grid_tag.isEmpty()) {
|
|
grids.insert(prop.grid_tag);
|
|
}
|
|
}
|
|
return QStringList(grids.begin(), grids.end());
|
|
}
|