OSDN Git Service

[denncoCreator] Implementing save functionality. The work is still in progress.
authortkawata <tkawata@users.sourceforge.jp>
Tue, 2 Oct 2012 15:33:24 +0000 (00:33 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Tue, 2 Oct 2012 15:33:24 +0000 (00:33 +0900)
21 files changed:
Source/dccontainersaver.cpp [new file with mode: 0644]
Source/dccontainersaver.h [new file with mode: 0644]
Source/dccontent.cpp
Source/dccontent.h
Source/dccreator.cpp
Source/denncoCreator.pro
Source/dialog/dcaddcellcodeclassdialog.cpp
Source/dialog/dcaddcelldialog.cpp
Source/treeview/dctreeviewwidget.cpp
Source/visualizer/component/dcvccell.cpp
Source/visualizer/component/dcvccell.h
Source/visualizer/component/dcvccellcode.cpp
Source/visualizer/component/dcvccellcode.h
Source/visualizer/component/dcvceditmodecursor.cpp
Source/visualizer/component/dcvceditmodecursor.h
Source/visualizer/component/dcvcpage.cpp
Source/visualizer/component/dcvcpage.h
Source/visualizer/component/dcvpagecomponent.h
Source/visualizer/dcscene.h
Source/visualizer/eventhandler/dcvterminalfromaxonmodehandler.cpp
Source/visualizer/eventhandler/dcvterminalfromreceptormodehandler.cpp

diff --git a/Source/dccontainersaver.cpp b/Source/dccontainersaver.cpp
new file mode 100644 (file)
index 0000000..9c726c7
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+//
+//  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 <QDomDocument>
+#include <QMap>
+
+DCContainerSaver::DCContainerSaver(DCContainer *container) : d_container(container)
+{
+
+}
+
+DCContainerSaver::~DCContainerSaver()
+{
+
+}
+
+bool DCContainerSaver::saveAll(const QString& containerRootPath)
+{
+    const QMap<QString,DCVCPage*> *pages = d_container->getScene()->getPages();
+    QMapIterator<QString, DCVCPage*> 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<DCVPageComponent*>* 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<DCReceptor*>(terminal->getTarget());
+            if (receptor)
+            {
+                DCCell *targetCell = dynamic_cast<DCCell*>(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 (file)
index 0000000..3f9f5d0
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on Oct-2, 2012.
+//
+#ifndef DCCONTAINERSAVER_H
+#define DCCONTAINERSAVER_H
+
+#include <QString>
+
+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
index 73e09ea..b5624d2 100644 (file)
 #include "DNXML.h"
 #include "DNXMLElement.h"
 #include "DNUtils.h"
+#include "dccontainersaver.h"
 
 #include <stdlib.h>
 #include <sstream>
 #include <iostream>
 
 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);
+}
index 8ad922c..46a0a5b 100644 (file)
 class DCContainer;
 class DCCreator;
 
-#include <string>
+#include <QString>
 
 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);
 
 };
 
index d6fa11c..07b8218 100644 (file)
@@ -132,6 +132,7 @@ bool DCCreator::saveAll()
 {
     if (d_scene)
     {
+        d_vcontent->saveAll(QString::fromStdString(getCurrentContainer()->getContainerRootPath()));
         return d_scene->saveSceneAll();
     }
     return false;
index 2ba3559..1979e5f 100644 (file)
@@ -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
 
index dce0c0c..30d9cee 100644 (file)
@@ -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<QString,DCVCPage*> pages = scene->getPages();
-    QMapIterator<QString, DCVCPage*> i(pages);
+    const QMap<QString,DCVCPage*> *pages = scene->getPages();
+    QMapIterator<QString, DCVCPage*> i(*pages);
     int row = 0;
     int selection = -1;
     while (i.hasNext())
index ecf53c7..e6b5f36 100644 (file)
@@ -50,8 +50,8 @@
     d_comboBox->addItem(QString::fromStdString(TKContainer::CELLTYPE_OUT), QString::fromStdString(TKContainer::CELLTYPE_OUT));
 
     DCScene *scene = container->getScene();
-    const QMap<QString,DCVCPage*> pages = scene->getPages();
-    QMapIterator<QString, DCVCPage*> i(pages);
+    const QMap<QString,DCVCPage*> *pages = scene->getPages();
+    QMapIterator<QString, DCVCPage*> i(*pages);
     int row = 0;
     int selection = -1;
     while (i.hasNext())
index 587496e..ce96f63 100644 (file)
@@ -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));
         }
 
index abfef02..342f188 100644 (file)
@@ -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<DCContainer*> (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)
index 8c1d1bb..4acfc1e 100644 (file)
@@ -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<DCVComponent*> *itemList);
index 38bc192..fe08b87 100644 (file)
@@ -23,3 +23,8 @@
 DCVCCellCode::DCVCCellCode(DCCellCode *owner)
 {
 }
+
+void DCVCCellCode::changePageBelonging(DCVCPage *page)
+{
+    //TODO
+}
index 9bc341f..8fe37c4 100644 (file)
 #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<DCVComponent*> *itemList) {}
index c08090b..65d9a38 100644 (file)
@@ -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];
index e885ef7..ddf6074 100644 (file)
@@ -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<DCVComponent*> *itemList);
index c79c5cb..168767a 100644 (file)
@@ -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;
index 0f2ac98..b6c0efc 100644 (file)
@@ -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<DCVPageComponent*> d_cells;
+    QList<DCVPageComponent*> 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<DCVPageComponent*>* getCells() const { return &d_cells; }
+    const QList<DCVPageComponent*>* 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();
 
index 3be831f..48818f0 100644 (file)
 
 #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; }
index 6625268..97304d5 100644 (file)
@@ -133,7 +133,7 @@ public:
 
     DCCell*                 getEditCellCodeCell() const { return d_editCellCodeCell; }
 
-    const QMap<QString,DCVCPage*> getPages() const { return d_pages; }
+    const QMap<QString,DCVCPage*>* getPages() const { return &d_pages; }
     bool                    getIsPageExist(const std::string& location) const;
 
     //
index 0736688..f084e56 100644 (file)
@@ -294,7 +294,7 @@ void DCVTerminalFromAxonModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent
             if (page)
             {
                 getController()->selectPage(this, page, shift);
-                d_cursor->setPageBelonging(page);
+                d_cursor->changePageBelonging(page);
             }
             else
             {
index c334fa7..1269b96 100644 (file)
@@ -277,7 +277,7 @@ void DCVTerminalFromReceptorModeHandler::mouseReleaseEvent(QGraphicsSceneMouseEv
             if (page)
             {
                 getController()->selectPage(this, page, shift);
-                d_cursor->setPageBelonging(page);
+                d_cursor->changePageBelonging(page);
             }
             else
             {