---
GScribo/GScribo.pro.user | 19 ++--
GScribo/Rendering/polygonitem.cpp | 2 -
GScribo/Rendering/polygonitem.h | 15 +++
GScribo/Rendering/scene.cpp | 42 +++++++-
GScribo/Rendering/scene.h | 7 +-
GScribo/mainwindow.cpp | 214 +++++++++++++++++++++++++++++++++++++
GScribo/mainwindow.h | 70 ++++++++++++
GScribo/xml.cpp | 58 ++++-------
GScribo/xml.h | 5 +-
GScribo/xmlwidget.cpp | 60 +++++++++--
GScribo/xmlwidget.h | 18 ++--
11 files changed, 435 insertions(+), 75 deletions(-)
create mode 100644 GScribo/mainwindow.cpp
create mode 100644 GScribo/mainwindow.h
diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user
index 5c5dcd4..b6ad263 100644
--- a/GScribo/GScribo.pro.user
+++ b/GScribo/GScribo.pro.user
@@ -168,36 +168,35 @@
<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-OdVBhpC8Q3,guid=12f5a3829adfbb5c05f6273d007125c0</value>
+ <value
type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-VUZT78qyIG,guid=a51566d968c6324fbe10159500728107</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-epygWB</value>
- <value type="QString">GNOME_KEYRING_PID=7156</value>
+ <value
type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-E8RI9F</value>
+ <value type="QString">GNOME_KEYRING_PID=8443</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</value>
+ <value
type="QString">OLDPWD=/lrde/home/stage/froger_a/qt</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=7231</value>
- <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-poGlEz7165/agent.7165</value>
+ <value type="QString">SSH_AGENT_PID=8518</value>
+ <value
type="QString">SSH_AUTH_SOCK=/tmp/ssh-FvhujW8452/agent.8452</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</value>
- <value type="QString">XAUTHORITY=/tmp/.gdmH3DGRW</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</value>
+ <value type="QString">XAUTHORITY=/tmp/.gdmOKGZRW</value>
<value
type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value>
- <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359463044.389005-635867443</value>
+ <value
type="QString">XDG_SESSION_COOKIE=b24883b9b4dbfb80ea83575b00000a11-1359551947.439559-1116819102</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/Rendering/polygonitem.cpp b/GScribo/Rendering/polygonitem.cpp
index d11d482..48dbad0 100644
--- a/GScribo/Rendering/polygonitem.cpp
+++ b/GScribo/Rendering/polygonitem.cpp
@@ -55,7 +55,6 @@ bool PolygonItem::repaint(const QRectF& rect, bool clic)
{
setPen(selectedPen);
setBrush(selectedBrush);
- update(rect);
}
}
@@ -65,7 +64,6 @@ bool PolygonItem::repaint(const QRectF& rect, bool clic)
{
setPen(unselectedPen);
setBrush(unselectedBrush);
- update(rect);
}
}
diff --git a/GScribo/Rendering/polygonitem.h b/GScribo/Rendering/polygonitem.h
index 9715872..112da15 100644
--- a/GScribo/Rendering/polygonitem.h
+++ b/GScribo/Rendering/polygonitem.h
@@ -22,6 +22,9 @@ class PolygonItem :
bool repaint(const QRectF &rect, bool clic);
inline void loadData(const GraphicRegion::Data& data);
+ inline void unselect();
+ inline void select();
+
private:
void init();
@@ -46,4 +49,16 @@ inline bool PolygonItem::isSelected(const QRectF &rect, bool clic)
return (boundingRect().width() == 0 || boundingRect().height() == 0 ||
boundingRect().intersects(rect)) && shape().intersects(rect);
}
+inline void PolygonItem::select()
+{
+ setPen(selectedPen);
+ setBrush(selectedBrush);
+}
+
+inline void PolygonItem::unselect()
+{
+ setPen(unselectedPen);
+ setBrush(unselectedBrush);
+}
+
#endif // POLYGONITEM_H
diff --git a/GScribo/Rendering/scene.cpp b/GScribo/Rendering/scene.cpp
index f58227f..eb86c6c 100644
--- a/GScribo/Rendering/scene.cpp
+++ b/GScribo/Rendering/scene.cpp
@@ -1,5 +1,7 @@
#include "scene.h"
+/******************************************* Run through item childs run through LINES
! TODO ****************************************/
+/******************************************* Center */
Scene::Scene(QObject *parent):
QGraphicsScene(parent)
{
@@ -92,13 +94,39 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
}
}
+void Scene::selectItem(PolygonItem *graphicalItem)
+{
+ if(graphicalItem)
+ {
+ QGraphicsItem *child;
+ PolygonItem *polygonItem;
+
+ foreach(child, item->childItems())
+ {
+ polygonItem = static_cast<PolygonItem *>(child);
+ polygonItem->unselect();
+
+ if(polygonItem->data(0).toInt() == GraphicRegion::Text)
+ {
+ foreach(child, polygonItem->childItems())
+ {
+ polygonItem = static_cast<PolygonItem *>(child);
+ polygonItem->unselect();
+ }
+ }
+ }
+
+ graphicalItem->select();
+ }
+}
+
void Scene::repaintSelection(const QRectF &rect, bool clic)
{
QGraphicsItem *child;
PolygonItem *polygonItem;
bool isSel;
- emit clearTreeItemSelection();
+ emit clearTreeSelection();
// Redraw all items in the scene except selection.
foreach(child, item->childItems())
@@ -106,14 +134,22 @@ void Scene::repaintSelection(const QRectF &rect, bool clic)
polygonItem = static_cast<PolygonItem *>(child);
isSel = polygonItem->repaint(rect, clic);
+ // If item selectionned, select it on the xml tree.
if(isSel)
emit
selectTreeItem(VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1)));
- // If the item is a text region, run through childs line items.
+ // If the item is a text region.
if(polygonItem->data(0).toInt() == GraphicRegion::Text)
{
+ // Run through each child lines items.
foreach(child, polygonItem->childItems())
- static_cast<PolygonItem *>(child)->repaint(rect, clic);
+ {
+ polygonItem = static_cast<PolygonItem *>(child);
+ isSel = polygonItem->repaint(rect, clic);
+
+ if(isSel)
+ emit
selectTreeItem(VariantPointer<QTreeWidgetItem>::fromQVariant(polygonItem->data(1)));
+ }
}
}
}
diff --git a/GScribo/Rendering/scene.h b/GScribo/Rendering/scene.h
index 2ea559f..0bd5d56 100644
--- a/GScribo/Rendering/scene.h
+++ b/GScribo/Rendering/scene.h
@@ -39,9 +39,12 @@ class Scene :
QString path;
bool clic;
+ public slots:
+ void selectItem(PolygonItem *graphicalItem);
+
signals:
- void selectTreeItem(QTreeWidgetItem *item);
- void clearTreeItemSelection();
+ void selectTreeItem(QTreeWidgetItem *treeItem);
+ void clearTreeSelection();
};
#endif // SCENE_H
diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp
new file mode 100644
index 0000000..6b098fc
--- /dev/null
+++ b/GScribo/mainwindow.cpp
@@ -0,0 +1,214 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+
+ setWindowTitle(tr("GScribo"));
+
+ initGraphicsRegion();
+ initTextRegion();
+ initXmlWidget();
+ initPageWidget();
+ initToolBar();
+ initMenuBar();
+
+ connectWidgets();
+ connectShortcuts();
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::initGraphicsRegion()
+{
+ // Cache backgroud to speed up its repaint.
+ graphicsView.setCacheMode(QGraphicsView::CacheBackground);
+ graphicsView.setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ graphicsView.setScene(&scene);
+
+ setCentralWidget(&graphicsView);
+}
+
+void MainWindow::initPageWidget()
+{
+ dockPages.setWindowTitle(tr("Pages"));
+ dockPages.setFeatures(QDockWidget::DockWidgetClosable);
+ dockPages.setMaximumWidth(190);
+ dockPages.setMinimumWidth(190);
+ dockPages.setWidget(&pagesWidget);
+
+ addDockWidget(Qt::LeftDockWidgetArea, &dockPages);
+}
+
+void MainWindow::initXmlWidget()
+{
+ dockXml.setWindowTitle(tr("Xml"));
+ dockXml.setFeatures(QDockWidget::DockWidgetClosable);
+ dockXml.setWidget(&xmlWidget);
+
+ addDockWidget(Qt::BottomDockWidgetArea, &dockXml);
+}
+
+void MainWindow::initTextRegion()
+{
+ dockText.setWindowTitle(tr("Text"));
+ dockText.setAllowedAreas(Qt::AllDockWidgetAreas);
+ dockText.setFeatures(QDockWidget::DockWidgetFloatable |
QDockWidget::DockWidgetMovable);
+ dockText.setWidget(&textEdit);
+
+ addDockWidget(Qt::RightDockWidgetArea, &dockText);
+ dockText.hide();
+}
+
+void MainWindow::initToolBar()
+{
+ QAction *open = ui->mainToolBar->addAction(tr("Open"));
+ connect(open, SIGNAL(triggered()), this, SLOT(onOpen()));
+
+ QAction *segment = ui->mainToolBar->addAction(tr("Segment"));
+ connect(segment, SIGNAL(triggered()), this, SLOT(onSegment()));
+
+ QAction *del = ui->mainToolBar->addAction(tr("Delete"));
+ connect(del, SIGNAL(triggered()), &pagesWidget, SLOT(removeSelection()));
+}
+
+void MainWindow::initMenuBar()
+{
+ QAction *preferences = ui->menuBar->addAction(tr("Preferences"));
+ connect(preferences, SIGNAL(triggered()), SLOT(onPreferences()));
+}
+
+void MainWindow::onPagesSelection(const QString &filename, const QPixmap
&pixmap)
+{
+ xml = processTmpXml(filename);
+ scene.changeScene(filename, pixmap, xml.graphicItem());
+ xmlWidget.changeView(xml.treeItem());
+}
+
+void MainWindow::onOpen()
+{
+ QStringList paths = QFileDialog::getOpenFileNames(this, "Open Image(s)",
QDir::homePath(), "Images (*.png *.jpg *.ppm *.bmp)");
+
+ if(paths.count() > 0)
+ {
+ QString path = paths[0];
+ QPixmap pixmap(path);
+
+ pagesWidget.addPixmap(path, pixmap);
+
+ // If more than one file, we store it in the page widget.
+ for(int i = 1; i < paths.count(); i++)
+ {
+ path = paths[i];
+ pixmap.load(path);
+ pagesWidget.addPixmap(path, pixmap);
+ }
+
+ // Seek if xml file already exists and in that case, add it to the scene.
+ xml = processTmpXml(path);
+ scene.changeScene(path, pixmap, xml.graphicItem());
+ xmlWidget.changeView(xml.treeItem());
+ }
+}
+
+Xml MainWindow::processTmpXml(const QString &filename) const
+{
+ QString path = filename;
+
+ // Get instance of the configuration settings.
+ Configs * const conf = Configs::getInstance();
+
+ // Get xml filename from image path.
+ path.remove(0, path.lastIndexOf('/')+1);
+ int pos = path.lastIndexOf('.');
+ path.remove(pos, path.length()-pos);
+ path += "_gui.xml";
+
+ // Get full path of xml file.
+ if(QDir::temp().exists(path))
+ path = QDir::tempPath() + "/" + path;
+ else if(QDir(conf->generalSaveXmlCustomDirPath()).exists(path))
+ path = conf->generalSaveXmlCustomDirPath() + "/" + path;
+ else
+ path = QString();
+
+ // Get xml file informations if it exists.
+ if(path.isNull())
+ return Xml();
+ else
+
+ return Xml(path);
+}
+
+
+void MainWindow::onSegment()
+{
+ if(scene.backgroundPath() != "")
+ {
+ QStringList filenames;
+
+ if(!pagesWidget.isVisible())
+ filenames << scene.backgroundPath();
+ else
+ filenames = pagesWidget.filenames();
+
+ // Run segmentation of page(s).
+ progressDialog.reset();
+ runner.start_demat(filenames);
+ }
+}
+
+void MainWindow::onXmlSaved(const QString& filename)
+{
+ xml.load(filename);
+ xmlWidget.changeView(xml.treeItem());
+ scene.addPolygonItem(xml.graphicItem());
+}
+
+void MainWindow::onPreferences()
+{
+ PreferencesDialog *preferenceDialog = new PreferencesDialog(this);
+ preferenceDialog->show();
+}
+
+void MainWindow::connectWidgets()
+{
+ // If double click on a picture of the page widget -> draw it on background
scene.
+ connect(&pagesWidget, SIGNAL(selectionClicked(QString,QPixmap)), this,
SLOT(onPagesSelection(QString,QPixmap)));
+
+ // Connect scene selection with xml tree and vice versa.
+ connect(&scene, SIGNAL(selectTreeItem(QTreeWidgetItem*)), &xmlWidget,
SLOT(selectItem(QTreeWidgetItem*)));
+ connect(&scene, SIGNAL(clearTreeSelection()), &xmlWidget,
SLOT(clearSelection()));
+ connect(&xmlWidget, SIGNAL(selectGraphicalItem(PolygonItem*)), &scene,
SLOT(selectItem(PolygonItem*)));
+
+ connect(&runner, SIGNAL(progress()), &progressDialog, SLOT(run()));
+ connect(&runner, SIGNAL(new_progress_max_value(int)), &progressDialog,
SLOT(setMaximum(int)));
+ connect(&runner, SIGNAL(new_progress_label(QString)), &progressDialog,
SLOT(setLabelText(QString)));
+ connect(&runner, SIGNAL(finished()), &progressDialog, SLOT(close()));
+ connect(&runner, SIGNAL(xml_saved(QString)), this, SLOT(onXmlSaved(QString)));
+}
+
+void MainWindow::connectShortcuts()
+{
+ QShortcut *del = new QShortcut(Qt::Key_Delete, &pagesWidget);
+ connect(del, SIGNAL(activated()), &pagesWidget, SLOT(removeSelection()));
+}
+
+void MainWindow::changeEvent(QEvent *e)
+{
+ QMainWindow::changeEvent(e);
+ switch (e->type())
+ {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h
new file mode 100644
index 0000000..9baab40
--- /dev/null
+++ b/GScribo/mainwindow.h
@@ -0,0 +1,70 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QGraphicsView>
+#include <QPlainTextEdit>
+#include <QMainWindow>
+#include <QHBoxLayout>
+#include <QDockWidget>
+#include <QFileDialog>
+#include <QGroupBox>
+
+#include "Preferences/preferencesdialog.h"
+#include "Processing/progressdialog.h"
+#include "PagesViewer/pageswidget.h"
+#include "Processing/runner.h"
+#include "Rendering/scene.h"
+#include "xmlwidget.h"
+#include "xml.h"
+
+namespace Ui
+{
+ class MainWindow;
+}
+
+class MainWindow:
+ public QMainWindow
+{
+ Q_OBJECT
+
+ public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+ protected:
+ void changeEvent(QEvent *e);
+
+ private:
+ void initGraphicsRegion();
+ void initTextRegion();
+ void initToolBar();
+ void initPageWidget();
+ void initXmlWidget();
+ void initMenuBar();
+ void connectWidgets();
+ void connectShortcuts();
+
+ Xml processTmpXml(const QString& filename) const;
+
+ Ui::MainWindow *ui;
+ QDockWidget dockText;
+ QDockWidget dockPages;
+ QDockWidget dockXml;
+ QGraphicsView graphicsView;
+ Scene scene;
+ QPlainTextEdit textEdit;
+ PagesWidget pagesWidget;
+ Runner runner;
+ ProgressDialog progressDialog;
+ Xml xml;
+ XmlWidget xmlWidget;
+
+ private slots:
+ void onOpen();
+ void onSegment();
+ void onXmlSaved(const QString& filename);
+ void onPreferences();
+ void onPagesSelection(const QString& filename, const QPixmap& pixmap);
+};
+
+#endif // MAINWINDOW_H
diff --git a/GScribo/xml.cpp b/GScribo/xml.cpp
index 143e4a7..59a3963 100644
--- a/GScribo/xml.cpp
+++ b/GScribo/xml.cpp
@@ -18,6 +18,9 @@ static const GraphicRegion::Data itemsData[] =
Xml::Xml(const QString &filename)
{
+ gItem = 0;
+ tItem = 0;
+
load(filename);
}
@@ -32,6 +35,7 @@ void Xml::load(const QString &filename)
QFile xmlFile(filename);
xmlFile.open(QIODevice::ReadOnly);
+ // Fill new xml tree.
xml.clear();
xml.setContent(&xmlFile);
@@ -93,40 +97,30 @@ void Xml::processNode(const QDomElement& root, const
GraphicRegion::Data& data,
{
if(!root.isNull())
{
- QDomElement node = root;
-
// Create corresponding tree item.
- QTreeWidgetItem *parentTreeItem = fillWidgetItem(root.tagName(), rootTreeItem);
- parentTreeItem->parent()->setData(0, Qt::UserRole,
VariantPointer<QDomNamedNodeMap>::toQVariant(new
QDomNamedNodeMap(root.attributes())));
- QTreeWidgetItem *treeItem;
+ QTreeWidgetItem *parentTreeItem = new QTreeWidgetItem(rootTreeItem,
QStringList(root.tagName()));
+ parentTreeItem->setData(0, Qt::UserRole,
VariantPointer<QDomNamedNodeMap>::toQVariant(new
QDomNamedNodeMap(root.attributes())));
QPolygon polygon;
- QString sx, sy;
// Run through all points data.
- node = node.firstChild().firstChild().toElement();
+ 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);
- // Store the xml node in the item.
- treeItem->setData(0, Qt::UserRole,
VariantPointer<QDomNamedNodeMap>::toQVariant(new
QDomNamedNodeMap(node.attributes())));
-
- polygon << QPoint(sx.toInt(), sy.toInt());
+ polygon << QPoint(node.attribute("x",
"null").toInt(), node.attribute("y", "null").toInt());
node = node.nextSibling().toElement();
}
// Create the graphical item from data structure.
PolygonItem *polygonItem = new PolygonItem(polygon, gItem);
polygonItem->loadData(data);
- // Store tree object in the graphical object.
- polygonItem->setData(0,
VariantPointer<QTreeWidgetItem>::toQVariant(parentTreeItem));
+
+ // Store tree object in the graphical object an vice versa.
+ polygonItem->setData(1,
VariantPointer<QTreeWidgetItem>::toQVariant(parentTreeItem));
+ parentTreeItem->setData(0, Qt::UserRole+1,
VariantPointer<PolygonItem>::toQVariant(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);
@@ -137,34 +131,22 @@ void Xml::processLineNode(const QDomElement& root, PolygonItem
*parentPolygonIte
{
if(!root.isNull())
{
- QDomElement node = root;
-
// Create corresponding tree item.
- QTreeWidgetItem *parentTreeItem = fillWidgetItem(root.tagName(), rootTreeItem);
- parentTreeItem->parent()->setData(0, Qt::UserRole,
VariantPointer<QDomNamedNodeMap>::toQVariant(new
QDomNamedNodeMap(node.attributes())));
- QTreeWidgetItem *treeItem;
+ QTreeWidgetItem *parentTreeItem = new QTreeWidgetItem(rootTreeItem,
QStringList(root.tagName()));
+ parentTreeItem->setData(0, Qt::UserRole,
VariantPointer<QDomNamedNodeMap>::toQVariant(new
QDomNamedNodeMap(root.attributes())));
QPolygon polygon;
- QString sx, sy;
int x, y;
int xMin = INT_MAX;
int xMax = INT_MIN;
// Run through all points data.
- node = node.firstChild().firstChild().toElement();
+ 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);
- // Store xml node attributes in the item.
- treeItem->setData(0, Qt::UserRole,
VariantPointer<QDomNamedNodeMap>::toQVariant(new
QDomNamedNodeMap(node.attributes())));
-
- x = sx.toInt();
- y = sy.toInt();
+ x = node.attribute("x", "null").toInt();
+ y = node.attribute("y", "null").toInt();
// Get beginning and end of line.
if(xMin > x)
@@ -179,8 +161,10 @@ void Xml::processLineNode(const QDomElement& root, PolygonItem
*parentPolygonIte
// Create the graphical item from data structure.
PolygonItem *polygonItem = new PolygonItem(polygon, parentPolygonItem);
polygonItem->loadData(itemsData[0]);
- // Store tree object in the graphical object.
+
+ // Store tree object in the graphical object and vice versa.
polygonItem->setData(1,
VariantPointer<QTreeWidgetItem>::toQVariant(parentTreeItem));
+ parentTreeItem->setData(0, Qt::UserRole+1,
VariantPointer<PolygonItem>::toQVariant(polygonItem));
// Get meanline and baseline.
processTypoNode(root, QPoint(xMin, xMax), polygonItem);
diff --git a/GScribo/xml.h b/GScribo/xml.h
index 3141eb3..81b7583 100644
--- a/GScribo/xml.h
+++ b/GScribo/xml.h
@@ -12,11 +12,8 @@
#include "variantpointer.h"
#include "region.h"
-class Xml :
- QObject
+class Xml
{
- Q_OBJECT
-
public:
explicit Xml(const QString& filename = QString());
diff --git a/GScribo/xmlwidget.cpp b/GScribo/xmlwidget.cpp
index 9c4c867..34ec266 100644
--- a/GScribo/xmlwidget.cpp
+++ b/GScribo/xmlwidget.cpp
@@ -17,7 +17,19 @@ XmlWidget::XmlWidget(QWidget *parent) :
setLayout(hLayout);
- connect(&viewer, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this,
SLOT(fillProperty(QTreeWidgetItem*)));
+ connect(&viewer, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this,
SLOT(setSelectItem(QTreeWidgetItem*)));
+}
+
+void XmlWidget::setSelectItem(QTreeWidgetItem *treeItem)
+{
+ viewer.setCurrentItem(treeItem, 0);
+ treeItem->setExpanded(true);
+
+ // Fill property tree view.
+ fillProperty(treeItem);
+
+ // Emit signal to select corresponding graphical item on the scene.
+ emit
selectGraphicalItem(VariantPointer<PolygonItem>::fromQVariant(treeItem->data(0,
Qt::UserRole+1)));
}
void XmlWidget::fillProperty(QTreeWidgetItem *treeItem)
@@ -31,18 +43,50 @@ void XmlWidget::fillProperty(QTreeWidgetItem *treeItem)
{
QStringList values;
- //if(node.hasAttributes())
- //{
- QDomNamedNodeMap attributes = *node;/*.attributes();*/
-
- for(int i = 0; i < attributes.count(); i++)
+ // Fill tree widget with all property of a node.
+ for(int i = 0; i < node->count(); i++)
{
- values << attributes.item(i).toAttr().name() <<
attributes.item(i).toAttr().value();
+ values << node->item(i).toAttr().name() <<
node->item(i).toAttr().value();
property.addTopLevelItem(new QTreeWidgetItem(values));
values.clear();
}
- //}
}
property.resizeColumnToContents(0);
}
+
+void XmlWidget::changeView(QTreeWidgetItem *treeItem)
+{
+ if(treeItem != viewer.topLevelItem(0))
+ {
+ // Delete all dom nodes pointers inside items data.
+ QTreeWidgetItem *topLevelItem = viewer.takeTopLevelItem(0);
+ if(topLevelItem)
+ {
+ deleteItemsNode(topLevelItem);
+ delete
VariantPointer<QDomNamedNodeMap>::fromQVariant(topLevelItem->data(0,
Qt::UserRole));
+ delete topLevelItem;
+ }
+
+ // Reset tree widgets.
+ property.clear();
+ viewer.reset();
+
+ if(treeItem != 0)
+ viewer.addTopLevelItem(treeItem);
+ }
+}
+
+void XmlWidget::deleteItemsNode(QTreeWidgetItem *topLevelItem)
+{
+ QTreeWidgetItem *item;
+
+ // Delete recursively all childs of an item and the child of the child item etc ...
+ for(int i = 0; i < topLevelItem->childCount(); i++)
+ {
+ item = topLevelItem->child(i);
+ deleteItemsNode(item);
+ delete VariantPointer<QDomNamedNodeMap>::fromQVariant(item->data(0,
Qt::UserRole));
+ delete item;
+ }
+}
diff --git a/GScribo/xmlwidget.h b/GScribo/xmlwidget.h
index 3f42db2..d6d8fe3 100644
--- a/GScribo/xmlwidget.h
+++ b/GScribo/xmlwidget.h
@@ -7,6 +7,7 @@
#include <QWidget>
#include <QLabel>
+#include "Rendering/polygonitem.h"
#include "variantpointer.h"
class XmlWidget :
@@ -17,23 +18,22 @@ class XmlWidget :
public:
explicit XmlWidget(QWidget *parent = 0);
- inline void changeView(QTreeWidgetItem *treeItem);
+ void changeView(QTreeWidgetItem *treeItem);
private:
+ void fillProperty(QTreeWidgetItem *treeItem);
+ void deleteItemsNode(QTreeWidgetItem *topLevelItem);
+
QTreeWidget viewer;
QTreeWidget property;
public slots:
- void fillProperty(QTreeWidgetItem *treeItem);
- inline void selectItem(QTreeWidgetItem *item);
+ void setSelectItem(QTreeWidgetItem *treeItem);
inline void clearSelection();
-};
-
-inline void XmlWidget::changeView(QTreeWidgetItem *treeItem)
-{ viewer.takeTopLevelItem(0); viewer.reset(); if(treeItem != 0)
viewer.addTopLevelItem(treeItem); }
-inline void XmlWidget::selectItem(QTreeWidgetItem *item)
-{ viewer.setCurrentItem(item, 0); item->setExpanded(true); }
+ signals:
+ void selectGraphicalItem(PolygonItem *polygonItem);
+};
inline void XmlWidget::clearSelection()
{ viewer.reset(); property.clear(); }
--
1.7.2.5