V6.7.4 追加更新
This commit is contained in:
+47
-311
@@ -452,320 +452,56 @@ void TestPrintWidget::onSaveASFile(QString filename,bool Flag){// use for dialog
|
||||
* */
|
||||
void TestPrintWidget::onFileOpen(QString filePath,bool reviewFlag){
|
||||
|
||||
if(editMode==SCENE) {
|
||||
if(filePath.endsWith(".xml"))
|
||||
{
|
||||
QFile file(filePath);
|
||||
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { // 以只写模式打开文件
|
||||
|
||||
if(reviewFlag)
|
||||
xmlfileName=filePath;
|
||||
|
||||
QXmlStreamReader reader(&file);
|
||||
if(!m_CreateImageFlag)
|
||||
{
|
||||
pPicScene->clear();
|
||||
pViewer->viewport()->update();
|
||||
unsigned char SpecialVarEnable = 0;
|
||||
if (sysPara) sysPara->devOp->fpgaWr(0xa4b0,(unsigned char *)&SpecialVarEnable,1);
|
||||
}
|
||||
// 解析 XML,直到结束
|
||||
while (!reader.atEnd()) {
|
||||
|
||||
// 读取下一个元素
|
||||
QXmlStreamReader::TokenType nType = reader.readNext();
|
||||
|
||||
switch (nType) {
|
||||
case QXmlStreamReader::StartDocument: { // 开始文档
|
||||
//qDebug() << QString::fromLocal8Bit("********** 开始文档(XML 声明) ********** ");
|
||||
// XML 声明
|
||||
QString strVersion = reader.documentVersion().toString();
|
||||
QString strEncoding = reader.documentEncoding().toString();
|
||||
bool bAlone = reader.isStandaloneDocument();
|
||||
//qDebug() << QString::fromLocal8Bit("版本:%1 编码:%2 Standalone:%3")
|
||||
// .arg(strVersion).arg(strEncoding).arg(bAlone) << "\r\n";
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::Comment: { // 注释
|
||||
//qDebug() << QString::fromLocal8Bit("********** 注释 ********** ");
|
||||
QString strComment = reader.text().toString();
|
||||
//qDebug() << strComment << "\r\n";
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::ProcessingInstruction: { // 处理指令
|
||||
//qDebug() << QString::fromLocal8Bit("********** 处理指令 ********** ");
|
||||
QString strProcInstr = reader.processingInstructionData().toString();
|
||||
//qDebug() << strProcInstr << "\r\n";
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::DTD: { // DTD
|
||||
//qDebug() << QString::fromLocal8Bit("********** DTD ********** ");
|
||||
QString strDTD = reader.text().toString();
|
||||
QXmlStreamNotationDeclarations notationDeclarations = reader.notationDeclarations(); // 符号声明
|
||||
QXmlStreamEntityDeclarations entityDeclarations = reader.entityDeclarations(); // 实体声明
|
||||
// DTD 声明
|
||||
QString strDTDName = reader.dtdName().toString();
|
||||
QString strDTDPublicId = reader.dtdPublicId().toString(); // DTD 公开标识符
|
||||
QString strDTDSystemId = reader.dtdSystemId().toString(); // DTD 系统标识符
|
||||
//qDebug() << QString::fromLocal8Bit("DTD : %1").arg(strDTD);
|
||||
//qDebug() << QString::fromLocal8Bit("DTD 名称 : %1").arg(strDTDName);
|
||||
//qDebug() << QString::fromLocal8Bit("DTD 公开标识符 : %1").arg(strDTDPublicId);
|
||||
//qDebug() << QString::fromLocal8Bit("DTD 系统标识符 : %1").arg(strDTDSystemId);
|
||||
//qDebug() << "\r\n";
|
||||
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::StartElement: { // 开始元素
|
||||
QString strElementName = reader.name().toString();
|
||||
if (QString::compare(strElementName, "VBfiles") == 0) { // 根元素
|
||||
//qDebug() << QString::fromLocal8Bit("********** 开始元素<VBfiles> ********** ");
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
if (attributes.hasAttribute("Version")) {
|
||||
QString strVersion = attributes.value("Version").toString();
|
||||
//qDebug() << QString::fromLocal8Bit("属性:Version(%1)").arg(strVersion);
|
||||
}
|
||||
|
||||
parseVbfile(reader, reviewFlag);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case QXmlStreamReader::EndDocument: { //*/*/ 结束文档
|
||||
//qDebug() << QString::fromLocal8Bit("********** 结束文档 ********** ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.hasError()) { // 解析出错
|
||||
qDebug() << QString::fromLocal8Bit("错误信息:%1 行号:%2 列号:%3 字符位移:%4").arg(reader.errorString()).arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.characterOffset());
|
||||
}
|
||||
//qDebug()<<"open done";
|
||||
file.close(); // 关闭文件
|
||||
//snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",filePath.toLatin1().constData());
|
||||
if(!m_CreateImageFlag)//生成图片显示
|
||||
{
|
||||
if(sysPara)
|
||||
{
|
||||
sysPara->sysFile =filePath;
|
||||
sysPara->loadParaFromFile();
|
||||
//qDebug()<<"textedit txt mode onFileOpen" << sysPara->sysFile;
|
||||
snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",filePath.toLatin1().constData());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 主动暂停打印
|
||||
if(reviewFlag) {
|
||||
emit sig_stopPrint();
|
||||
|
||||
// xmlfileName 会被 saveLastWork 更改,因此此处暂存变量, 在执行后恢复
|
||||
qDebug() << "xmlfileName:" << xmlfileName;
|
||||
auto filename = xmlfileName;
|
||||
disconnect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),0,0);
|
||||
connect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),this,SLOT(onSaveASFile(QString,bool)), Qt::DirectConnection);
|
||||
dialogSaveFile->saveLastWork();
|
||||
xmlfileName = filename;
|
||||
disconnect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),0,0);
|
||||
}
|
||||
|
||||
emit sendButtonClickedSignal(20); //打开文件完成跳转到主窗口
|
||||
}
|
||||
if(editMode != SCENE || !filePath.endsWith(".xml")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
extern QStringList stringListRecive;
|
||||
|
||||
void TestPrintWidget::parseVbfile(QXmlStreamReader &reader, bool loadPrintSetting) {
|
||||
// int textItemPosX;
|
||||
// int textItemPosY;
|
||||
// textItemPosX = picText->pos().x() - pPicScene->itemsBoundingRect().x();
|
||||
// textItemPosY = picText->pos().y() - pPicScene->itemsBoundingRect().y();
|
||||
float pos_x,pos_y;
|
||||
bool Condition= false ;
|
||||
int CatchStartValue = -1;
|
||||
int CatchValue = -1;
|
||||
|
||||
QXmlStreamAttributes itemAttrs;
|
||||
|
||||
while (!reader.atEnd()) {
|
||||
reader.readNext();
|
||||
if (reader.isStartElement()) { // 开始元素
|
||||
QString strElementName = reader.name().toString();
|
||||
if (QString::compare(strElementName, "VBfile") == 0) {
|
||||
//qDebug() << QString::fromLocal8Bit("********** 开始元素<VBfile> ********** ");
|
||||
} else if (QString::compare(strElementName, QString("pointer_x")) == 0) { // 方式一
|
||||
reader.readNext();
|
||||
if (reader.isCharacters()) {
|
||||
pos_x = reader.text().toString().toDouble();
|
||||
//qDebug() << QString("pointer_x:%1").arg(reader.text().toString());
|
||||
}
|
||||
} else if (QString::compare(strElementName, QString("pointer_y")) == 0) { // 方式二
|
||||
pos_y = reader.readElementText().toDouble();
|
||||
//qDebug() << QString("pointer_y:%1").arg(reader.readElementText());
|
||||
}
|
||||
else if (QString::compare(strElementName, QString("Condition")) == 0) {
|
||||
Condition = reader.readElementText().toInt() ? true : false;
|
||||
}
|
||||
else if (QString::compare(strElementName, QString("CatchStartValue")) == 0) {
|
||||
CatchStartValue = reader.readElementText().toInt();
|
||||
}
|
||||
else if (QString::compare(strElementName, QString("CatchValue")) == 0) {
|
||||
CatchValue = reader.readElementText().toInt();
|
||||
}
|
||||
else if (QString::compare(strElementName, QString("html_src")) == 0) {
|
||||
//qDebug() << QString("html_src:%1").arg(reader.readElementText());
|
||||
}
|
||||
else if(strElementName == "itemAttrs") {
|
||||
itemAttrs = reader.attributes();
|
||||
} else if(strElementName == "PrintSettings" && loadPrintSetting) {
|
||||
|
||||
// 加载打印设置
|
||||
QXmlStreamAttributes attrs = reader.attributes();
|
||||
PrintSettingModel model;
|
||||
PrintSettingModel::loadFromXml(model, attrs);
|
||||
if(m_printSetting) {
|
||||
m_printSetting->setModel(model);
|
||||
m_printSetting->applyPrintSettingsToSysPara(false);
|
||||
}
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
} else if (reader.isEntityReference()) { // 实体引用
|
||||
QString strName = reader.name().toString();
|
||||
QString strText = reader.text().toString();
|
||||
//qDebug() << QString("EntityReference : %1(%2)").arg(strName).arg(strText);
|
||||
} else if (reader.isCDATA()) { // CDATA
|
||||
QString strCDATA = reader.text().toString();
|
||||
//qDebug() << QString("CDATA : %1").arg(strCDATA);
|
||||
PicTextItem *pPictText = nullptr;
|
||||
SourceType sourceType = SourceType::UNKNOWN;
|
||||
bool ok = false;
|
||||
sourceType = SourceType(itemAttrs.value("sourceType").toInt(&ok));
|
||||
switch(sourceType) {
|
||||
case IMAGE:
|
||||
pPictText = new PicImageItem(0, 0);
|
||||
break;
|
||||
case DATETIME:
|
||||
pPictText = new PicDateItem();
|
||||
break;
|
||||
case SCHEDULE_SHIFT:
|
||||
pPictText = new PicScheduleShiftItem();
|
||||
break;
|
||||
case CODE:
|
||||
pPictText = new PicCodeItem();
|
||||
break;
|
||||
|
||||
case COUNTER:
|
||||
pPictText = new PicCounterItem();
|
||||
break;
|
||||
|
||||
case TEXT:
|
||||
default:
|
||||
pPictText = new PicTextItem(0, 0, sourceType);
|
||||
break;
|
||||
}
|
||||
|
||||
pPictText->setAttrs(itemAttrs);
|
||||
|
||||
if(m_CreateImageFlag)
|
||||
{
|
||||
m_pSavePicScene->addItem(pPictText);
|
||||
}
|
||||
else
|
||||
{
|
||||
pPicScene->addItem(pPictText);
|
||||
}
|
||||
QFont font = pPictText->font();
|
||||
// font.setLetterSpacing(QFont::AbsoluteSpacing,sysPara->para.textEditCharSpace);
|
||||
pPictText->setPos(pos_x,pos_y);
|
||||
pPictText->SpecialConditions = Condition;
|
||||
pPictText->CatchCnt1StartValue = CatchStartValue;
|
||||
pPictText->CatchCnt1CurrValue = CatchValue;
|
||||
|
||||
itemAttrs.clear();
|
||||
|
||||
// Condition= false ;
|
||||
// CatchValue = -1;
|
||||
//LogInfo::setRunStatusText(tr("接收文件解析::2"));
|
||||
if(sysPara!=nullptr && !sysPara->status.forTemplateUse || m_CreateImageFlag)
|
||||
{
|
||||
pPictText->setHtml(strCDATA);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
//qDebug() << tr("接收文件解析:");
|
||||
//LogInfo::setRunStatusText(tr("接收文件解析::3"));
|
||||
//stringListRecive << "aaaa" << "bbbb" << "cccc";
|
||||
if(strCDATA.contains("#1111") || strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#01.bmp\" />"))
|
||||
{
|
||||
if(stringListRecive.size() > 0)
|
||||
{
|
||||
if(strCDATA.contains("#1111"))
|
||||
{
|
||||
strCDATA.replace("#1111",stringListRecive.at(0).toStdString().c_str());
|
||||
}
|
||||
else if(strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#01.bmp\" />"))
|
||||
{
|
||||
// emit generateQRCode(stringListRecive.at(0));
|
||||
strCDATA.replace("modbusQR#01.bmp","modbusQR.bmp");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(strCDATA.contains("#2222") || strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#02.bmp\" />"))
|
||||
{
|
||||
if(stringListRecive.size() > 1)
|
||||
{
|
||||
if(strCDATA.contains("#2222"))
|
||||
{
|
||||
strCDATA.replace("#2222",stringListRecive.at(1).toStdString().c_str());
|
||||
}
|
||||
else if(strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#02.bmp\" />"))
|
||||
{
|
||||
// emit generateQRCode(stringListRecive.at(1));
|
||||
strCDATA.replace("modbusQR#02.bmp","modbusQR.bmp");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strCDATA.contains("#3333") || strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#03.bmp\" />"))
|
||||
{
|
||||
if(stringListRecive.size() > 2)
|
||||
{
|
||||
if(strCDATA.contains("#3333"))
|
||||
{
|
||||
strCDATA.replace("#3333",stringListRecive.at(2).toStdString().c_str());
|
||||
}
|
||||
else if(strCDATA.contains("<img src=\"/home/plg/doc/modbusQR#03.bmp\" />"))
|
||||
{
|
||||
// emit generateQRCode(stringListRecive.at(2));
|
||||
strCDATA.replace("modbusQR#03.bmp","modbusQR.bmp");
|
||||
}
|
||||
}
|
||||
}
|
||||
pPictText->setHtml(strCDATA);
|
||||
}
|
||||
Condition= false ;
|
||||
CatchValue = -1;
|
||||
CatchStartValue = -1;
|
||||
|
||||
reader.readNext();
|
||||
if (reader.isCharacters()) {
|
||||
QString strCharacters = reader.text().toString();
|
||||
//qDebug() << QString("Characters : %1").arg(strCharacters);
|
||||
}
|
||||
} else if (reader.isEndElement()) { // 结束元素
|
||||
QString strElementName = reader.name().toString();
|
||||
if (QString::compare(strElementName, "Blogs") == 0) {
|
||||
//qDebug() << QString::fromLocal8Bit("********** 结束元素<Blogs> ********** ");
|
||||
break; // 跳出循环(解析 QXmlStreamReader::EndDocument)
|
||||
} else if (QString::compare(strElementName, "Blog") == 0) {
|
||||
//qDebug() << QString::fromLocal8Bit("********** 结束元素<Blog> ********** ");
|
||||
}
|
||||
}
|
||||
if(reviewFlag) {
|
||||
xmlfileName = filePath;
|
||||
}
|
||||
|
||||
pViewer->viewport()->update();
|
||||
unsigned char SpecialVarEnable = 0;
|
||||
if (sysPara) {
|
||||
sysPara->devOp->fpgaWr(0xa4b0,(unsigned char *)&SpecialVarEnable,1);
|
||||
}
|
||||
|
||||
PrintSettingModel loadedPrintSetting;
|
||||
bool ok = PicSceneLoader::loadSceneFromFile(filePath,
|
||||
pPicScene,
|
||||
reviewFlag ? &loadedPrintSetting : nullptr);
|
||||
if(!ok) {
|
||||
qWarning() << "Failed to load file:" << filePath;
|
||||
return;
|
||||
}
|
||||
|
||||
if(reviewFlag && m_printSetting) {
|
||||
m_printSetting->setModel(loadedPrintSetting);
|
||||
m_printSetting->applyPrintSettingsToSysPara(false);
|
||||
}
|
||||
|
||||
if(sysPara)
|
||||
{
|
||||
sysPara->sysFile = filePath;
|
||||
sysPara->loadParaFromFile();
|
||||
snprintf(sysPara->para.lastOpenedFileName,sizeof(sysPara->para.lastOpenedFileName),"%s",filePath.toLatin1().constData());
|
||||
}
|
||||
|
||||
// 主动暂停打印
|
||||
if(reviewFlag) {
|
||||
emit sig_stopPrint();
|
||||
|
||||
// xmlfileName 会被 saveLastWork 更改,因此此处暂存变量, 在执行后恢复
|
||||
qDebug() << "xmlfileName:" << xmlfileName;
|
||||
auto filename = xmlfileName;
|
||||
disconnect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),0,0);
|
||||
connect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),this,SLOT(onSaveASFile(QString,bool)), Qt::DirectConnection);
|
||||
dialogSaveFile->saveLastWork();
|
||||
xmlfileName = filename;
|
||||
disconnect(dialogSaveFile,SIGNAL(saveFile(QString,bool)),0,0);
|
||||
}
|
||||
|
||||
emit sendButtonClickedSignal(20); //打开文件完成跳转到主窗口
|
||||
}
|
||||
|
||||
void TestPrintWidget::addCodeItem(QString str)
|
||||
|
||||
Reference in New Issue
Block a user