From feeb66073ea682647fc9eda133e41fecc95c4980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D1=81=D0=BE=D0=B2=D0=B8=D0=BA=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sun, 17 Jan 2021 17:03:56 +0000 Subject: [PATCH] Upload New File --- xmlparser.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 xmlparser.cpp diff --git a/xmlparser.cpp b/xmlparser.cpp new file mode 100644 index 0000000..717b1b2 --- /dev/null +++ b/xmlparser.cpp @@ -0,0 +1,45 @@ +#include "xmlparser.h" +#include "ui_mainwindow.h" + +bool XMLParser::startElement(const QString&, + const QString&, + const QString& tagName, + const QXmlAttributes& + ) +{ + if(tagName == "catalog") + treeItem = new QTreeWidgetItem(treeWidget); + + else + treeItem = new QTreeWidgetItem(treeItem); + return true; +} + +// ------------------------------------------------------------------ +bool XMLParser::characters(const QString& strText) +{ + m_strText = ": " + strText; + return true; +} + +// ------------------------------------------------------------------ +bool XMLParser::endElement(const QString&, const QString&, const QString& str) +{ + treeItem->setText(0, str + m_strText); + if(treeItem->parent() && treeItem->parent()->text(0) == "") + treeItem = treeItem->parent(); + m_strText = ""; + if(str == "catalog") + treeItem->setText(0, title); + +return true; +} + +// ------------------------------------------------------------------ +bool XMLParser::fatalError(const QXmlParseException& exception) +{ + QString str = "Line: " + QString::number(exception.lineNumber()) + ", Column: " + QString::number(exception.columnNumber()) + ", Message: " + exception.message(); + QMessageBox::warning(nullptr, "Ошибка", str); + + return false; +} -- GitLab