From e446a8e5c84071e1ca155e6ddd7bf02762909b87 Mon Sep 17 00:00:00 2001 From: tkawata Date: Wed, 3 Oct 2012 00:33:24 +0900 Subject: [PATCH] [denncoCreator] Implementing save functionality. The work is still in progress. --- Source/dccontainersaver.cpp | 128 +++++++++++++++++++++ Source/dccontainersaver.h | 38 ++++++ Source/dccontent.cpp | 31 +++-- Source/dccontent.h | 16 +-- Source/dccreator.cpp | 1 + Source/denncoCreator.pro | 6 +- Source/dialog/dcaddcellcodeclassdialog.cpp | 4 +- Source/dialog/dcaddcelldialog.cpp | 4 +- Source/treeview/dctreeviewwidget.cpp | 6 +- Source/visualizer/component/dcvccell.cpp | 6 +- Source/visualizer/component/dcvccell.h | 4 +- Source/visualizer/component/dcvccellcode.cpp | 5 + Source/visualizer/component/dcvccellcode.h | 5 +- Source/visualizer/component/dcvceditmodecursor.cpp | 38 +++--- Source/visualizer/component/dcvceditmodecursor.h | 5 +- Source/visualizer/component/dcvcpage.cpp | 49 +++++++- Source/visualizer/component/dcvcpage.h | 25 +++- Source/visualizer/component/dcvpagecomponent.h | 19 ++- Source/visualizer/dcscene.h | 2 +- .../dcvterminalfromaxonmodehandler.cpp | 2 +- .../dcvterminalfromreceptormodehandler.cpp | 2 +- 21 files changed, 321 insertions(+), 75 deletions(-) create mode 100644 Source/dccontainersaver.cpp create mode 100644 Source/dccontainersaver.h diff --git a/Source/dccontainersaver.cpp b/Source/dccontainersaver.cpp new file mode 100644 index 0000000..9c726c7 --- /dev/null +++ b/Source/dccontainersaver.cpp @@ -0,0 +1,128 @@ +// Copyright (c) 2012 Dennco Project +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +// Created by tkawata on Oct-2, 2012. +// +#include "dccontainersaver.h" + +#include "dccontainer.h" +#include "dcscene.h" +#include "dcvcpage.h" +#include "dccell.h" +#include "dccellcode.h" +#include "dcreceptor.h" +#include "dcaxon.h" +#include "dcaxonterminal.h" +#include "dcvpagecomponent.h" + +#include +#include + +DCContainerSaver::DCContainerSaver(DCContainer *container) : d_container(container) +{ + +} + +DCContainerSaver::~DCContainerSaver() +{ + +} + +bool DCContainerSaver::saveAll(const QString& containerRootPath) +{ + const QMap *pages = d_container->getScene()->getPages(); + QMapIterator i(*pages); + while (i.hasNext()) + { + i.next(); + DCVCPage *page = i.value(); + saveForPage(containerRootPath, page); + } + return true; +} + +bool DCContainerSaver::saveForPage(const QString& containerRootPath, DCVCPage *page) +{ + QString pageFilePath = containerRootPath; + pageFilePath.append(page->getLocationPath()); + + QDomDocument doc("html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); + doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\""); + + QDomElement root = doc.createElementNS("http://www.w3.org/1999/xhtml","html"); + root.setAttribute("lang", "en"); + QDomElement body = doc.createElement("body"); + root.appendChild(body); + + const QList* vcells = page->getCells(); + for (int j = 0; j < vcells->length(); j++) + { + DCCell *cell = vcells->at(j)->getOwnerCell(); + QString cellName = QString::fromStdString(cell->getName()); + + QDomElement aCellTag = doc.createElement("a"); + aCellTag.setAttribute("define", "cell"); + aCellTag.setAttribute("name", cellName); + + QDomElement aCellCodeTag = doc.createElement("a"); + aCellCodeTag.setAttribute("parameter", "cellcode"); + if (cell->getCellCode() && cell->getCellCode() != d_container->getEmptyCellCodeClass()) + { + aCellCodeTag.setAttribute("href", QString::fromStdString(cell->getCellCode()->getName())); + } + else + { + aCellCodeTag.setAttribute("type", cell->getType()); + } + aCellTag.appendChild(aCellCodeTag); + DCAxon *axon = cell->getAxon(); + for (int k = 0; k < axon->getNumberOfTerminals(); k++) + { + DCAxonTerminal *terminal = axon->getTerminalAt(k); + DCReceptor *receptor = dynamic_cast(terminal->getTarget()); + if (receptor) + { + DCCell *targetCell = dynamic_cast(receptor->getOwnerCell()); + if (targetCell) + { + QString connectionPath = QString::fromStdString(targetCell->getLocation()); + connectionPath.append("#"); + connectionPath.append(QString::fromStdString(targetCell->getName())); + QString receptorName = QString::fromStdString(targetCell->getReceptorName(receptor)); + + QDomElement aConnectionTag = doc.createElement("a"); + aConnectionTag.setAttribute("parameter", "connection"); + aConnectionTag.setAttribute("href", connectionPath); + aConnectionTag.setAttribute("receptor", receptorName); + aCellTag.appendChild(aConnectionTag); + } + } + } + body.appendChild(aCellTag); + } + + doc.appendChild(root); + + QFile file(pageFilePath); + bool r = false; + if (file.open(QFile::WriteOnly | QFile::Truncate)) + { + QTextStream out(&file); + doc.save(out, 4); + r = true; + } + return r; +} diff --git a/Source/dccontainersaver.h b/Source/dccontainersaver.h new file mode 100644 index 0000000..3f9f5d0 --- /dev/null +++ b/Source/dccontainersaver.h @@ -0,0 +1,38 @@ +// Copyright (c) 2012 Dennco Project +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// +// Created by tkawata on Oct-2, 2012. +// +#ifndef DCCONTAINERSAVER_H +#define DCCONTAINERSAVER_H + +#include + +class DCContainer; +class DCVCPage; + +class DCContainerSaver +{ + DCContainer *d_container; +public: + DCContainerSaver(DCContainer *container); + virtual ~DCContainerSaver(); + + bool saveAll(const QString& containerRootPath); + bool saveForPage(const QString& containerRootPath, DCVCPage *page); +}; + +#endif // DCCONTAINERSAVER_H diff --git a/Source/dccontent.cpp b/Source/dccontent.cpp index 73e09ea..b5624d2 100644 --- a/Source/dccontent.cpp +++ b/Source/dccontent.cpp @@ -24,16 +24,17 @@ #include "DNXML.h" #include "DNXMLElement.h" #include "DNUtils.h" +#include "dccontainersaver.h" #include #include #include DCContent::DCContent(DCCreator *creator, std::string contentPath) : - mCreator(creator), mValid(false), mContainer(0) + d_creator(creator), d_valid(false), d_container(0) { - mContainer = (DCContainer*) TKContainer::createContainer(); - mContainer->setContent(this); + d_container = (DCContainer*) TKContainer::createContainer(); + d_container->setContent(this); dnGlobal()->updateRunningStatus(DNGlobal::STOPPED); dnGlobal()->resetErrorStatus(); @@ -52,7 +53,7 @@ DCContent::DCContent(DCCreator *creator, std::string contentPath) : std::string dataStorePath = containerRoot; dataStorePath.append("/data.db"); - succeeded = mContainer->setDataStore(dataStorePath.c_str()); + succeeded = d_container->setDataStore(dataStorePath.c_str()); if (!succeeded) { dnNotifyError("Initialization failed","Failed to the setup data store"); @@ -66,16 +67,16 @@ DCContent::DCContent(DCCreator *creator, std::string contentPath) : return; } - mValid = true; + d_valid = true; } DCContent::~DCContent() { - mValid = false; - if (mContainer) + d_valid = false; + if (d_container) { - delete mContainer; - mContainer = 0; + delete d_container; + d_container = 0; } } @@ -159,10 +160,16 @@ bool DCContent::parseSettingFile(const char *contentRoot) bool DCContent::parseContainerFile(const char *containerRoot) { - DNContainerBuilder builder(mContainer); - mContainer->beganBuildContainer(); + DNContainerBuilder builder(d_container); + d_container->beganBuildContainer(); bool r = builder.buildContainerFromXHTML(containerRoot); - mContainer->endedBuildContainer(); + d_container->endedBuildContainer(); return r; } + +bool DCContent::saveAll(const QString& containerRoot) +{ + DCContainerSaver saver(d_container); + return saver.saveAll(containerRoot); +} diff --git a/Source/dccontent.h b/Source/dccontent.h index 8ad922c..46a0a5b 100644 --- a/Source/dccontent.h +++ b/Source/dccontent.h @@ -22,25 +22,27 @@ class DCContainer; class DCCreator; -#include +#include class DCContent { bool parseSettingFile(const char *contentRoot); bool parseContainerFile(const char *containerRoot); - DCCreator *mCreator; - bool mValid; - DCContainer *mContainer; + DCCreator *d_creator; + bool d_valid; + DCContainer *d_container; public: DCContent(DCCreator *creator, std::string contentPath); virtual ~DCContent(); - bool isValid() { return mValid; } + bool isValid() const { return d_valid; } - DCContainer* getContainer() const { return mContainer; } - DCCreator* getCreator() const { return mCreator; } + DCContainer* getContainer() const { return d_container; } + DCCreator* getCreator() const { return d_creator; } + + bool saveAll(const QString& containerRoot); }; diff --git a/Source/dccreator.cpp b/Source/dccreator.cpp index d6fa11c..07b8218 100644 --- a/Source/dccreator.cpp +++ b/Source/dccreator.cpp @@ -132,6 +132,7 @@ bool DCCreator::saveAll() { if (d_scene) { + d_vcontent->saveAll(QString::fromStdString(getCurrentContainer()->getContainerRootPath())); return d_scene->saveSceneAll(); } return false; diff --git a/Source/denncoCreator.pro b/Source/denncoCreator.pro index 2ba3559..1979e5f 100644 --- a/Source/denncoCreator.pro +++ b/Source/denncoCreator.pro @@ -87,7 +87,8 @@ HEADERS = mainwindow.h \ dialog/dcinputnewpagenamedialog.h \ dialog/dcaddcelldialog.h \ utils/dcskeltoncreatorutil.h \ - utils/dcutil.h + utils/dcutil.h \ + dccontainersaver.h SOURCES = main.cpp \ mainwindow.cpp \ @@ -169,7 +170,8 @@ SOURCES = main.cpp \ dialog/dcinputnewpagenamedialog.cpp \ dialog/dcaddcelldialog.cpp \ utils/dcskeltoncreatorutil.cpp \ - utils/dcutil.cpp + utils/dcutil.cpp \ + dccontainersaver.cpp RESOURCES = denncoCreator.qrc diff --git a/Source/dialog/dcaddcellcodeclassdialog.cpp b/Source/dialog/dcaddcellcodeclassdialog.cpp index dce0c0c..30d9cee 100644 --- a/Source/dialog/dcaddcellcodeclassdialog.cpp +++ b/Source/dialog/dcaddcellcodeclassdialog.cpp @@ -50,8 +50,8 @@ DCAddCellCodeClassDialog::DCAddCellCodeClassDialog(DCContainer *container, DCCre d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_OUT), QString::fromStdString(TKContainer::CELLTYPE_OUT)); DCScene *scene = container->getScene(); - const QMap pages = scene->getPages(); - QMapIterator i(pages); + const QMap *pages = scene->getPages(); + QMapIterator i(*pages); int row = 0; int selection = -1; while (i.hasNext()) diff --git a/Source/dialog/dcaddcelldialog.cpp b/Source/dialog/dcaddcelldialog.cpp index ecf53c7..e6b5f36 100644 --- a/Source/dialog/dcaddcelldialog.cpp +++ b/Source/dialog/dcaddcelldialog.cpp @@ -50,8 +50,8 @@ d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_OUT), QString::fromStdString(TKContainer::CELLTYPE_OUT)); DCScene *scene = container->getScene(); - const QMap pages = scene->getPages(); - QMapIterator i(pages); + const QMap *pages = scene->getPages(); + QMapIterator i(*pages); int row = 0; int selection = -1; while (i.hasNext()) diff --git a/Source/treeview/dctreeviewwidget.cpp b/Source/treeview/dctreeviewwidget.cpp index 587496e..ce96f63 100644 --- a/Source/treeview/dctreeviewwidget.cpp +++ b/Source/treeview/dctreeviewwidget.cpp @@ -73,7 +73,7 @@ bool DCTreeViewModel::setData(const QModelIndex &index, const QVariant &value, i if (QFileInfo(oldFilePath).isDir() && IsIndexUnderContainer(this, index)) { - QString containerPath = QString::fromStdString(d_creator->getCurrentContainer()getContainerRootPathth()); + QString containerPath = QString::fromStdString(d_creator->getCurrentContainer()->getContainerRootPath()); QString containerBasedPath = "/" + QDir(containerPath).relativeFilePath(baseDirPath); if (d_creator->doCommandRenameDirectoryImmidiate(this, containerBasedPath, oldFileName, value.toString())) { @@ -238,12 +238,12 @@ void DCTreeViewWidget::doContextMenu(const QPoint &pos) if (showMenu) { - QString contentPath; + QString containerPath; QString containerBasedPath; if (index.isValid()) { - containerPath = QString::fromStdString(d_creator->getCurrentContainer()getContainerRootPathth()); + containerPath = QString::fromStdString(d_creator->getCurrentContainer()->getContainerRootPath()); containerBasedPath = "/" + QDir(containerPath).relativeFilePath(fileModel->filePath(index)); } diff --git a/Source/visualizer/component/dcvccell.cpp b/Source/visualizer/component/dcvccell.cpp index abfef02..342f188 100644 --- a/Source/visualizer/component/dcvccell.cpp +++ b/Source/visualizer/component/dcvccell.cpp @@ -35,7 +35,7 @@ static const double CUBE_ROUNDRADIUS = 0.05; static const double PI = 3.14159265358979323846264338327950288419717; DCVCCell::DCVCCell(DCCell *owner, DCVCPage *page, float size, float height) - : d_owner(owner), d_page(page), d_shouldUpdateShape(true), + : DCVPageComponent(page), d_owner(owner), d_shouldUpdateShape(true), d_dragOffsetX(0), d_dragOffsetY(0), d_dragOffsetZ(0), d_draggingOriginalSize(0), d_isDragging(false), d_isResizingDrag(false), d_draggingOriginalAxonLength(0) { DCContainer *container = dynamic_cast (d_owner->getContainer()); @@ -59,9 +59,9 @@ DCVCCell::~DCVCCell() } -void DCVCCell::unregisterFromPage() +void DCVCCell::changePageBelonging(DCVCPage *page) { - d_page = NULL; + //TODO } void DCVCCell::prepareChildrenForDraw(bool isAnimationInterval) diff --git a/Source/visualizer/component/dcvccell.h b/Source/visualizer/component/dcvccell.h index 8c1d1bb..4acfc1e 100644 --- a/Source/visualizer/component/dcvccell.h +++ b/Source/visualizer/component/dcvccell.h @@ -29,7 +29,6 @@ class DCVCPage; class DCVCCell : public DCVPageComponent { DCCell *d_owner; - DCVCPage *d_page; DCCubeRenderer *d_shape; bool d_shouldUpdateShape; DCSelectionRenderer *d_selectionRectRenderer; @@ -47,10 +46,9 @@ public: virtual DCCell* getOwnerCell() const { return d_owner; } - virtual DCVCPage * getPageBelonging() const{ return d_page; } virtual bool isResizingArea(float x, float y, float z) const; - virtual void unregisterFromPage(); + virtual void changePageBelonging(DCVCPage *page); virtual void prepareChildrenForDraw(bool isAnimationInterval); virtual void drawChildren(bool isAnimationInterval); virtual void drawChildrenForSelection(QList *itemList); diff --git a/Source/visualizer/component/dcvccellcode.cpp b/Source/visualizer/component/dcvccellcode.cpp index 38bc192..fe08b87 100644 --- a/Source/visualizer/component/dcvccellcode.cpp +++ b/Source/visualizer/component/dcvccellcode.cpp @@ -23,3 +23,8 @@ DCVCCellCode::DCVCCellCode(DCCellCode *owner) { } + +void DCVCCellCode::changePageBelonging(DCVCPage *page) +{ + //TODO +} diff --git a/Source/visualizer/component/dcvccellcode.h b/Source/visualizer/component/dcvccellcode.h index 9bc341f..8fe37c4 100644 --- a/Source/visualizer/component/dcvccellcode.h +++ b/Source/visualizer/component/dcvccellcode.h @@ -19,11 +19,11 @@ #ifndef DCVCCELLCODE_H #define DCVCCELLCODE_H -#include "dcvcomponent.h" +#include "dcvpagecomponent.h" class DCCellCode; -class DCVCCellCode : public DCVComponent +class DCVCCellCode : public DCVPageComponent { public: DCVCCellCode(DCCellCode *owner); @@ -32,6 +32,7 @@ public: virtual DCCell * getOwnerCell() const { return NULL; } virtual bool isResizingArea(float x, float y, float z) const { return false; } + virtual void changePageBelonging(DCVCPage *page); virtual void prepareChildrenForDraw(bool isAnimationInterval) {} virtual void drawChildren(bool isAnimationInterval) {} virtual void drawChildrenForSelection(QList *itemList) {} diff --git a/Source/visualizer/component/dcvceditmodecursor.cpp b/Source/visualizer/component/dcvceditmodecursor.cpp index c08090b..65d9a38 100644 --- a/Source/visualizer/component/dcvceditmodecursor.cpp +++ b/Source/visualizer/component/dcvceditmodecursor.cpp @@ -32,7 +32,7 @@ static DCCubeRenderer *s_cursorShape = NULL; DCVCEditModeCursor::DCVCEditModeCursor() - : d_ownerCell(NULL), d_ownerAxon(NULL), d_ownerReceptor(NULL), d_page(NULL), + : d_ownerCell(NULL), d_ownerAxon(NULL), d_ownerReceptor(NULL), d_cursorType(DCV_CURSOR_NONE), d_dropTarget(NULL), d_dragOffsetX(0), d_dragOffsetY(0), d_isDragging(false) { d_terminal = new DCVCEditModeTerminal; @@ -60,13 +60,13 @@ void DCVCEditModeCursor::setOwnerFromAxon(DCAxon *owner) d_cursorType = DCV_CURSOR_FROM_AXON; if (d_ownerCell) { - setPageBelonging(d_ownerCell->getPageBelonging()); + changePageBelonging(d_ownerCell->getPageBelonging()); setVisible(DCVComponent::DCV_VISIBLE_FULL, DCVComponent::DCV_VISIBLE_FULL); owner->registerEditCursor(this); } else { - setPageBelonging(NULL); + changePageBelonging(NULL); setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE); } } @@ -83,13 +83,13 @@ void DCVCEditModeCursor::setOwnerFromReceptor(DCReceptor *owner) if (d_ownerReceptor && d_ownerCell) { d_cursorType = DCV_CURSOR_FROM_RECEPTAOR; - setPageBelonging(d_ownerCell->getPageBelonging()); + changePageBelonging(d_ownerCell->getPageBelonging()); setVisible(DCVComponent::DCV_VISIBLE_FULL, DCVComponent::DCV_VISIBLE_FULL); owner->registerEditCursor(this); } else { - setPageBelonging(NULL); + changePageBelonging(NULL); setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE); } } @@ -107,27 +107,24 @@ void DCVCEditModeCursor::unsetCursor() d_ownerReceptor = NULL; } d_ownerCell = NULL; - setPageBelonging(NULL); + changePageBelonging(NULL); setVisible(DCVComponent::DCV_VISIBLE_NONE, DCVComponent::DCV_VISIBLE_NONE); } -void DCVCEditModeCursor::setPageBelonging(DCVCPage *page) +void DCVCEditModeCursor::changePageBelonging(DCVCPage *page) { - bool changed = false; - if (d_page != page) + if (getPageBelonging() != page) { - if (d_page) + if (page) { - d_page->unregisterEditCursor(); + page->registerEditCursor(this); + } + else + { + getPageBelonging()->unregisterEditCursor(); } - changed = true; - } - d_page = page; - if (d_page) - d_page->registerEditCursor(this); - - if (changed) emit pageBelongingChanged(page); + } } void DCVCEditModeCursor::setDropTarget(DCVComponent *dropTarget) @@ -148,11 +145,6 @@ bool DCVCEditModeCursor::isResizingArea(float x, float y, float z) const return false; } -void DCVCEditModeCursor::unregisterFromPage() -{ - d_page = NULL; -} - void DCVCEditModeCursor::prepareChildrenForDraw(bool isAnimationInterval) { float matrix[16]; diff --git a/Source/visualizer/component/dcvceditmodecursor.h b/Source/visualizer/component/dcvceditmodecursor.h index e885ef7..ddf6074 100644 --- a/Source/visualizer/component/dcvceditmodecursor.h +++ b/Source/visualizer/component/dcvceditmodecursor.h @@ -40,7 +40,6 @@ private: DCCell *d_ownerCell; DCAxon *d_ownerAxon; DCReceptor *d_ownerReceptor; - DCVCPage *d_page; DCVEditCursorType d_cursorType; DCVCEditModeTerminal *d_terminal; DCVComponent *d_dropTarget; @@ -52,7 +51,6 @@ public: DCVCEditModeCursor(); virtual ~DCVCEditModeCursor(); - virtual DCVCPage* getPageBelonging() const { return d_page; } virtual DCCell* getOwnerCell() const { return d_ownerCell; } virtual bool isResizingArea(float x, float y, float z) const; DCVCEditModeTerminal* getTerminal() const { return d_terminal; } @@ -61,11 +59,10 @@ public: void setOwnerFromAxon(DCAxon *owner); void setOwnerFromReceptor(DCReceptor *owner); - void setPageBelonging(DCVCPage *page); void setDropTarget(DCVComponent *dropTarget); void unsetCursor(); - virtual void unregisterFromPage(); + virtual void changePageBelonging(DCVCPage *page); virtual void prepareChildrenForDraw(bool isAnimationInterval); virtual void drawChildren(bool isAnimationInterval); virtual void drawChildrenForSelection(QList *itemList); diff --git a/Source/visualizer/component/dcvcpage.cpp b/Source/visualizer/component/dcvcpage.cpp index c79c5cb..168767a 100644 --- a/Source/visualizer/component/dcvcpage.cpp +++ b/Source/visualizer/component/dcvcpage.cpp @@ -40,7 +40,15 @@ DCVCPage::~DCVCPage() DCVPageComponent *cell = d_cells.takeFirst(); if (cell) { - cell->unregisterFromPage(); + cell->unregisteredFromPage(); + } + } + while (!d_cellCodeClasses.isEmpty()) + { + DCVPageComponent *cellCodeClass = d_cellCodeClasses.takeFirst(); + if (cellCodeClass) + { + cellCodeClass->unregisteredFromPage(); } } } @@ -49,7 +57,12 @@ void DCVCPage::registerCell(DCVPageComponent *cell) { if (cell) { + if (cell->getPageBelonging()) + { + cell->getPageBelonging()->unregisterCell(cell); + } d_cells.append(cell); + cell->regiesteredToPage(this); } } @@ -58,16 +71,48 @@ void DCVCPage::unregisterCell(DCVPageComponent *cell) if (cell) { d_cells.removeOne(cell); + cell->unregisteredFromPage(); + } +} + +void DCVCPage::registerCellCodeClass(DCVPageComponent *cellCodeClass) +{ + if (cellCodeClass) + { + if (cellCodeClass->getPageBelonging()) + { + cellCodeClass->getPageBelonging()->unregisterCellCodeClass(cellCodeClass); + } + d_cellCodeClasses.append(cellCodeClass); + cellCodeClass->regiesteredToPage(this); + } +} + +void DCVCPage::unregisterCellCodeClass(DCVPageComponent *cellCodeClass) +{ + if (cellCodeClass) + { + d_cellCodeClasses.removeOne(cellCodeClass); + cellCodeClass->unregisteredFromPage(); } } void DCVCPage::registerEditCursor(DCVPageComponent *ecursor) { + if (ecursor) + { + if (ecursor->getPageBelonging()) + { + ecursor->getPageBelonging()->unregisterEditCursor(); + } + } d_editCursor = ecursor; + d_editCursor->regiesteredToPage(this); } void DCVCPage::unregisterEditCursor() { + d_editCursor->unregisteredFromPage(); d_editCursor = NULL; } @@ -270,7 +315,7 @@ void DCVCPage::loadAttributesFromXML(QDomElement element) if (path == d_locationPath) { QDomNodeList cellNodes = e.childNodes(); - for (int j = 0; j < cellNodes.length(); j++) + for (unsigned int j = 0; j < cellNodes.length(); j++) { if (!cellNodes.at(j).isElement()) continue; diff --git a/Source/visualizer/component/dcvcpage.h b/Source/visualizer/component/dcvcpage.h index 0f2ac98..b6c0efc 100644 --- a/Source/visualizer/component/dcvcpage.h +++ b/Source/visualizer/component/dcvcpage.h @@ -21,8 +21,6 @@ #include "dcvcomponent.h" -class DCVCCell; -class DCVCCellCode; class DCVPageComponent; class DCVCPage : public DCVComponent @@ -38,6 +36,8 @@ class DCVCPage : public DCVComponent float d_colorA; QList d_cells; + QList d_cellCodeClasses; + DCVPageComponent *d_editCursor; public: @@ -50,9 +50,30 @@ public: virtual bool isResizingArea(float x, float y, float z) const { return false; } QString getLocationPath() const { return d_locationPath; } + const QList* getCells() const { return &d_cells; } + const QList* getCellCodeClasses() const { return &d_cellCodeClasses; } + + // register / unregister cell to this page. + // They are called from DCVCCell. + // Other classes shouldn't call this directly. + // To change the page a cell belonging, + // DCVCCell::changePageBelonging() should be called instead. void registerCell(DCVPageComponent *cell); void unregisterCell(DCVPageComponent *cell); + // register / unregister cellcode to this page. + // They are called from DCVCCellCode. + // Other classes shouldn't call this directly. + // To change the page a cell code class belonging, + // DCVCCellCode::changePageBelonging() should be called instead. + void registerCellCodeClass(DCVPageComponent *cellCodeClass); + void unregisterCellCodeClass(DCVPageComponent *cellCodeClass); + + // register / unregister cellcode to this page. + // They are called from DCVCEditModeCursor. + // Other classes shouldn't call this directly. + // To change the page a cell code class belonging, + // DCVCEditModeCursor::changePageBelonging() should be called instead. void registerEditCursor(DCVPageComponent *ecursor); void unregisterEditCursor(); diff --git a/Source/visualizer/component/dcvpagecomponent.h b/Source/visualizer/component/dcvpagecomponent.h index 3be831f..48818f0 100644 --- a/Source/visualizer/component/dcvpagecomponent.h +++ b/Source/visualizer/component/dcvpagecomponent.h @@ -21,18 +21,27 @@ #include "dcvcomponent.h" -class DCVCPage; +#include "dcvcpage.h" class DCVPageComponent : public DCVComponent { - float d_pageX; - float d_pageY; + friend class DCVCPage; + + DCVCPage *d_page; + float d_pageX; + float d_pageY; + + void regiesteredToPage(DCVCPage *page) { d_page = page; } + void unregisteredFromPage() { d_page = NULL; } public: - DCVPageComponent() : d_pageX(0), d_pageY(0) {} + DCVPageComponent() : d_page(NULL), d_pageX(0), d_pageY(0) {} + explicit DCVPageComponent(DCVCPage *page) : d_page(page), d_pageX(0), d_pageY(0) {} virtual ~DCVPageComponent() {} - virtual void unregisterFromPage() = 0; + inline DCVCPage* getPageBelonging() const{ return d_page; } + + virtual void changePageBelonging(DCVCPage *page) = 0; virtual float getPageX() const { return d_pageX; } virtual float getPageY() const { return d_pageY; } diff --git a/Source/visualizer/dcscene.h b/Source/visualizer/dcscene.h index 6625268..97304d5 100644 --- a/Source/visualizer/dcscene.h +++ b/Source/visualizer/dcscene.h @@ -133,7 +133,7 @@ public: DCCell* getEditCellCodeCell() const { return d_editCellCodeCell; } - const QMap getPages() const { return d_pages; } + const QMap* getPages() const { return &d_pages; } bool getIsPageExist(const std::string& location) const; // diff --git a/Source/visualizer/eventhandler/dcvterminalfromaxonmodehandler.cpp b/Source/visualizer/eventhandler/dcvterminalfromaxonmodehandler.cpp index 0736688..f084e56 100644 --- a/Source/visualizer/eventhandler/dcvterminalfromaxonmodehandler.cpp +++ b/Source/visualizer/eventhandler/dcvterminalfromaxonmodehandler.cpp @@ -294,7 +294,7 @@ void DCVTerminalFromAxonModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent if (page) { getController()->selectPage(this, page, shift); - d_cursor->setPageBelonging(page); + d_cursor->changePageBelonging(page); } else { diff --git a/Source/visualizer/eventhandler/dcvterminalfromreceptormodehandler.cpp b/Source/visualizer/eventhandler/dcvterminalfromreceptormodehandler.cpp index c334fa7..1269b96 100644 --- a/Source/visualizer/eventhandler/dcvterminalfromreceptormodehandler.cpp +++ b/Source/visualizer/eventhandler/dcvterminalfromreceptormodehandler.cpp @@ -277,7 +277,7 @@ void DCVTerminalFromReceptorModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEv if (page) { getController()->selectPage(this, page, shift); - d_cursor->setPageBelonging(page); + d_cursor->changePageBelonging(page); } else { -- 2.11.0