summaryrefslogtreecommitdiff
path: root/src/contentswidget
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-03-02 17:57:16 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2019-03-02 17:57:16 +0200
commit03cb04bd435ddc5a637166d3188c45bb7391d6a0 (patch)
tree59b5b1f7748a62160c74a58afac12e7b8a9b30a1 /src/contentswidget
downloadcpdf-master.tar.xz
Initial commitHEADmaster
Diffstat (limited to 'src/contentswidget')
-rw-r--r--src/contentswidget/contentswidget.cpp61
-rw-r--r--src/contentswidget/contentswidget.h25
-rw-r--r--src/contentswidget/contentswidget.ui52
3 files changed, 138 insertions, 0 deletions
diff --git a/src/contentswidget/contentswidget.cpp b/src/contentswidget/contentswidget.cpp
new file mode 100644
index 0000000..40ea5f9
--- /dev/null
+++ b/src/contentswidget/contentswidget.cpp
@@ -0,0 +1,61 @@
+#include "contentswidget.h"
+#include "ui_contentswidget.h"
+#include <QDomDocument>
+
+ContentsForm::ContentsForm(QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::ContentsForm)
+{
+ ui->setupUi(this);
+}
+
+ContentsForm::~ContentsForm()
+{
+ delete ui;
+}
+
+QTreeWidgetItem *treeNode(QTreeWidgetItem *parent, const QDomNode &node)
+{
+ auto *item = new QTreeWidgetItem(parent);
+ item->setText(0, node.nodeName());
+
+ if(node.hasAttributes()) {
+ const auto attr = node.attributes();
+ for(int i = 0; i < attr.length(); ++i) {
+ const QString name = attr.item(i).nodeName();
+ const QString value = attr.item(i).nodeValue();
+
+ if(name == "Open")
+ item->setText(1, value);
+ else if(name == "Destination")
+ item->setText(2, value);
+ else
+ qDebug("Unknown attribute name %s\nattr.value=%s", qUtf8Printable(name), qUtf8Printable(value));
+ }
+ }
+
+ auto child = node.firstChild();
+ while(!child.isNull()) {
+ treeNode(item, child);
+ child = child.nextSibling();
+ }
+
+ return item;
+}
+
+void ContentsForm::setContents(QDomDocument *document)
+{
+ ui->treeWidget->clear();
+
+ if(document && !document->isNull()) {
+ auto node = document->firstChild();
+ while(!node.isNull()) {
+ auto *item = treeNode(nullptr, node);
+ ui->treeWidget->addTopLevelItem(item);
+
+ node = node.nextSibling();
+ }
+ }
+ delete document;
+}
+
diff --git a/src/contentswidget/contentswidget.h b/src/contentswidget/contentswidget.h
new file mode 100644
index 0000000..9276bf4
--- /dev/null
+++ b/src/contentswidget/contentswidget.h
@@ -0,0 +1,25 @@
+#ifndef CPDF_CONTENTSWIDGET_H
+#define CPDF_CONTENTSWIDGET_H
+
+#include <QWidget>
+
+namespace Ui {
+ class ContentsForm;
+}
+
+class QDomDocument;
+class ContentsForm : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ContentsForm(QWidget *parent = nullptr);
+ ~ContentsForm();
+
+public slots:
+ void setContents(QDomDocument *document);
+
+private:
+ Ui::ContentsForm *ui = nullptr;
+};
+
+#endif // CPDF_CONTENTSWIDGET_H
diff --git a/src/contentswidget/contentswidget.ui b/src/contentswidget/contentswidget.ui
new file mode 100644
index 0000000..8b74c36
--- /dev/null
+++ b/src/contentswidget/contentswidget.ui
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ContentsForm</class>
+ <widget class="QWidget" name="ContentsForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>240</width>
+ <height>320</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Contents</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTreeWidget" name="treeWidget">
+ <column>
+ <property name="text">
+ <string notr="true">Item</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Destination</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>