0319bef Good page widget advancement : customize model to see in the vieww which picture is selected and optimize memory and speed with new custom model.

--- GScribo/GScribo.pro | 6 ++- GScribo/GScribo.pro.user | 32 ++++++++++---------- GScribo/PagesWidget/listmodel.cpp | 40 ++++++++++++------------ GScribo/PagesWidget/listmodel.h | 27 +++++++++++++---- GScribo/PagesWidget/pagesdelegate.cpp | 20 ++++++++++++ GScribo/PagesWidget/pagesdelegate.h | 18 +++++++++++ GScribo/PagesWidget/pageswidget.cpp | 31 ++++--------------- GScribo/PagesWidget/pageswidget.h | 32 +++++++++++++++++--- GScribo/Rendering/polygonitem.cpp | 1 - GScribo/Rendering/scene.cpp | 44 +++++++++++++++------------ GScribo/Rendering/scene.h | 12 +++++-- GScribo/Rendering/selection.cpp | 2 +- GScribo/XmlWidget/regionwidget.cpp | 5 +++ GScribo/XmlWidget/selectionproxy.h | 5 +-- GScribo/XmlWidget/xmlwidget.cpp | 1 + GScribo/XmlWidget/xmlwidget.h | 2 +- GScribo/mainwindow.cpp | 39 ++++++++++++------------ GScribo/mainwindow.h | 2 +- GScribo/xml.cpp | 53 +++++++++++++++++---------------- 19 files changed, 220 insertions(+), 152 deletions(-) create mode 100644 GScribo/PagesWidget/pagesdelegate.cpp create mode 100644 GScribo/PagesWidget/pagesdelegate.h create mode 100644 GScribo/XmlWidget/regionwidget.cpp diff --git a/GScribo/GScribo.pro b/GScribo/GScribo.pro index c02e8c9..a7f730e 100644 --- a/GScribo/GScribo.pro +++ b/GScribo/GScribo.pro @@ -28,7 +28,8 @@ SOURCES += main.cpp \ XmlWidget/xmlmodel.cpp \ XmlWidget/xmlitem.cpp \ XmlWidget/xmlattributes.cpp \ - XmlWidget/attributemodel.cpp + XmlWidget/attributemodel.cpp \ + PagesWidget/pagesdelegate.cpp HEADERS += mainwindow.h \ variantpointer.h \ configs.h \ @@ -52,7 +53,8 @@ HEADERS += mainwindow.h \ XmlWidget/xmlattributes.h \ XmlWidget/selectionproxy.h \ XmlWidget/xmldelegate.h \ - XmlWidget/attributemodel.h + XmlWidget/attributemodel.h \ + PagesWidget/pagesdelegate.h FORMS += mainwindow.ui \ Preferences/preferencesdialog.ui \ Preferences/ocroptions.ui \ diff --git a/GScribo/GScribo.pro.user b/GScribo/GScribo.pro.user index c386cec..77c6b9f 100644 --- a/GScribo/GScribo.pro.user +++ b/GScribo/GScribo.pro.user @@ -76,7 +76,7 @@ <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-e9nHbn7LYK,guid=e39a93d8f03a16fd6bc992a3000b7303</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-8HhQV0Db3w,guid=820a1dac27c5f8287b84357100000031</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> @@ -87,22 +87,22 @@ <value type="QString">LANG=fr_FR.UTF-8</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/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=8057</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-EVOSGL8004/agent.8004</value> + <value type="QString">SSH_AGENT_PID=2149</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vKpzBP2096/agent.2096</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</value> - <value type="QString">XAUTHORITY=/tmp/.gdmD7T7RW</value> + <value type="QString">WINDOWID=16777252</value> + <value type="QString">WINDOWPATH=7</value> + <value type="QString">XAUTHORITY=/tmp/.gdmYQPASW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360136006.519710-1569843383</value> + <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360245257.460868-2058632410</value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> <value type="QString">XTERM_VERSION=XTerm(261)</value> @@ -125,7 +125,7 @@ <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-e9nHbn7LYK,guid=e39a93d8f03a16fd6bc992a3000b7303</value> + <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-8HhQV0Db3w,guid=820a1dac27c5f8287b84357100000031</value> <value type="QString">DESKTOP_SESSION=fluxbox</value> <value type="QString">DISPLAY=:0.0</value> <value type="QString">GDMSESSION=fluxbox</value> @@ -136,22 +136,22 @@ <value type="QString">LANG=fr_FR.UTF-8</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/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=8057</value> - <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-EVOSGL8004/agent.8004</value> + <value type="QString">SSH_AGENT_PID=2149</value> + <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vKpzBP2096/agent.2096</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</value> - <value type="QString">XAUTHORITY=/tmp/.gdmD7T7RW</value> + <value type="QString">WINDOWID=16777252</value> + <value type="QString">WINDOWPATH=7</value> + <value type="QString">XAUTHORITY=/tmp/.gdmYQPASW</value> <value type="QString">XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/usr/share/gdm/</value> - <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360136006.519710-1569843383</value> + <value type="QString">XDG_SESSION_COOKIE=9a5c41ad78622411b8e25b00459a554f-1360245257.460868-2058632410</value> <value type="QString">XTERM_LOCALE=fr_FR.UTF-8</value> <value type="QString">XTERM_SHELL=/bin/bash</value> <value type="QString">XTERM_VERSION=XTerm(261)</value> diff --git a/GScribo/PagesWidget/listmodel.cpp b/GScribo/PagesWidget/listmodel.cpp index 0a57f97..35a86e4 100644 --- a/GScribo/PagesWidget/listmodel.cpp +++ b/GScribo/PagesWidget/listmodel.cpp @@ -3,16 +3,7 @@ ListModel::ListModel(QObject *parent): QAbstractListModel(parent) { -} - -QStringList ListModel::filenames() const -{ - return paths; -} - -int ListModel::rowCount(const QModelIndex&) const -{ - return pixmaps.count(); + currentRow_ = -1; } QVariant ListModel::data(const QModelIndex& index, int role) const @@ -21,27 +12,25 @@ QVariant ListModel::data(const QModelIndex& index, int role) const return QVariant(); if(role == Qt::DecorationRole) - return QIcon(pixmaps.value(index.row()).scaled(QSize(200, 200), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + return pixmaps_[index.row()]; - // Store the original pixmap in a custom place. if(role == Qt::UserRole) - return pixmaps[index.row()]; + return filenames_[index.row()]; - // Store the path of the pixmap in an other custom place. if(role == Qt::UserRole+1) - return paths[index.row()]; + return currentRow_; return QVariant(); } -void ListModel::addPixmap(const QString& filename, const QPixmap& pixmap) +void ListModel::addPicture(const QString& filename, const QPixmap& pixmap) { int row = rowCount(); beginInsertRows(QModelIndex(), row, row); - pixmaps.insert(row, pixmap); - paths.insert(row, filename); + pixmaps_.insert(row, pixmap.scaled(QSize(200, 200), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + filenames_.insert(row, filename); endInsertRows(); } @@ -52,8 +41,19 @@ void ListModel::removePixmap(const QModelIndex &parent) beginRemoveRows(parent, row, row); - pixmaps.removeAt(row); - paths.removeAt(row); + pixmaps_.removeAt(row); + filenames_.removeAt(row); endRemoveRows(); } + +void ListModel::setCurrentRow(int currentRow) +{ + int precRow = currentRow_; + currentRow_ = currentRow; + + QModelIndex i = index(precRow, 0, QModelIndex()); + emit dataChanged(i, i); + i = index(currentRow_, 0, QModelIndex()); + emit dataChanged(i, i); +} diff --git a/GScribo/PagesWidget/listmodel.h b/GScribo/PagesWidget/listmodel.h index dac1a2d..46bc04e 100644 --- a/GScribo/PagesWidget/listmodel.h +++ b/GScribo/PagesWidget/listmodel.h @@ -12,17 +12,32 @@ class ListModel: public: explicit ListModel(QObject *parent = 0); - QStringList filenames() const; - int rowCount(const QModelIndex& parent = QModelIndex()) const; + + inline QStringList filenames() const; + inline int rowCount(const QModelIndex& parent = QModelIndex()) const; + + inline int currentRow() const; + void setCurrentRow(int currentRow); + QVariant data(const QModelIndex& index, int role = Qt::DecorationRole) const; - void addPixmap(const QString& filename, const QPixmap& pixmap); + void addPicture(const QString& filename, const QPixmap& pixmap); private: - QList<QPixmap> pixmaps; - QStringList paths; + QStringList filenames_; + QList<QPixmap> pixmaps_; + int currentRow_; public slots: - void removePixmap(const QModelIndex &parent); + void removePixmap(const QModelIndex& parent); }; +inline QStringList ListModel::filenames() const +{ return filenames_; } + +inline int ListModel::rowCount(const QModelIndex&) const +{ return filenames_.count(); } + +inline int ListModel::currentRow() const +{ return currentRow_; } + #endif // LISTMODEL_H diff --git a/GScribo/PagesWidget/pagesdelegate.cpp b/GScribo/PagesWidget/pagesdelegate.cpp new file mode 100644 index 0000000..19a34c2 --- /dev/null +++ b/GScribo/PagesWidget/pagesdelegate.cpp @@ -0,0 +1,20 @@ +#include "pagesdelegate.h" + +PagesDelegate::PagesDelegate(QObject *parent) : + QStyledItemDelegate(parent) +{ + pen_.setColor(QColor::fromRgb(255, 69, 0, 255)); + pen_.setWidth(2); +} + +void PagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QStyledItemDelegate::paint(painter, option, index); + + if(index.row() == index.data(Qt::UserRole+1).toInt()) + { + painter->setPen(pen_); + painter->drawRect(option.rect); + painter->fillRect(option.rect, QColor::fromRgb(255, 69, 0, 60)); + } +} diff --git a/GScribo/PagesWidget/pagesdelegate.h b/GScribo/PagesWidget/pagesdelegate.h new file mode 100644 index 0000000..ff422ca --- /dev/null +++ b/GScribo/PagesWidget/pagesdelegate.h @@ -0,0 +1,18 @@ +#ifndef PAGESDELEGATE_H +#define PAGESDELEGATE_H + +#include <QStyledItemDelegate> +#include <QPainter> + +class PagesDelegate : + public QStyledItemDelegate +{ + public: + explicit PagesDelegate(QObject *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + + private: + QPen pen_; +}; + +#endif // PAGESDELEGATE_H diff --git a/GScribo/PagesWidget/pageswidget.cpp b/GScribo/PagesWidget/pageswidget.cpp index e05d38a..b7d2ac8 100644 --- a/GScribo/PagesWidget/pageswidget.cpp +++ b/GScribo/PagesWidget/pageswidget.cpp @@ -5,35 +5,16 @@ PagesWidget::PagesWidget(QWidget *parent): { setUniformItemSizes(true); setSelectionMode(QAbstractItemView::ExtendedSelection); - setSelectionRectVisible(false); setViewMode(QListView::IconMode); setIconSize(QSize(200, 200)); - setFlow(QListView::TopToBottom); setMovement(QListView::Static); + setResizeMode(QListView::Adjust); setSpacing(10); - setWrapping(false); - setModel(&model); - connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(getPixmap(QModelIndex))); -} + setModel(&model_); + setItemDelegate(new PagesDelegate()); -QStringList PagesWidget::filenames() const -{ - return model.filenames(); -} - -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>(); - QString filename = index.data(Qt::UserRole+1).toString(); - - emit sceneChanged(filename, pixmap); -} - -void PagesWidget::addPixmap(const QString& filename, const QPixmap& pixmap) -{ - model.addPixmap(filename, pixmap); + connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(getPicture(QModelIndex))); } void PagesWidget::removeSelection() @@ -47,10 +28,10 @@ void PagesWidget::removeSelection() // From the highest row value to the smallest to be sure to remove the good index. for(int i = indexes.count()-1; i > -1; i--) - model.removePixmap(indexes[i]); + model_.removePixmap(indexes[i]); // Draw new pixmap on the scene. - getPixmap(model.index(indexes[0].row())); + getPicture(model_.index(indexes[0].row())); clearSelection(); } } diff --git a/GScribo/PagesWidget/pageswidget.h b/GScribo/PagesWidget/pageswidget.h index 60ea9b6..3e2c443 100644 --- a/GScribo/PagesWidget/pageswidget.h +++ b/GScribo/PagesWidget/pageswidget.h @@ -4,6 +4,7 @@ #include <QListView> #include <QShortcut> +#include "pagesdelegate.h" #include "listmodel.h" class PagesWidget: @@ -13,18 +14,39 @@ class PagesWidget: public: explicit PagesWidget(QWidget *parent = 0); - void addPixmap(const QString& filename, const QPixmap& pixmap); - QStringList filenames() const; + + inline QStringList filenames() const; + inline int currentRow() const; + inline void setCurrentRow(int currentRow); + + inline void addPicture(const QString& filename, const QPixmap& pixmap); private: - ListModel model; + ListModel model_; public slots: - void getPixmap(const QModelIndex &index); void removeSelection(); + private slots: + inline void getPicture(const QModelIndex& index); + signals: - void sceneChanged(const QString& filename, const QPixmap& pixmap); + void imageSelectionned(const QString& filename); }; +inline QStringList PagesWidget::filenames() const +{ return model_.filenames(); } + +inline int PagesWidget::currentRow() const +{ return model_.currentRow(); } + +inline void PagesWidget::setCurrentRow(int currentRow) +{ model_.setCurrentRow(currentRow); } + +void PagesWidget::getPicture(const QModelIndex& index) +{ QString filename = index.data(Qt::UserRole).toString(); emit imageSelectionned(filename); } + +inline void PagesWidget::addPicture(const QString& filename, const QPixmap& pixmap) +{ model_.addPicture(filename, pixmap); } + #endif // PAGESWIDGET_H diff --git a/GScribo/Rendering/polygonitem.cpp b/GScribo/Rendering/polygonitem.cpp index ba35395..7c84d0c 100644 --- a/GScribo/Rendering/polygonitem.cpp +++ b/GScribo/Rendering/polygonitem.cpp @@ -71,7 +71,6 @@ void PolygonItem::setSelected(const QRectF& rect, bool clic) if(region_ == GraphicRegion::Line) static_cast<PolygonItem *>(parentItem())->xmlItem()->select(); } - else { // Unselect graphical and xml item. diff --git a/GScribo/Rendering/scene.cpp b/GScribo/Rendering/scene.cpp index 1572ecb..25a0f15 100644 --- a/GScribo/Rendering/scene.cpp +++ b/GScribo/Rendering/scene.cpp @@ -21,8 +21,8 @@ Scene::Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent): void Scene::init() { isPressing_ = false; - clic_ = false; - item_ = 0; + click_ = false; + rootItem_ = 0; // Disable the scene size adaptation to items rect with a non null rect. setSceneRect(0, 0, 0, 1); @@ -33,10 +33,10 @@ void Scene::init() void Scene::clear() { - if(item_) - delete item_; + if(rootItem_) + delete rootItem_; - item_ = 0; + rootItem_ = 0; } void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -44,7 +44,7 @@ void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event) if(event->button() == Qt::LeftButton && !isPressing_) { isPressing_ = true; - clic_ = true; + click_ = true; pressPos_ = event->scenePos(); selection_.show(); @@ -55,7 +55,7 @@ void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(isPressing_) { - clic_ = false; + click_ = false; // Adapt if the selection rectangle has a negative size. if(pressPos_.x() < event->scenePos().x()) @@ -77,14 +77,14 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) isPressing_ = false; // If no selection, store the click position in the selection rectangle. - if(clic_) + if(click_) selection_.setRect(QRectF(QPointF(0, 0), event->scenePos())); // Redraw all items in selection. - if(item_) + if(rootItem_) { emit beginSelection(); - selectItems(selection_.rect(), clic_); + selectItems(selection_.rect(), click_); emit endSelection(); } @@ -99,7 +99,7 @@ void Scene::selectItem(PolygonItem *graphicalItem) PolygonItem *polygonItem; // Unselect all items. - foreach(child, item_->childItems()) + foreach(child, rootItem_->childItems()) { polygonItem = static_cast<PolygonItem *>(child); polygonItem->unselect(); @@ -120,30 +120,34 @@ void Scene::selectItem(PolygonItem *graphicalItem) void Scene::selectItems(const QRectF& rect, bool clic) { QGraphicsItem *child; - foreach(child, item_->childItems()) + foreach(child, rootItem_->childItems()) static_cast<PolygonItem *>(child)->setSelected(rect, clic); } -void Scene::addPolygonItem(QGraphicsItem *item) +void Scene::setRootItem(QGraphicsItem *rootItem) { - // Delete all items in the scene. + // Delete all items. clear(); - item_ = item; - addItem(item); + rootItem_ = rootItem; + addItem(rootItem); } -void Scene::changeScene(const QString& filename, const QPixmap& pixmap, QGraphicsItem *item) +void Scene::changeScene(const QString& filename, QGraphicsItem *rootItem) { backgroundPath_ = filename; - // Delete all items in the scene. + // Delete all items. clear(); + QPixmap pixmap(filename); setSceneRect(pixmap.rect()); setBackgroundBrush(QBrush(pixmap)); // Add new items. - if(item) - addPolygonItem(item); + if(rootItem) + { + rootItem_ = rootItem; + addItem(rootItem); + } } diff --git a/GScribo/Rendering/scene.h b/GScribo/Rendering/scene.h index 0cf964e..a11ff2c 100644 --- a/GScribo/Rendering/scene.h +++ b/GScribo/Rendering/scene.h @@ -20,10 +20,11 @@ class Scene : explicit Scene(qreal x, qreal y, qreal width, qreal height, QObject *parent = 0); inline QString backgroundPath() const; + void setRootItem(QGraphicsItem *graphicalItem); + inline QGraphicsItem *rootItem() const; void clear(); - void addPolygonItem(QGraphicsItem *item); - void changeScene(const QString& filename, const QPixmap& pixmap, QGraphicsItem *item = 0); + void changeScene(const QString& filename, QGraphicsItem *rootItem = 0); void selectItems(const QRectF& rect, bool clic); protected: @@ -34,11 +35,11 @@ class Scene : private: void init(); - QGraphicsItem *item_; + QGraphicsItem *rootItem_; Selection selection_; QPointF pressPos_; bool isPressing_; - bool clic_; + bool click_; QString backgroundPath_; public slots: @@ -52,4 +53,7 @@ class Scene : inline QString Scene::backgroundPath() const { return backgroundPath_; } +inline QGraphicsItem *Scene::rootItem() const +{ return rootItem_; } + #endif // SCENE_H diff --git a/GScribo/Rendering/selection.cpp b/GScribo/Rendering/selection.cpp index 438e92e..dfe187e 100644 --- a/GScribo/Rendering/selection.cpp +++ b/GScribo/Rendering/selection.cpp @@ -24,7 +24,7 @@ void Selection::init() setZValue(INT_MAX); QPen pen; - pen.setStyle(Qt::DashLine); + pen.setStyle(Qt::SolidLine); pen.setCapStyle(Qt::SquareCap); pen.setCosmetic(true); setPen(pen); diff --git a/GScribo/XmlWidget/regionwidget.cpp b/GScribo/XmlWidget/regionwidget.cpp new file mode 100644 index 0000000..70b021f --- /dev/null +++ b/GScribo/XmlWidget/regionwidget.cpp @@ -0,0 +1,5 @@ +nclude "regionwidget.h" + +RegionWidget::RegionWidget() +{ +} diff --git a/GScribo/XmlWidget/selectionproxy.h b/GScribo/XmlWidget/selectionproxy.h index c169dea..32edae4 100644 --- a/GScribo/XmlWidget/selectionproxy.h +++ b/GScribo/XmlWidget/selectionproxy.h @@ -19,10 +19,7 @@ class SelectionProxy : }; inline bool SelectionProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const -{ - QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - return index.data(filterRole()).toBool(); -} +{ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); return index.data(filterRole()).toBool(); } inline void SelectionProxy::beginResetModel() { QSortFilterProxyModel::beginResetModel(); } diff --git a/GScribo/XmlWidget/xmlwidget.cpp b/GScribo/XmlWidget/xmlwidget.cpp index 05f69e1..3b0e055 100644 --- a/GScribo/XmlWidget/xmlwidget.cpp +++ b/GScribo/XmlWidget/xmlwidget.cpp @@ -36,6 +36,7 @@ XmlWidget::XmlWidget(QWidget *parent) : void XmlWidget::changeView(XmlItem *rootItem) { + attributesModel_.reset(); model_.load(rootItem); } diff --git a/GScribo/XmlWidget/xmlwidget.h b/GScribo/XmlWidget/xmlwidget.h index 70a3ece..a8063f9 100644 --- a/GScribo/XmlWidget/xmlwidget.h +++ b/GScribo/XmlWidget/xmlwidget.h @@ -52,6 +52,6 @@ inline void XmlWidget::onBeginGraphicalSelection() { selectionProxy_.beginResetModel(); } inline void XmlWidget::onEndGraphicalSelection() -{ selectionProxy_.endResetModel(); property_.reset(); selection_.expandAll(); } +{ selectionProxy_.endResetModel(); attributesModel_.reset(); selection_.expandAll(); } #endif // XMLWIDGET_H diff --git a/GScribo/mainwindow.cpp b/GScribo/mainwindow.cpp index 9dcd31b..13902e4 100644 --- a/GScribo/mainwindow.cpp +++ b/GScribo/mainwindow.cpp @@ -39,8 +39,7 @@ void MainWindow::initPageWidget() { dockPages.setWindowTitle(tr("Pages")); dockPages.setFeatures(QDockWidget::DockWidgetClosable); - dockPages.setMaximumWidth(190); - dockPages.setMinimumWidth(190); + //dockPages.setFixedWidth(190); dockPages.setWidget(&pagesWidget); addDockWidget(Qt::LeftDockWidgetArea, &dockPages); @@ -84,21 +83,19 @@ void MainWindow::initMenuBar() connect(preferences, SIGNAL(triggered()), SLOT(onPreferences())); } -void MainWindow::onFileChanged(const QString &filename, const QPixmap &pixmap) +void MainWindow::onFileChanged(const QString& filename) { // If it's not the current scene. if(scene.backgroundPath() != filename) { QString xmlPath = Xml::getPath(filename); - // Check if the xml file exists to draw data in the scene. - if(QFile(xmlPath).exists()) - { - xml.load(xmlPath); - scene.changeScene(filename, pixmap, xml.graphicItem()); - xmlWidget.changeView(xml.treeItem()); - } - else - scene.changeScene(filename, pixmap); + // Check if the xml file already exists. + if(!QFile(xmlPath).exists()) + xmlPath = QString(); + + xml.load(xmlPath); + scene.changeScene(filename, xml.graphicItem()); + xmlWidget.changeView(xml.treeItem()); } } @@ -113,6 +110,7 @@ void MainWindow::onOpen() int counter = 0; bool isContained; + // Check for an image not already added to the page widget. do { path = paths[counter]; @@ -122,22 +120,23 @@ void MainWindow::onOpen() if(!isContained) { - QPixmap pixmap(path); - pagesWidget.addPixmap(path, pixmap); + onFileChanged(path); + pagesWidget.setCurrentRow(filenames.count()+counter-1); + pagesWidget.addPicture(path, QPixmap(path)); // If more than one file, we store it in the page widget. for(int i = counter; i < paths.count(); i++) { + // Check if the page widget contains the image. if(!filenames.contains(paths[i], Qt::CaseSensitive)) { path = paths[i]; - pixmap.load(path); - pagesWidget.addPixmap(path, pixmap); + pagesWidget.addPicture(path, QPixmap(path)); } } - - onFileChanged(path, pixmap); } + else + onFileChanged(path); } } @@ -162,7 +161,7 @@ void MainWindow::onXmlSaved(const QString& filename) { xml.load(filename); xmlWidget.changeView(xml.treeItem()); - scene.addPolygonItem(xml.graphicItem()); + scene.setRootItem(xml.graphicItem()); } void MainWindow::onPreferences() @@ -174,7 +173,7 @@ void MainWindow::onPreferences() void MainWindow::connectWidgets() { // If double click on a picture of the page widget -> draw it on background scene. - connect(&pagesWidget, SIGNAL(sceneChanged(QString,QPixmap)), this, SLOT(onFileChanged(QString,QPixmap))); + connect(&pagesWidget, SIGNAL(imageSelectionned(QString)), this, SLOT(onFileChanged(QString))); // Connect the scene to the xml widget and vice versa. connect(&scene, SIGNAL(beginSelection()), &xmlWidget, SLOT(onBeginGraphicalSelection())); diff --git a/GScribo/mainwindow.h b/GScribo/mainwindow.h index 92642d1..28132ca 100644 --- a/GScribo/mainwindow.h +++ b/GScribo/mainwindow.h @@ -64,7 +64,7 @@ class MainWindow: void onSegment(); void onXmlSaved(const QString& filename); void onPreferences(); - void onFileChanged(const QString& filename, const QPixmap& pixmap); + void onFileChanged(const QString& filename); }; #endif // MAINWINDOW_H diff --git a/GScribo/xml.cpp b/GScribo/xml.cpp index af59c0a..8a273db 100644 --- a/GScribo/xml.cpp +++ b/GScribo/xml.cpp @@ -16,16 +16,13 @@ static const GraphicRegion::Data itemsData[] = { QColor::fromRgb(0, 204, 255, 90), "ChartRegion", (int)GraphicRegion::Chart, 2 } }; -Xml::Xml(const QString &filename) +Xml::Xml(const QString& filename) { - gItem = 0; - tItem = 0; - path = filename; load(filename); } -QString Xml::getPath(const QString &filename) +QString Xml::getPath(const QString& filename) { // Get instance of the configuration settings. Configs *const conf = Configs::getInstance(); @@ -41,35 +38,39 @@ QString Xml::getPath(const QString &filename) return conf->generalSaveXmlCustomDirPath() + "/" + xmlPath; } -void Xml::load(const QString &filename) +void Xml::load(const QString& filename) { - if(!filename.isEmpty()) + if(filename.isEmpty()) { - // Reset graphic and tree items; - tItem = new XmlItem; - gItem = new QGraphicsPolygonItem; + tItem = 0; + gItem = 0; + return; + } - QFile xmlFile(filename); - xmlFile.open(QIODevice::ReadOnly); + // Reset graphic and tree items; + tItem = new XmlItem; + gItem = new QGraphicsPolygonItem; - // Fill new xml tree. - xml.clear(); - xml.setContent(&xmlFile); + QFile xmlFile(filename); + xmlFile.open(QIODevice::ReadOnly); - xmlFile.close(); + // Fill new xml tree. + xml.clear(); + xml.setContent(&xmlFile); - QDomElement root = xml.documentElement(); - tItem->load(root); + xmlFile.close(); - root = root.firstChild().toElement(); - XmlItem *parentTreeItem = init(root, tItem); + QDomElement root = xml.documentElement(); + tItem->load(root); - // Run through the xml file structure by structure. - root = root.nextSibling().firstChild().toElement(); - processNode(root, itemsData[1], parentTreeItem); - for(int i = 2; i < 10; i++) - processNode(root.nextSiblingElement(itemsData[i].name), itemsData[i], parentTreeItem); - } + root = root.firstChild().toElement(); + XmlItem *parentTreeItem = init(root, tItem); + + // Run through the xml file structure by structure. + root = root.nextSibling().firstChild().toElement(); + processNode(root, itemsData[1], parentTreeItem); + for(int i = 2; i < 10; i++) + processNode(root.nextSiblingElement(itemsData[i].name), itemsData[i], parentTreeItem); } XmlItem *Xml::init(const QDomElement& root, XmlItem *rootTreeItem) -- 1.7.2.5
participants (1)
-
Antoine Froger