新二维码/条形码编辑逻辑
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "ViewModels.h"
|
||||
#include <QDebug>
|
||||
|
||||
DateItemModel DateItemModel::createDefaultReplaceModel()
|
||||
{
|
||||
@@ -28,3 +29,81 @@ DateItemModel DateItemModel::createDefaultReplaceModel()
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
void DateItemModel::loadFromXml(DateItemModel &vm, const QXmlStreamAttributes &attrs)
|
||||
{
|
||||
auto& m = vm;
|
||||
m.dataMap = attrs.value("dataMap").toString().split("<br>");
|
||||
m.daysMap = attrs.value("daysMap").toString().split("<br>");
|
||||
m.hoursMap = attrs.value("hoursMap").toString().split("<br>");
|
||||
m.monthsMap = attrs.value("monthsMap").toString().split("<br>");
|
||||
m.weeksMap = attrs.value("weeksMap").toString().split("<br>");
|
||||
|
||||
auto yearsMap = attrs.value("yearsMap").toString().split("<br>");
|
||||
for(auto it = yearsMap.begin(); it != yearsMap.end(); ++it) {
|
||||
auto yearPair = it->split("<subbr>");
|
||||
if(yearPair.size() == 2) {
|
||||
m.yearsMap[yearPair[0].toInt()] = yearPair[1];
|
||||
}
|
||||
}
|
||||
|
||||
m.monthsOffset = attrs.value("monthsOffset").toInt();
|
||||
m.daysOffset = attrs.value("daysOffset").toInt();
|
||||
m.datetimePattern = attrs.value("datetimePattern").toString();
|
||||
}
|
||||
|
||||
void DateItemModel::saveToXml(const DateItemModel &vm, QXmlStreamAttributes &attrs)
|
||||
{
|
||||
auto& m = vm;
|
||||
auto dataMap = m.dataMap.join("<br>");
|
||||
auto daysMap = m.daysMap.join("<br>");
|
||||
auto hoursMap = m.hoursMap.join("<br>");
|
||||
auto monthsMap = m.monthsMap.join("<br>");
|
||||
auto weeksMap = m.weeksMap.join("<br>");
|
||||
|
||||
QString yearsMap;
|
||||
for(auto it = m.yearsMap.begin(); it != m.yearsMap.end(); ++it) {
|
||||
yearsMap.append(QString("%1<subbr>%2<br>").arg(it.key()).arg(it.value()));
|
||||
}
|
||||
|
||||
attrs.append("dataMap", dataMap);
|
||||
attrs.append("daysMap", daysMap);
|
||||
attrs.append("hoursMap", hoursMap);
|
||||
attrs.append("monthsMap", monthsMap);
|
||||
attrs.append("weeksMap", weeksMap);
|
||||
attrs.append("yearsMap", yearsMap);
|
||||
attrs.append("datetimePattern", m.datetimePattern);
|
||||
attrs.append("monthsOffset", QString::number(m.monthsOffset));
|
||||
attrs.append("daysOffset", QString::number(m.daysOffset));
|
||||
}
|
||||
|
||||
void CounterViewModel::loadFromXml(CounterViewModel &vm, const QXmlStreamAttributes &attrs)
|
||||
{
|
||||
auto typeRef = attrs.value("counter_type");
|
||||
auto digitalNumRef = attrs.value("digital_num");
|
||||
|
||||
bool ok = false;
|
||||
int counterType = typeRef.toInt(&ok);
|
||||
if(!ok || (counterType != COUNTER_TYPE_1 && COUNTER_TYPE_2 != counterType)) {
|
||||
qWarning() << "Invalied counter type: " << counterType;
|
||||
return;
|
||||
}
|
||||
|
||||
ok = false;
|
||||
int digitalNum = digitalNumRef.toInt(&ok);
|
||||
if(!ok || digitalNum <= 0) {
|
||||
qWarning() << "Invalied counter digital number: " << digitalNum;
|
||||
return;
|
||||
}
|
||||
|
||||
vm.counterType = static_cast<COUNTER_TYPE>(counterType);
|
||||
vm.digitalNum = digitalNum;
|
||||
qInfo() << "Loaded attrs from xml: " << " counter type: " << counterType << ", digitalNum: " << digitalNum;
|
||||
}
|
||||
|
||||
void CounterViewModel::saveToXml(CounterViewModel &vm, QXmlStreamAttributes &attrs)
|
||||
{
|
||||
attrs.append("counter_type", QString::number(vm.counterType));
|
||||
attrs.append("digital_num", QString::number(vm.digitalNum));
|
||||
qInfo() << "Set attrs to xml: " << " counter type: " << vm.counterType << ", digitalNum: " << vm.digitalNum;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user