
--- GScribo/GScribo.pro | 10 ++- GScribo/GScribo.pro.user | 42 +++++----- GScribo/PagesViewer/pageswidget.cpp | 4 +- GScribo/xmlattributes.cpp | 5 + GScribo/xmlattributes.h | 26 ++++++ GScribo/xmlitem.cpp | 5 + GScribo/xmlitem.h | 44 +++++++++++ GScribo/xmlmodel.cpp | 5 + GScribo/xmlmodel.h | 26 ++++++ XmlTree/XmlTree.pro | 15 +++- XmlTree/XmlTree.pro.user | 48 ++++++------ {GScribo => XmlTree}/configs.h | 14 ++-- XmlTree/main.cpp | 1 + XmlTree/mainwindow.cpp | 11 +-- XmlTree/mainwindow.h | 1 - XmlTree/pointer.h | 19 ----- XmlTree/polygonitem.cpp | 44 +---------- XmlTree/polygonitem.h | 39 +++++++--- XmlTree/treeview.h | 19 +++++ {GScribo => XmlTree}/variantpointer.h | 0 XmlTree/xml.cpp | 137 ++++++++++++++++++--------------- XmlTree/xml.h | 49 +++++++----- XmlTree/xmldelegate.cpp | 12 +++ XmlTree/xmldelegate.h | 21 +++++ XmlTree/xmlitem.cpp | 52 +++++++++++++ XmlTree/xmlitem.h | 71 +++++++++++++++++ XmlTree/xmlmodel.cpp | 104 +++++++++++++++++++++++++ XmlTree/xmlmodel.h | 38 +++++++++ XmlTree/xmlproxy.cpp | 6 ++ XmlTree/xmlproxy.h | 13 +++ XmlTree/xmlwidget.cpp | 12 +++- XmlTree/xmlwidget.h | 16 ++-- 32 files changed, 680 insertions(+), 229 deletions(-) create mode 100644 GScribo/xmlattributes.cpp create mode 100644 GScribo/xmlattributes.h create mode 100644 GScribo/xmlitem.cpp create mode 100644 GScribo/xmlitem.h create mode 100644 GScribo/xmlmodel.cpp create mode 100644 GScribo/xmlmodel.h copy {GScribo => XmlTree}/configs.h (91%) delete mode 100644 XmlTree/pointer.h create mode 100644 XmlTree/treeview.h copy {GScribo => XmlTree}/variantpointer.h (100%) create mode 100644 XmlTree/xmldelegate.cpp create mode 100644 XmlTree/xmldelegate.h create mode 100644 XmlTree/xmlitem.cpp create mode 100644 XmlTree/xmlitem.h create mode 100644 XmlTree/xmlmodel.cpp create mode 100644 XmlTree/xmlmodel.h create mode 100644 XmlTree/xmlproxy.cpp create mode 100644 XmlTree/xmlproxy.h diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro index 42d9e7b..8478bd9 100644 --- a/GScribo/GScribo.pro +++ b/GScribo/GScribo.pro @@ -29,7 +29,10 @@ SOURCES += main.cpp \ Processing/preprocess.cpp \ Processing/runner.cpp \ xml.cpp \ - xmlwidget.cpp + xmlwidget.cpp \ + xmlmodel.cpp \ + xmlitem.cpp \ + xmlattributes.cpp HEADERS += mainwindow.h \ configs.h \ region.h \ @@ -51,7 +54,10 @@ HEADERS += mainwindow.h \ Processing/runner.h \ xml.h \ variantpointer.h \ - xmlwidget.h + xmlwidget.h \ + xmlmodel.h \ + xmlitem.h \ + xmlattributes.h FORMS += mainwindow.ui \ Preferences/preferencesdialog.ui \ Preferences/ocroptions.ui \ diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user index 4d451eb..d01f28d 100644 --- a/GScribo/GScribo.pro.user +++ b/GScribo/GScribo.pro.user @@ -67,35 +67,36 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qmlsXLWJn3,guid=e4b2f30ca8d018ccce50314c0073cc47</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Cbkm7WIjhu,guid=65649d2ae970b655ca196e3400751d1b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-tl4Csb</value> - <value type="QString">GNOME_KEYRING_PID=6905</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xOpurb</value> + <value type="QString">GNOME_KEYRING_PID=2702</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> + <value type="QString">LANGUAGE=</value> <value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value> <value type="QString">LOGNAME=froger_a</value> - <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> + <value type="QString">OLDPWD=/lrde/home/stage/froger_a</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value> <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value> <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=6981</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-Xmeufp6914/agent.6914</value> + <value type="QString">SSH_AGENT_PID=2784</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-UFTNiR2711/agent.2711</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> - <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmHN3NRW</value> + <value type="QString">WINDOWID=12582948</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm6IKTRW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359636746.918575-1681926162</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359722975.26426-1436129248</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -119,35 +120,36 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qmlsXLWJn3,guid=e4b2f30ca8d018ccce50314c0073cc47</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Cbkm7WIjhu,guid=65649d2ae970b655ca196e3400751d1b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-tl4Csb</value> - <value type="QString">GNOME_KEYRING_PID=6905</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xOpurb</value> + <value type="QString">GNOME_KEYRING_PID=2702</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> + <value type="QString">LANGUAGE=</value> <value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator</value> <value type="QString">LOGNAME=froger_a</value> - <value type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</value> + <value type="QString">OLDPWD=/lrde/home/stage/froger_a</value> <value type="QString">PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games</value> <value type="QString">PWD=/lrde/home/stage/froger_a/qt/GScribo</value> <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=6981</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-Xmeufp6914/agent.6914</value> + <value type="QString">SSH_AGENT_PID=2784</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-UFTNiR2711/agent.2711</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> - <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdmHN3NRW</value> + <value type="QString">WINDOWID=12582948</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm6IKTRW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359636746.918575-1681926162</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359722975.26426-1436129248</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> diff --git a/GScribo/PagesViewer/pageswidget.cpp b/GScribo/PagesViewer/pageswidget.cpp index 7140d73..e05d38a 100644 --- a/GScribo/PagesViewer/pageswidget.cpp +++ b/GScribo/PagesViewer/pageswidget.cpp @@ -22,7 +22,7 @@ QStringList PagesWidget::filenames() const return model.filenames(); } -void PagesWidget::getPixmap(const QModelIndex &index) +void PagesWidget::getPixmap(const QModelIndex& index) { // Get the pixmap and the path of the icon to send it to the scene and draw it. QPixmap pixmap = index.data(Qt::UserRole).value<QPixmap>(); @@ -31,7 +31,7 @@ void PagesWidget::getPixmap(const QModelIndex &index) emit sceneChanged(filename, pixmap); } -void PagesWidget::addPixmap(const QString& filename, const QPixmap &pixmap) +void PagesWidget::addPixmap(const QString& filename, const QPixmap& pixmap) { model.addPixmap(filename, pixmap); } diff --git a/GScribo/xmlattributes.cpp b/GScribo/xmlattributes.cpp new file mode 100644 index 0000000..5e2ecfc --- /dev/null +++ b/GScribo/xmlattributes.cpp @@ -0,0 +1,5 @@ +#include "xmlattributes.h" + +XmlAttributes::XmlAttributes() +{ +} diff --git a/GScribo/xmlattributes.h b/GScribo/xmlattributes.h new file mode 100644 index 0000000..af99e6e --- /dev/null +++ b/GScribo/xmlattributes.h @@ -0,0 +1,26 @@ +#ifndef XMLATTRIBUTES_H +#define XMLATTRIBUTES_H + +#include <QDomNamedNodeMap> + +class XmlAttributes +{ + public: + explicit XmlAttributes(XmlAttributes *precItem = 0); + explicit XmlAttributes(const QDomNamedNodeMap& node); + explicit XmlAttributes(const QDomNamedNodeMap& node, XmlAttributes *precItem = 0); + ~XmlAttributes(); + + inline QString name() const; + inline QString value() const; + inline int row(); + + private: + void init(XmlAttributes *precItem = 0); + + QString n; + QString v; + int r; +}; + +#endif // XMLATTRIBUTES_H diff --git a/GScribo/xmlitem.cpp b/GScribo/xmlitem.cpp new file mode 100644 index 0000000..bf82191 --- /dev/null +++ b/GScribo/xmlitem.cpp @@ -0,0 +1,5 @@ +#include "xmlitem.h" + +XmlItem::XmlItem() +{ +} diff --git a/GScribo/xmlitem.h b/GScribo/xmlitem.h new file mode 100644 index 0000000..a45c81c --- /dev/null +++ b/GScribo/xmlitem.h @@ -0,0 +1,44 @@ +#ifndef XMLITEM_H +#define XMLITEM_H + +#include <QDomElement> + +#include "Rendering/polygonitem.h" +#include "xmlattributes.h" + +class XmlItem +{ + public: + explicit XmlItem(XmlItem *parent = 0); + explicit XmlItem(XmlItem *precItem, XmlItem *parent = 0); + explicit XmlItem(const QDomElement& node, XmlItem *parent = 0); + explicit XmlItem(const QDomElement& node, XmlItem precItem, XmlItem *parent = 0); + ~XmlItem(); + + void load(const QDomElement& node); + + inline QList<XmlItem *> childs() const; + inline XmlItem *child(int i) const; + inline void setChild(XmlItem *child); + + inline XmlItem *parent() const; + inline void setParent(XmlItem *parent); + + inline PolygonItem *graphicalItem(); + inline void setGraphicalItem(PolygonItem *graphicalItem); + + inline QString text() const; + inline int row() const; + inline XmlAttributes *attributes() const; + + private: + void init(XmlItem *parent = 0, XmlItem *precItem = 0); + + QList<XmlItem *> lChilds; + XmlItem *par; + PolygonItem *graphItem; + QString name; + XmlAttributes *attrs; +}; + +#endif // XMLITEM_H diff --git a/GScribo/xmlmodel.cpp b/GScribo/xmlmodel.cpp new file mode 100644 index 0000000..728d601 --- /dev/null +++ b/GScribo/xmlmodel.cpp @@ -0,0 +1,5 @@ +#include "xmlmodel.h" + +XmlModel::XmlModel() +{ +} diff --git a/GScribo/xmlmodel.h b/GScribo/xmlmodel.h new file mode 100644 index 0000000..33c54f0 --- /dev/null +++ b/GScribo/xmlmodel.h @@ -0,0 +1,26 @@ +#ifndef XMLMODEL_H +#define XMLMODEL_H + +#include <QAbstractItemModel> + +class XmlModel : + public QAbstractItemModel +{ + public: + explicit XmlModel(QObject *parent); + ~XmlModel(); + + inline int rowCount(const QModelIndex &parent) const; + inline int columnCount(const QModelIndex &parent) const; + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role) const; + + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &child) const; + + private: + +}; + +#endif // XMLMODEL_H diff --git a/XmlTree/XmlTree.pro b/XmlTree/XmlTree.pro index f3f3df2..f5205b2 100644 --- a/XmlTree/XmlTree.pro +++ b/XmlTree/XmlTree.pro @@ -8,11 +8,20 @@ SOURCES += main.cpp \ mainwindow.cpp \ xmlwidget.cpp \ xml.cpp \ - polygonitem.cpp + polygonitem.cpp \ + xmlmodel.cpp \ + xmlitem.cpp \ + xmlproxy.cpp \ + xmldelegate.cpp HEADERS += mainwindow.h \ xmlwidget.h \ xml.h \ - pointer.h \ + region.h \ polygonitem.h \ - region.h + variantpointer.h \ + configs.h \ + xmlmodel.h \ + xmlitem.h \ + xmlproxy.h \ + xmldelegate.h FORMS += mainwindow.ui diff --git a/XmlTree/XmlTree.pro.user b/XmlTree/XmlTree.pro.user index 847bc66..7cf0eb5 100644 --- a/XmlTree/XmlTree.pro.user +++ b/XmlTree/XmlTree.pro.user @@ -76,14 +76,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-eapkGsqUHQ,guid=856e00f0cd1b8664a4a8a6ce006f8d7e</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Cbkm7WIjhu,guid=65649d2ae970b655ca196e3400751d1b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-bwEU7s</value> - <value type="QString">GNOME_KEYRING_PID=2961</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xOpurb</value> + <value type="QString">GNOME_KEYRING_PID=2702</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -95,16 +95,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=3036</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yHlEXz2970/agent.2970</value> + <value type="QString">SSH_AGENT_PID=2784</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-UFTNiR2711/agent.2711</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm5EEHRW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm6IKTRW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359358530.347400-806764092</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359722975.26426-1436129248</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -128,14 +128,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-eapkGsqUHQ,guid=856e00f0cd1b8664a4a8a6ce006f8d7e</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Cbkm7WIjhu,guid=65649d2ae970b655ca196e3400751d1b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-bwEU7s</value> - <value type="QString">GNOME_KEYRING_PID=2961</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xOpurb</value> + <value type="QString">GNOME_KEYRING_PID=2702</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -147,16 +147,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=3036</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yHlEXz2970/agent.2970</value> + <value type="QString">SSH_AGENT_PID=2784</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-UFTNiR2711/agent.2711</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm5EEHRW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm6IKTRW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359358530.347400-806764092</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359722975.26426-1436129248</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> @@ -177,14 +177,14 @@ <valuemap type="QVariantMap"> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value> <valuelist key="abstractProcess.Environment" type="QVariantList"> - <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-eapkGsqUHQ,guid=856e00f0cd1b8664a4a8a6ce006f8d7e</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Cbkm7WIjhu,guid=65649d2ae970b655ca196e3400751d1b</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> <value type="QString">GDM_LANG=fr_FR.UTF-8</value> <value type="QString">GDM_XSERVER_LOCATION=local</value> - <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-bwEU7s</value> - <value type="QString">GNOME_KEYRING_PID=2961</value> + <value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-xOpurb</value> + <value type="QString">GNOME_KEYRING_PID=2702</value> <value type="QString">GTK_MODULES=canberra-gtk-module</value> <value type="QString">HOME=/lrde/home/stage/froger_a</value> <value type="QString">LANG=fr_FR.UTF-8</value> @@ -196,16 +196,16 @@ <value type="QString">QTDIR=/usr/share/qt4</value> <value type="QString">SHELL=/bin/bash</value> <value type="QString">SHLVL=2</value> - <value type="QString">SSH_AGENT_PID=3036</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-yHlEXz2970/agent.2970</value> + <value type="QString">SSH_AGENT_PID=2784</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-UFTNiR2711/agent.2711</value> <value type="QString">TERM=xterm</value> <value type="QString">USER=froger_a</value> <value type="QString">USERNAME=froger_a</value> <value type="QString">WINDOWID=10485796</value> - <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> - <value type="QString">XAUTHORITY=/tmp/.gdm5EEHRW</value> + <value type="QString">WINDOWPATH=7:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8:8</value> + <value type="QString">XAUTHORITY=/tmp/.gdm6IKTRW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359358530.347400-806764092</value> + <value type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359722975.26426-1436129248</value> <value type="QString">XPSERVERLIST=:64 </value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> diff --git a/GScribo/configs.h b/XmlTree/configs.h similarity index 91% copy from GScribo/configs.h copy to XmlTree/configs.h index 594650f..74968c9 100644 --- a/GScribo/configs.h +++ b/XmlTree/configs.h @@ -1,7 +1,7 @@ #ifndef CONFIGS_H #define CONFIGS_H -#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> +//#include <scribo/toolchain/internal/text_in_doc_preprocess_functor.hh> #include <QSettings> #include <QDir> @@ -28,8 +28,8 @@ class Configs : inline bool preprocessingRemoveNoise(); inline void setPreprocessingRemoveNoise(bool b); - inline int preprocessingBinAlgo(); - inline void setPreprocessingBinAlgo(int algo); + /*inline int preprocessingBinAlgo(); + inline void setPreprocessingBinAlgo(int algo);*/ inline int segmentationFindSeps(); inline void setSegmentationFindSeps(int seps); @@ -77,11 +77,11 @@ inline bool Configs::preprocessingRemoveNoise() inline void Configs::setPreprocessingRemoveNoise(bool b) { setValue("preprocessing/remove_noise", b); } -inline int Configs::preprocessingBinAlgo() -{ return value("preprocessing/bin_algo", scribo::toolchain::internal::SauvolaMs).toInt(); } +/*inline int Configs::preprocessingBinAlgo() +{ return value("preprocessing/bin_algo", scribo::toolchain::internal::SauvolaMs).toInt(); }*/ -inline void Configs::setPreprocessingBinAlgo(int algo) -{ setValue("preprocessing/bin_algo", algo); } +/*inline void Configs::setPreprocessingBinAlgo(int algo) +{ setValue("preprocessing/bin_algo", algo); }*/ inline int Configs::segmentationFindSeps() { return value("segmentation/find_seps", Separator::Both).toInt(); } diff --git a/XmlTree/main.cpp b/XmlTree/main.cpp index 6e7efd9..3d5e575 100644 --- a/XmlTree/main.cpp +++ b/XmlTree/main.cpp @@ -1,4 +1,5 @@ #include <QtGui/QApplication> + #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/XmlTree/mainwindow.cpp b/XmlTree/mainwindow.cpp index 26729b7..e76f576 100644 --- a/XmlTree/mainwindow.cpp +++ b/XmlTree/mainwindow.cpp @@ -9,15 +9,8 @@ MainWindow::MainWindow(QWidget *parent) : xml.load("/tmp/mp00082c_gui.xml"); - //xmlWidget.load(xml.treeItem()); - - view = new QGraphicsView(new QGraphicsScene()); - - QGraphicsItem *item; - foreach(item, xml.graphicsItems()) - view->scene()->addItem(item); - - setCentralWidget(view); + XmlWidget *xmlWidget = new XmlWidget(xml.treeItem()); + setCentralWidget(&xmlWidget->tree); } MainWindow::~MainWindow() diff --git a/XmlTree/mainwindow.h b/XmlTree/mainwindow.h index 221d43d..98c4c68 100644 --- a/XmlTree/mainwindow.h +++ b/XmlTree/mainwindow.h @@ -27,7 +27,6 @@ class MainWindow : private: Ui::MainWindow *ui; QGraphicsView *view; - XmlWidget xmlWidget; Xml xml; }; diff --git a/XmlTree/pointer.h b/XmlTree/pointer.h deleted file mode 100644 index 7a84c47..0000000 --- a/XmlTree/pointer.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef POINTER_H -#define POINTER_H - -#include <QVariant> - -template<typename T> class Pointer -{ - public: - static inline QVariant toQVariant(T *pointer) - { return QVariant::fromValue((void *)pointer); } - - static inline T *fromQVariant(const QVariant& variant) - { return (T *)variant.value<void *>(); } - - private: - Pointer() { } -}; - -#endif // POINTER_H diff --git a/XmlTree/polygonitem.cpp b/XmlTree/polygonitem.cpp index 6bdcd3e..b447e28 100644 --- a/XmlTree/polygonitem.cpp +++ b/XmlTree/polygonitem.cpp @@ -29,48 +29,12 @@ void PolygonItem::init() void PolygonItem::setColor(const QColor &color) { - selectedPen.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 200)); + selectedPen.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 255)); unselectedPen.setColor(color); selectedBrush.setColor(color); - unselectedBrush.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 30)); + unselectedBrush.setColor(QColor::fromRgb(color.red(), color.green(), color.blue(), 40)); - setPen(selectedPen); - setBrush(selectedBrush); -} - -QColor PolygonItem::color() const -{ - return selectedBrush.color(); -} - -void PolygonItem::repaint(const QRectF& rect, bool clic) -{ - bool sel; - - // For optimization, do first an intersection by bounding rectangle beetween items and selection and then an intersection by shape. - if(clic) - sel = (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().contains(rect.bottomRight())) && shape().contains(rect.bottomRight()); - else - sel = (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().intersects(rect)) && shape().intersects(rect); - - // Change items brush and pen if it's selectionned or not. - if(sel) - { - if(pen() != selectedPen) - { - setPen(selectedPen); - setBrush(selectedBrush); - update(rect); - } - } - else - { - if(pen() != unselectedPen) - { - setPen(unselectedPen); - setBrush(unselectedBrush); - update(rect); - } - } + setPen(unselectedPen); + setBrush(unselectedBrush); } diff --git a/XmlTree/polygonitem.h b/XmlTree/polygonitem.h index 0e8377d..ca32774 100644 --- a/XmlTree/polygonitem.h +++ b/XmlTree/polygonitem.h @@ -1,26 +1,30 @@ #ifndef POLYGONITEM_H #define POLYGONITEM_H -#include <QGraphicsPathItem> +#include <QGraphicsPolygonItem> +#include <QTreeWidgetItem> #include <QPen> +#include "variantpointer.h" #include "region.h" class PolygonItem : - public QObject, public QGraphicsPolygonItem { - Q_OBJECT - public: explicit PolygonItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); explicit PolygonItem(const QPolygonF& path, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); void setColor(const QColor& color); - QColor color() const; + inline QColor color() const; inline void loadData(const GraphicRegion::Data& data); + inline bool isSelected(const QRectF& rect, bool clic); + inline void unselect(); + inline void select(); + inline void setSelected(bool selected); + private: void init(); @@ -28,16 +32,29 @@ class PolygonItem : QPen unselectedPen; QBrush selectedBrush; QBrush unselectedBrush; - - public slots: - void repaint(const QRectF& rect, bool clic); }; +inline QColor PolygonItem::color() const +{ return selectedBrush.color(); } + inline void PolygonItem::loadData(const GraphicRegion::Data &data) +{ setData(0, data.region); setColor(data.color); setZValue(data.zValue); } + +inline bool PolygonItem::isSelected(const QRectF &rect, bool clic) { - setData(0, data.region); - setColor(data.color); - setZValue(data.zValue); + if(clic) + return (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().contains(rect.bottomRight())) && shape().contains(rect.bottomRight()); + else + return (boundingRect().width() == 0 || boundingRect().height() == 0 || boundingRect().intersects(rect)) && shape().intersects(rect); } +inline void PolygonItem::select() +{ if(pen() != selectedPen) { setPen(selectedPen); setBrush(selectedBrush); } } + +inline void PolygonItem::unselect() +{ if(pen() != unselectedPen) { setPen(unselectedPen); setBrush(unselectedBrush); } } + +inline void PolygonItem::setSelected(bool selected) +{ if(selected) select(); else unselect(); } + #endif // POLYGONITEM_H diff --git a/XmlTree/treeview.h b/XmlTree/treeview.h new file mode 100644 index 0000000..4321f34 --- /dev/null +++ b/XmlTree/treeview.h @@ -0,0 +1,19 @@ +#ifndef TREEVIEW_H +#define TREEVIEW_H + +#include <QTreeView> + +#include "xmlmodel.h" + +class TreeView : public QTreeView +{ + public: + explicit TreeView(QWidget *parent); + explicit TreeView(QTreeViewPrivate& dd, QWidget *parent); + explicit TreeView(const QTreeView& view); + + private: + XmlModel model; +}; + +#endif // TREEVIEW_H diff --git a/GScribo/variantpointer.h b/XmlTree/variantpointer.h similarity index 100% copy from GScribo/variantpointer.h copy to XmlTree/variantpointer.h diff --git a/XmlTree/xml.cpp b/XmlTree/xml.cpp index 8dd9d17..5931e92 100644 --- a/XmlTree/xml.cpp +++ b/XmlTree/xml.cpp @@ -2,131 +2,147 @@ static const GraphicRegion::Data itemsData[] = { - /* COLOR | NAME | REGION | ZVALUE */ - { QColor::fromRgb(255, 0, 0, 80), "Line", (int)GraphicRegion::Line, 2 }, - { QColor::fromRgb(0, 100, 0, 80), "TextRegion", (int)GraphicRegion::Text, 1 }, - { QColor::fromRgb(0, 0, 255, 60), "VerticalSeparatorRegion", (int)GraphicRegion::VerticalSeparator, 2 }, - { QColor::fromRgb(0, 0, 255, 60), "HorizontalSeparatorRegion", (int)GraphicRegion::HorizontalSeparator, 2 }, - { QColor::fromRgb(0, 0, 128, 60), "WhitespaceSeparatorRegion", (int)GraphicRegion::WhiteSpaceSeparator, 2 }, - { QColor::fromRgb(255, 120, 0, 60), "ImageRegion", (int)GraphicRegion::Image, 1 }, - { QColor::fromRgb(43, 39, 128, 60), "NoiseRegion", (int)GraphicRegion::Noise, 2 }, - { QColor::fromRgb(220, 246, 0, 60), "TableRegion", (int)GraphicRegion::Table, 2 }, - { QColor::fromRgb(170, 0, 255, 60), "MathsRegion", (int)GraphicRegion::Maths, 2 }, - { QColor::fromRgb(255, 0, 144, 60), "GraphicRegion", (int)GraphicRegion::Graphic, 2 }, - { QColor::fromRgb(0, 204, 255, 60), "ChartRegion", (int)GraphicRegion::Chart, 2 } + /* COLOR | NAME | REGION | ZVALUE */ + { QColor::fromRgb(255, 0, 0, 90), "Line", (int)GraphicRegion::Line, 2 }, + { QColor::fromRgb(0, 100, 0, 90), "TextRegion", (int)GraphicRegion::Text, 1 }, + { QColor::fromRgb(0, 0, 255, 90), "VerticalSeparatorRegion", (int)GraphicRegion::VerticalSeparator, 2 }, + { QColor::fromRgb(0, 0, 255, 90), "HorizontalSeparatorRegion", (int)GraphicRegion::HorizontalSeparator, 2 }, + { QColor::fromRgb(0, 0, 128, 90), "WhitespaceSeparatorRegion", (int)GraphicRegion::WhiteSpaceSeparator, 2 }, + { QColor::fromRgb(255, 120, 0, 90), "ImageRegion", (int)GraphicRegion::Image, 1 }, + { QColor::fromRgb(43, 39, 128, 90), "NoiseRegion", (int)GraphicRegion::Noise, 2 }, + { QColor::fromRgb(220, 246, 0, 90), "TableRegion", (int)GraphicRegion::Table, 2 }, + { QColor::fromRgb(170, 0, 255, 90), "MathsRegion", (int)GraphicRegion::Maths, 2 }, + { QColor::fromRgb(255, 0, 144, 90), "GraphicRegion", (int)GraphicRegion::Graphic, 2 }, + { QColor::fromRgb(0, 204, 255, 90), "ChartRegion", (int)GraphicRegion::Chart, 2 } }; Xml::Xml(const QString &filename) { + gItem = 0; + tItem = 0; + + path = filename; load(filename); } +QString Xml::getPath(const QString &filename) +{ + // Get instance of the configuration settings. + Configs *const conf = Configs::getInstance(); + + QString xmlPath = filename; + + // Get xml filename from image path. + xmlPath.remove(0, xmlPath.lastIndexOf('/')+1); + int pos = xmlPath.lastIndexOf('.'); + xmlPath.remove(pos, xmlPath.length()-pos); + xmlPath += "_gui.xml"; + + return conf->generalSaveXmlCustomDirPath() + "/" + xmlPath; +} + void Xml::load(const QString &filename) { if(!filename.isEmpty()) { + // Reset graphic and tree items; + tItem = new XmlItem; + gItem = new QGraphicsPolygonItem; + QFile xmlFile(filename); xmlFile.open(QIODevice::ReadOnly); - QDomDocument xml; + // Fill new xml tree. + xml.clear(); xml.setContent(&xmlFile); xmlFile.close(); QDomElement root = xml.documentElement(); - tItems.setText(0, root.tagName()); + tItem->load(root); root = root.firstChild().toElement(); - QTreeWidgetItem *parentTreeItem = init(root, &tItems); + XmlItem *parentTreeItem = init(root, tItem); // Run through the xml file structure by structure. root = root.nextSibling().firstChild().toElement(); - for(int i = 1; i < 10; i++) + processNode(root, itemsData[1], parentTreeItem); + for(int i = 2; i < 10; i++) processNode(root.nextSiblingElement(itemsData[i].name), itemsData[i], parentTreeItem); } } -QTreeWidgetItem *Xml::init(const QDomElement& root, QTreeWidgetItem *rootTreeItem) +XmlItem *Xml::init(const QDomElement& root, XmlItem *rootTreeItem) { QDomElement node = root; - QString nodeText; - QTreeWidgetItem *parentTreeItem = new QTreeWidgetItem(rootTreeItem); - parentTreeItem->setText(0, node.tagName()); + XmlItem *parentTreeItem = new XmlItem(node, rootTreeItem); - QTreeWidgetItem *treeItem, *childTreeItem; - node = node.firstChild().toElement(); + QString nodeText; + XmlItem *treeItem = 0; // Run through "METADATA" node and subnodes. + node = node.firstChild().toElement(); while(!node.isNull()) { - treeItem = new QTreeWidgetItem(parentTreeItem, treeItem); - treeItem->setText(0, node.tagName()); - - // Add widget item child with text content. - nodeText = node.text(); - childTreeItem = new QTreeWidgetItem(treeItem); - childTreeItem->setText(0, nodeText); - + treeItem = new XmlItem(node, parentTreeItem, treeItem); node = node.nextSibling().toElement(); } // Add "PAGE" root node and return it. - parentTreeItem = new QTreeWidgetItem(rootTreeItem, parentTreeItem); - parentTreeItem->setText(0, root.nextSibling().toElement().tagName()); - + parentTreeItem = new XmlItem(root.nextSibling().toElement(), rootTreeItem, parentTreeItem); return parentTreeItem; } -void Xml::processNode(const QDomElement& root, const GraphicRegion::Data& data, QTreeWidgetItem *rootTreeItem) +void Xml::processNode(const QDomElement& root, const GraphicRegion::Data& data, XmlItem *rootTreeItem) { if(!root.isNull()) { // Create corresponding tree item. - QTreeWidgetItem *parentTreeItem = fillWidgetItem(root.tagName(), rootTreeItem); - QTreeWidgetItem *treeItem; + XmlItem *parentTreeItem = new XmlItem(root, rootTreeItem); + XmlItem *parentItem = new XmlItem(root.firstChild().toElement(), parentTreeItem); QPolygon polygon; - QString sx, sy; + QString x, y; + XmlItem *item = 0; // Run through all points data. QDomElement node = root.firstChild().firstChild().toElement(); while(!node.isNull()) { - sx = node.attribute("x", "null"); - sy = node.attribute("y", "null"); + x = node.attribute("x", "null"); + y = node.attribute("y", "null"); - treeItem = new QTreeWidgetItem(parentTreeItem, treeItem); - treeItem->setText(0, node.tagName() + " = " + sx + ", " + sy); + item = new XmlItem(node, parentItem, item); - polygon << QPoint(sx.toInt(), sy.toInt()); + polygon << QPoint(x.toInt(), y.toInt()); node = node.nextSibling().toElement(); } // Create the graphical item from data structure. - PolygonItem *polygonItem = new PolygonItem(polygon); + PolygonItem *polygonItem = new PolygonItem(polygon, gItem); polygonItem->loadData(data); - gItems << polygonItem; + parentTreeItem->setGraphicalItem(polygonItem); if(data.region == GraphicRegion::Text) - processLineNode(root.firstChild().nextSiblingElement("Line"), polygonItem, parentTreeItem->parent()); + processLineNode(root.firstChild().nextSiblingElement("Line"), polygonItem, parentTreeItem); // Run through all nodes from the same data structure recursively. processNode(root.nextSiblingElement(data.name), data, rootTreeItem); } } -void Xml::processLineNode(const QDomElement& root, PolygonItem *parentPolygonItem, QTreeWidgetItem *rootTreeItem) +void Xml::processLineNode(const QDomElement& root, PolygonItem *parentPolygonItem, XmlItem *rootTreeItem) { if(!root.isNull()) { // Create corresponding tree item. - QTreeWidgetItem *parentTreeItem = fillWidgetItem(root.tagName(), rootTreeItem); - QTreeWidgetItem *treeItem; + XmlItem *parentTreeItem = new XmlItem(root, rootTreeItem, rootTreeItem->child(0)); + XmlItem *parentItem = new XmlItem(root.firstChild().toElement(), parentTreeItem); + XmlItem *item = 0; QPolygon polygon; - QString sx, sy; - int x, y; + QString x, y; int xMin = INT_MAX; int xMax = INT_MIN; @@ -135,28 +151,25 @@ void Xml::processLineNode(const QDomElement& root, PolygonItem *parentPolygonIte QDomElement node = root.firstChild().firstChild().toElement(); while(!node.isNull()) { - sx = node.attribute("x", "null"); - sy = node.attribute("y", "null"); - - treeItem = new QTreeWidgetItem(parentTreeItem, treeItem); - treeItem->setText(0, node.tagName() + " = " + sx + ", " + sy); + x = node.attribute("x", "null"); + y = node.attribute("y", "null"); - x = sx.toInt(); - y = sy.toInt(); + item = new XmlItem(node, parentItem, item); // Get beginning and end of line. - if(xMin > x) - xMin = x; - if(xMax < x) - xMax = x; + if(xMin > x.toInt()) + xMin = x.toInt(); + if(xMax < x.toInt()) + xMax = x.toInt(); - polygon << QPoint(x, y); + polygon << QPoint(x.toInt(), y.toInt()); node = node.nextSibling().toElement(); } // Create the graphical item from data structure. PolygonItem *polygonItem = new PolygonItem(polygon, parentPolygonItem); polygonItem->loadData(itemsData[0]); + parentTreeItem->setGraphicalItem(polygonItem); // Get meanline and baseline. processTypoNode(root, QPoint(xMin, xMax), polygonItem); diff --git a/XmlTree/xml.h b/XmlTree/xml.h index 9abec4e..5ab1c31 100644 --- a/XmlTree/xml.h +++ b/XmlTree/xml.h @@ -1,7 +1,6 @@ #ifndef XML_H #define XML_H -#include <QTreeWidgetItem> #include <QGraphicsItem> #include <QStringList> #include <QDomElement> @@ -9,42 +8,54 @@ #include <QFile> #include "polygonitem.h" +#include "variantpointer.h" +#include "xmlitem.h" +#include "configs.h" #include "region.h" -class Xml : - QObject +class Xml { - Q_OBJECT - public: explicit Xml(const QString& filename = QString()); + inline XmlItem *treeItem(); + inline QGraphicsItem *graphicItem(); + inline QDomDocument document() const; + inline QString filename() const; + + static QString getPath(const QString& filename); void load(const QString& filename); - inline QTreeWidgetItem *treeItem(); - inline QList<QGraphicsItem *> graphicsItems(); private: - QTreeWidgetItem *init(const QDomElement& root, QTreeWidgetItem *rootTreeItem); - inline QTreeWidgetItem *fillWidgetItem(const QString& tagName, QTreeWidgetItem *rootTreeItem); - void processNode(const QDomElement& root, const GraphicRegion::Data& data, QTreeWidgetItem *rootTreeItem); - void processLineNode(const QDomElement& root, PolygonItem *parentPolygonItem, QTreeWidgetItem *rootTreeItem); + XmlItem *init(const QDomElement& root, XmlItem *rootTreeItem); + //inline QTreeWidgetItem *fillWidgetItem(const QString& tagName, QTreeWidgetItem *rootTreeItem); + void processNode(const QDomElement& root, const GraphicRegion::Data& data, XmlItem *rootTreeItem); + void processLineNode(const QDomElement& root, PolygonItem *parentPolygonItem, XmlItem *rootTreeItem); void processTypoNode(const QDomElement& root, const QPoint& xPoint, PolygonItem *rootPolygonItem); - QList<QGraphicsItem *> gItems; - QTreeWidgetItem tItems; + QGraphicsPolygonItem *gItem; + XmlItem *tItem; + QDomDocument xml; + QString path; }; -inline QTreeWidgetItem *Xml::treeItem() -{ return &tItems; } +inline XmlItem *Xml::treeItem() +{ return tItem; } + +inline QGraphicsItem *Xml::graphicItem() +{ return gItem; } + +inline QDomDocument Xml::document() const +{ return xml; } -inline QList<QGraphicsItem *> Xml::graphicsItems() -{ return gItems; } +inline QString Xml::filename() const +{ return path; } -inline QTreeWidgetItem *Xml::fillWidgetItem(const QString& tagName, QTreeWidgetItem *rootTreeItem) +/*inline XmlItem *Xml::fillWidgetItem(const QString& tagName, QTreeWidgetItem *rootTreeItem) { QTreeWidgetItem *treeItem = new QTreeWidgetItem(rootTreeItem, QStringList(tagName)); treeItem = new QTreeWidgetItem(treeItem, QStringList("Coords")); return treeItem; -} +}*/ #endif // XML_H diff --git a/XmlTree/xmldelegate.cpp b/XmlTree/xmldelegate.cpp new file mode 100644 index 0000000..b4d2941 --- /dev/null +++ b/XmlTree/xmldelegate.cpp @@ -0,0 +1,12 @@ +#include "xmldelegate.h" + +XmlDelegate::XmlDelegate(QObject *parent) : + QStyledItemDelegate(parent) +{ +} + +void XmlDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QStyledItemDelegate::paint(painter, option, index); + painter->drawText(option.rect, index.data(Qt::UserRole).toString()); +} diff --git a/XmlTree/xmldelegate.h b/XmlTree/xmldelegate.h new file mode 100644 index 0000000..ebd54c3 --- /dev/null +++ b/XmlTree/xmldelegate.h @@ -0,0 +1,21 @@ +#ifndef XMLDELEGATE_H +#define XMLDELEGATE_H + +#include <QStyledItemDelegate> +#include <QPainter> +#include <QSpinBox> +#include <QLabel> + +class XmlDelegate : + public QStyledItemDelegate +{ + public: + explicit XmlDelegate(QObject *parent = 0); + + //QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + /*void setEditorData(QWidget *editor, const QModelIndex& index) const; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;*/ +}; + +#endif // XMLDELEGATE_H diff --git a/XmlTree/xmlitem.cpp b/XmlTree/xmlitem.cpp new file mode 100644 index 0000000..b72a682 --- /dev/null +++ b/XmlTree/xmlitem.cpp @@ -0,0 +1,52 @@ +#include "xmlitem.h" + +XmlItem::XmlItem(XmlItem *parent, XmlItem *precItem) +{ + init(parent, precItem); +} + +XmlItem::XmlItem(const QDomElement &node, XmlItem *parent, XmlItem *precItem) +{ + init(parent, precItem); + load(node); +} + +XmlItem::~XmlItem() +{ + // Delete all childs. + XmlItem *child; + foreach(child, childs()) + delete child; +} + +void XmlItem::init(XmlItem *parent, XmlItem *precItem) +{ + if(parent) + parent->addChild(this); + + gItem = 0; + father = parent; + + if(precItem) + row = precItem->rowCount()+1; + else + row = 0; +} + +void XmlItem::load(const QDomElement& node) +{ + tagName = node.tagName(); + + // Load node attributes. + QDomNamedNodeMap nodeMap = node.attributes(); + QDomAttr attr; + QStringList values; + + for(int i = 0; i < nodeMap.count(); i++) + { + attr = nodeMap.item(i).toAttr(); + values << attr.name() << attr.value(); + + attrs << values; + } +} diff --git a/XmlTree/xmlitem.h b/XmlTree/xmlitem.h new file mode 100644 index 0000000..d9e4aa3 --- /dev/null +++ b/XmlTree/xmlitem.h @@ -0,0 +1,71 @@ +#ifndef XMLITEM_H +#define XMLITEM_H + +#include <QDomElement> + +#include "polygonitem.h" + +class XmlItem +{ + public: + explicit XmlItem(XmlItem *parent = 0, XmlItem *precItem = 0); + explicit XmlItem(const QDomElement& node, XmlItem *parent = 0, XmlItem *precItem = 0); + ~XmlItem(); + + void load(const QDomElement& node); + + inline QList<XmlItem *> childs() const; + inline void addChild(XmlItem *child); + inline XmlItem *child(int i); + inline XmlItem *parent(); + + inline PolygonItem *graphicalItem() const; + inline void setGraphicalItem(PolygonItem *graphicalItem); + + inline QString text() const; + inline QList<QStringList> attributes() const; + inline int rowCount() const; + + private: + void init(XmlItem *parent = 0, XmlItem *precItem = 0); + + QList<XmlItem *> listChilds; + XmlItem *father; + PolygonItem *gItem; + + QString tagName; + QList<QStringList> attrs; + + int row; +}; + +inline QList<XmlItem *> XmlItem::childs() const +{ return listChilds; } + +inline void XmlItem::addChild(XmlItem *child) +{ listChilds << child; } + +inline XmlItem *XmlItem::child(int i) +{ if(i > -1 && i < listChilds.count()) return listChilds[i]; return 0; } + +inline XmlItem *XmlItem::parent() +{ return father; } + +inline PolygonItem *XmlItem::graphicalItem() const +{ return gItem; } + +inline void XmlItem::setGraphicalItem(PolygonItem *graphicalItem) +{ gItem = graphicalItem; } + +inline QString XmlItem::text() const +{ return tagName; } + +inline QList<QStringList> XmlItem::attributes() const +{ return attrs; } + +inline int XmlItem::rowCount() const +{ return row; } + +Q_DECLARE_METATYPE(XmlItem); + +#endif // XMLITEM_H diff --git a/XmlTree/xmlmodel.cpp b/XmlTree/xmlmodel.cpp new file mode 100644 index 0000000..58ee88d --- /dev/null +++ b/XmlTree/xmlmodel.cpp @@ -0,0 +1,104 @@ +#include "xmlmodel.h" + +XmlModel::XmlModel(XmlItem *rootItem, QObject *parent) : + QAbstractItemModel(parent) +{ + this->rootItem = rootItem; +} + +XmlModel::XmlModel(XmlItem *rootItem, QAbstractItemModelPrivate &dd, QObject *parent) : + QAbstractItemModel(dd, parent) +{ + this->rootItem = rootItem; +} + +XmlModel::~XmlModel() +{ + delete rootItem; +} + +XmlItem *XmlModel::xmlItem(const QModelIndex &parent) const +{ + // Check if we are in the root item. + if(!parent.isValid()) + return rootItem; + else + // Get xml item from the model index. + return static_cast<XmlItem *>(parent.internalPointer()); +} + +QVariant XmlModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section) + { + case 0: + return tr("Tree"); + case 1: + return tr("Name"); + case 2: + return tr("Value"); + default: + return QVariant(); + } + } + + return QVariant(); +} + +QVariant XmlModel::data(const QModelIndex& index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + if(role == Qt::UserRole) + return static_cast<XmlItem *>(index.internalPointer())->text(); + + /*if(role == Qt::UserRole) + static_cast<XmlItem *>(index.internalPointer())->text(); + + if(role == Qt::UserRole+1) + static_cast<XmlItem *>(index.internalPointer())->attributes(); + + if(role == Qt::UserRole+2) + VariantPointer::toQVariant(static_cast<XmlItem *>(index.internalPointer())->graphicalItem());*/ + + return QVariant(); +} + +QModelIndex XmlModel::index(int row, int column, const QModelIndex& parent) const +{ + if(!hasIndex(row, column, parent)) + return QModelIndex(); + + XmlItem *parentItem, *childItem; + + // Check if we are in the root item. + if(!parent.isValid()) + parentItem = rootItem; + else + // Get xml item from the model index. + parentItem = static_cast<XmlItem *>(parent.internalPointer()); + + childItem = parentItem->child(row); + + // Create the model index from the child item. + if(childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex XmlModel::parent(const QModelIndex& child) const +{ + if(!child.isValid()) + return QModelIndex(); + + XmlItem *parentItem = static_cast<XmlItem *>(child.internalPointer())->parent(); + + if(!parentItem || parentItem == rootItem) + return QModelIndex(); + + return createIndex(parentItem->rowCount(), 0, parentItem); +} diff --git a/XmlTree/xmlmodel.h b/XmlTree/xmlmodel.h new file mode 100644 index 0000000..6247cb1 --- /dev/null +++ b/XmlTree/xmlmodel.h @@ -0,0 +1,38 @@ +#ifndef XMLMODEL_H +#define XMLMODEL_H + +#include <QAbstractItemModel> + +#include "xmlitem.h" + +class XmlModel : + public QAbstractItemModel +{ + public: + explicit XmlModel(XmlItem *rootItem, QObject *parent = 0); + explicit XmlModel(XmlItem *rootItem, QAbstractItemModelPrivate& dd, QObject *parent); + ~XmlModel(); + + inline int rowCount(const QModelIndex& parent) const; + int columnCount(const QModelIndex& parent) const; + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + QVariant data(const QModelIndex& index, int role) const; + + QModelIndex index(int row, int column, const QModelIndex& parent) const; + QModelIndex parent(const QModelIndex& child) const; + + private: + XmlItem *xmlItem(const QModelIndex& parent) const; + + XmlItem *rootItem; +}; + +inline int XmlModel::rowCount(const QModelIndex& parent) const +{ XmlItem *parentItem = xmlItem(parent); return parentItem->childs().count(); } + +inline int XmlModel::columnCount(const QModelIndex&/* parent*/) const +{ return 1; } + +#endif // XMLMODEL_H diff --git a/XmlTree/xmlproxy.cpp b/XmlTree/xmlproxy.cpp new file mode 100644 index 0000000..b861bf6 --- /dev/null +++ b/XmlTree/xmlproxy.cpp @@ -0,0 +1,6 @@ +#include "xmlproxy.h" + +XmlProxy::XmlProxy(QObject *parent) : + QSortFilterProxyModel(parent) +{ +} diff --git a/XmlTree/xmlproxy.h b/XmlTree/xmlproxy.h new file mode 100644 index 0000000..8f1f517 --- /dev/null +++ b/XmlTree/xmlproxy.h @@ -0,0 +1,13 @@ +#ifndef XMLPROXY_H +#define XMLPROXY_H + +#include <QSortFilterProxyModel> + +class XmlProxy : + QSortFilterProxyModel +{ + public: + explicit XmlProxy(QObject *parent = 0); +}; + +#endif // XMLPROXY_H diff --git a/XmlTree/xmlwidget.cpp b/XmlTree/xmlwidget.cpp index d39651c..255642c 100644 --- a/XmlTree/xmlwidget.cpp +++ b/XmlTree/xmlwidget.cpp @@ -1,7 +1,15 @@ #include "xmlwidget.h" -XmlWidget::XmlWidget(QTreeWidgetItem *item) +XmlWidget::XmlWidget(XmlItem *item) { + XmlModel *model = new XmlModel(item); + XmlDelegate *delegate = new XmlDelegate(); + + proxy.setFilterRegExp(QRegExp(".Region|Line|Metadata|Page|Creator|Created|LastChange|Comments", Qt::CaseInsensitive)); + proxy.setFilterRole(Qt::UserRole); + proxy.setSourceModel(model); + tree.setParent(this); - load(item); + tree.setItemDelegate(delegate); + tree.setModel(&proxy); } diff --git a/XmlTree/xmlwidget.h b/XmlTree/xmlwidget.h index 301ee1d..8ee8699 100644 --- a/XmlTree/xmlwidget.h +++ b/XmlTree/xmlwidget.h @@ -1,25 +1,25 @@ #ifndef XMLWIDGET_H #define XMLWIDGET_H +#include <QSortFilterProxyModel> #include <QTreeWidgetItem> #include <QDomElement> #include <QWidget> +#include "xmldelegate.h" +#include "xmlmodel.h" +#include "xmlitem.h" + class XmlWidget : public QWidget { - friend class QTreeWidget; - public: - explicit XmlWidget(QTreeWidgetItem *item = 0); + explicit XmlWidget(XmlItem *item = 0); - inline void load(QTreeWidgetItem *item); + QTreeView tree; private: - QTreeWidget tree; + QSortFilterProxyModel proxy; }; -inline void XmlWidget::load(QTreeWidgetItem *item) -{ tree.addTopLevelItem(item); } - #endif // XMLWIDGET_H -- 1.7.2.5