#include "dccreator.h"
DCCommand::DCCommand(const void *requester, DCCreator *creator)
- : d_requester(requester), d_controller(creator)
+ : d_requester(requester), d_controller(creator), d_commandResult(DCCOMMAND_NOT_EXECUTED)
{
if (creator)
{
class DCCommand : public QUndoCommand
{
- const void *d_requester;
- DCCreator *d_controller;
- DCScene *d_scene;
+public:
+ enum E_DCCOMMAND_RESULT {DCCOMMAND_NOT_EXECUTED, DCCOMMAND_SUCCEEDED, DCCOMMAND_FAILED };
+
+private:
+ const void *d_requester;
+ DCCreator *d_controller;
+ DCScene *d_scene;
+ E_DCCOMMAND_RESULT d_commandResult;
public:
DCCommand(const void *requester, DCCreator *creator);
virtual ~DCCommand() {}
- const void * getRequester() const { return d_requester; }
- DCCreator * getController() const { return d_controller; }
- DCScene * getScene() const { return d_scene; }
+ const void * getRequester() const { return d_requester; }
+ DCCreator * getController() const { return d_controller; }
+ DCScene * getScene() const { return d_scene; }
+ E_DCCOMMAND_RESULT getCommandResult() const { return d_commandResult; }
+
+protected:
+ void setCommandResult(E_DCCOMMAND_RESULT result) { d_commandResult = result; }
};
#endif // DCCOMMAND_H
void DCStartAddAxonTerminalCommandFromAxon::redo()
{
DCAxon *axon = d_ownerCell->getAxon();
- getScene()->startTerminalEditForAxon(getRequester(), axon);
+ bool r = getScene()->startTerminalEditForAxon(getRequester(), axon);
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
+
}
void DCStartAddAxonTerminalCommandFromAxon::undo()
void DCStartAddAxonTerminalCommandFromReceptor::redo()
{
DCReceptor *receptor = d_ownerCell->createReceptor(d_receptorName);
- getScene()->startTerminalEditForReceptor(getRequester(), receptor);
+ bool r = getScene()->startTerminalEditForReceptor(getRequester(), receptor);
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCStartAddAxonTerminalCommandFromReceptor::undo()
void DCCommitAddAxonTerminalCommand::redo()
{
+ bool r = false;
if (!d_receptor)
{
d_isAdded = d_axonCell->connectTo(d_receptorName.toStdString(), d_receptorCell);
- getScene()->finishTerminalEdit(getRequester());
+ r = getScene()->finishTerminalEdit(getRequester());
}
else
{
d_receptor->setTarget(terminal);
d_isAdded = true;
}
- getScene()->finishTerminalEdit(getRequester());
+ r = getScene()->finishTerminalEdit(getRequester());
}
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCCommitAddAxonTerminalCommand::undo()
void DCRemoveAxonTerminalCommand::redo()
{
+ bool r = false;
if (d_axonTerminal)
{
//delete from axon terminal
QString receptorName = QString::fromStdString(targetCell->getReceptorName(receptor));
d_isDeleted = targetCell->removeReceptor(receptorName);
if (d_isDeleted)
- axon->removeAxonTerminal(d_axonTerminal);
+ r = axon->removeAxonTerminal(d_axonTerminal);
}
}
else
DCAxon *axon = dynamic_cast<DCAxon*>(terminal->getOwner());
d_isDeleted = d_cell->removeReceptor(d_receptorName);
if (d_isDeleted)
- axon->removeAxonTerminal(terminal);
+ r = axon->removeAxonTerminal(terminal);
}
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCRemoveAxonTerminalCommand::undo()
void DCStartCellCodeEditCommand::redo()
{
- getScene()->startCellCodeEdit(getRequester(), d_cell);
-
+ bool r =getScene()->startCellCodeEdit(getRequester(), d_cell);
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCStartCellCodeEditCommand::undo()
void DCFinishCellCodeEditCommand::redo()
{
- getScene()->finishCellCodeEdit(getRequester());
-
+ bool r = getScene()->finishCellCodeEdit(getRequester());
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCFinishCellCodeEditCommand::undo()
void DCAssignCellCodeClassToCellCommand::redo()
{
+ bool r = false;
if (d_cell)
{
d_prevClass = d_cell->getCellCode();
- d_cell->setCellCode(d_cellCode, NULL);
+ r = d_cell->setCellCode(d_cellCode, NULL);
}
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCAssignCellCodeClassToCellCommand::undo()
void DCUnassignCellCodeClassFromCellCommand::redo()
{
+ bool r = false;
if (d_cell)
{
d_prevClass = d_cell->getCellCode();
- d_cell->setCellCode(getController()->getCurrentContainer()->getEmptyCellCodeClass(), NULL);
+ r = d_cell->setCellCode(getController()->getCurrentContainer()->getEmptyCellCodeClass(), NULL);
}
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCUnassignCellCodeClassFromCellCommand::undo()
void DCAddCellCodeClassCommand::redo()
{
- d_container->addCellCode(d_name.toStdString(), d_type.toStdString(), "\n");
+ bool r = d_container->addCellCode(d_name.toStdString(), d_type.toStdString(), "\n") != NULL;
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCAddCellCodeClassCommand::undo()
/*--------------------------------*/
+DCMoveCellCodeClassCommand::DCMoveCellCodeClassCommand(const void *requester, DCCreator *creator, const QString &name, const QString &type)
+ : DCCommand(requester, creator), d_name(name), d_type(type)
+{
+}
+
+DCMoveCellCodeClassCommand::~DCMoveCellCodeClassCommand()
+{
+}
+
+void DCMoveCellCodeClassCommand::redo()
+{
+
+}
+
+void DCMoveCellCodeClassCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+
DCRemoveCellCodeClassCommand::DCRemoveCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCellCode *cellCode)
- : DCCommand(requester, creator), d_container(container), d_cellCode(cellCode)
+ : DCCommand(requester, creator), d_container(container)
+{
+ d_cellCodes.append(cellCode);
+}
+
+DCRemoveCellCodeClassCommand::DCRemoveCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCellCode *> &cellcodes)
+ : DCCommand(requester, creator), d_container(container), d_cellCodes(cellcodes)
{
}
void DCRemoveCellCodeClassCommand::redo()
{
- d_container->removeCellCode(d_cellCode);
+ bool r = false;
+
+ for (int i = 0; i < d_cellCodes.length(); i++)
+ {
+ if (!d_container->removeCellCode(d_cellCodes.at(i)))
+ {
+ r = false;
+ }
+ }
+
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCRemoveCellCodeClassCommand::undo()
void DCAddCellCommand::redo()
{
+ bool r = false;
+
DCCell *cell = dynamic_cast<DCCell*>(d_container->addCell(d_path.toStdString(), d_name.toStdString(), d_type.toStdString(), ""));
if (cell)
{
+ r = true;
cell->getVComponent()->setSelected(true,true);
getController()->selectPage(this, cell->getPageBelonging(), false);
if (getController()->getPersMode() != DCCreator::DC_PERSMODE_PAGEEDIT)
getController()->changePersMode(this, DCCreator::DC_PERSMODE_PAGEEDIT);
}
}
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCAddCellCommand::undo()
/*--------------------------------*/
-DCRemoveCellsCommand::DCRemoveCellsCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCell*> &cells)
+DCRenameCellCommand::DCRenameCellCommand(const void *requester, DCCreator *creator, DCCell *cell, const QString &newName)
+ : DCCommand(requester, creator), d_cell(cell), d_name(newName)
+{
+
+}
+
+DCRenameCellCommand::~DCRenameCellCommand()
+{
+
+}
+
+void DCRenameCellCommand::redo()
+{
+ bool r = false;
+ DCContainer *container = getController()->getCurrentContainer();
+ if (container)
+ r = container->renameCell(d_cell, d_name);
+
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
+}
+
+void DCRenameCellCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+
+DCMoveCellCommand::DCMoveCellCommand(const void *requester, DCCreator *creator, DCCell *cell, DCVCPage *newPage)
+ : DCCommand(requester, creator), d_cell(cell), d_page(newPage)
+{
+}
+
+DCMoveCellCommand::~DCMoveCellCommand()
+{
+
+}
+
+void DCMoveCellCommand::redo()
+{
+ bool r = false;
+
+ if (d_page && d_cell)
+ {
+ d_cell->getVComponent()->changePageBelonging(d_page);
+ r = true;
+ }
+
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
+}
+
+void DCMoveCellCommand::undo()
+{
+
+}
+
+/*--------------------------------*/
+
+DCRemoveCellCommand::DCRemoveCellCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCell* cell)
+ : DCCommand(requester, creator), d_container(container)
+{
+ d_cells.append(cell);
+}
+
+DCRemoveCellCommand::DCRemoveCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCell*> &cells)
: DCCommand(requester, creator), d_container(container), d_cells(cells)
{
}
-DCRemoveCellsCommand::~DCRemoveCellsCommand()
+DCRemoveCellCommand::~DCRemoveCellCommand()
{
}
-void DCRemoveCellsCommand::redo()
+void DCRemoveCellCommand::redo()
{
+ bool r = true;
for (int i = 0; i < d_cells.length(); i++)
{
- d_container->removeCell(d_cells.at(i));
+ if (!d_container->removeCell(d_cells.at(i)))
+ {
+ r = false;
+ }
}
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
-void DCRemoveCellsCommand::undo()
+void DCRemoveCellCommand::undo()
{
}
{
DCTreeViewWidget::requestSelectionWhenRowAdded();
d_page = getScene()->addPage(d_path.toStdString());
- getController()->savePage(d_page);
+ bool r = getController()->savePage(d_page);
getController()->selectPage(getRequester(), d_page, false);
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCAddPageCommand::undo()
}
/*--------------------------------*/
+DCMovePageCommand::DCMovePageCommand(const void *requester, DCCreator *creator, const QString &oldContainerBasedPathName, const QString &newContainerBasedPathName)
+ : DCCommand(requester, creator), d_oldPath(oldContainerBasedPathName), d_newPath(newContainerBasedPathName)
+{
+}
+
+DCMovePageCommand::~DCMovePageCommand()
+{
+ qDebug() << "DCRenamePageCommand removed..";
+}
+
+void DCMovePageCommand::redo()
+{
+ bool r = false;
+
+ DCContainer *container = getController()->getCurrentContainer();
+ DCVCPage *oldPage = getScene()->getPage(d_oldPath.toStdString());
+ if (container && oldPage && !getScene()->getIsPageExist(d_newPath.toStdString()))
+ {
+ DCTreeViewWidget::requestSelectionWhenRowAdded();
+ DCVCPage *newPage = container->movePage(d_oldPath, d_newPath);
+ getController()->selectPage(getRequester(), newPage, false);
+
+ if (newPage)
+ {
+ r = getController()->saveAll(false);
+ }
+ if (r)
+ {
+ QString filePath = QString::fromStdString(container->getContainerRootPath());
+ filePath.append(d_oldPath);
+
+ QString sceneSettingFilePath = getScene()->getSceneSettingFilePathForPage(oldPage);
+
+ if (!DCTreeViewWidget::removeFile(filePath))
+ {
+ r = false;
+ }
+ QDir dir;
+ dir.remove(sceneSettingFilePath);
+
+ if (!getScene()->removePage(oldPage))
+ {
+ r = false;
+ }
+ }
+ }
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
+}
+
+void DCMovePageCommand::undo()
+{
+
+}
+
+
+/*--------------------------------*/
DCRemovePageCommand::DCRemovePageCommand(const void *requester, DCCreator *creator, DCVCPage *page)
: DCCommand(requester, creator), d_page(page)
{
void DCRemovePageCommand::redo()
{
+ bool r = false;
+
const QList<DCVPageComponent*> *vcells = d_page->getCells();
- const QList<DCVPageComponent*> *cellCodeClasses = d_page->getCellCodeClasses();
+ const QList<DCVPageComponent*> *vcellCodeClasses = d_page->getCellCodeClasses();
DCContainer *container = getController()->getCurrentContainer();
- for (int i = 0; i < cellCodeClasses->length(); i++)
+ QList<DCCellCode*> cellcodes;
+ for (int i = 0; i < vcellCodeClasses->length(); i++)
+ {
+ DCCellCode *cellCode = dynamic_cast<DCVCCellCode*>(vcellCodeClasses->at(i))->getOwnerCellCodeClass();
+ if (cellCode)
+ cellcodes.append(cellCode);
+ }
+
+ if (cellcodes.length()>0)
{
- DCCellCode *cellCode = dynamic_cast<DCVCCellCode*>(cellCodeClasses->at(i))->getOwnerCellCodeClass();
- DCCommand *command = new DCRemoveCellCodeClassCommand(getRequester(), getController(), container, cellCode);
+ DCCommand *command = new DCRemoveCellCodeClassCommand(getRequester(), getController(), container, cellcodes);
d_undoStack.push(command);
+
+ if (command->getCommandResult() != DCCommand::DCCOMMAND_SUCCEEDED)
+ r = false;
}
QList<DCCell*> cells;
cells.append(cell);
}
- DCCommand *removeCellCommand = new DCRemoveCellsCommand(getRequester(), getController(), container, cells);
- d_undoStack.push(removeCellCommand);
+ if (cells.length()>0)
+ {
+ DCCommand *command = new DCRemoveCellCommand(getRequester(), getController(), container, cells);
+ d_undoStack.push(command);
+
+ if (command->getCommandResult() != DCCommand::DCCOMMAND_SUCCEEDED)
+ r = false;
+ }
QString filePath = QString::fromStdString(getController()->getCurrentContainer()->getContainerRootPath());
filePath.append(d_page->getLocationPath());
QString sceneSettingFilePath = getScene()->getSceneSettingFilePathForPage(d_page);
QDir dir;
- dir.remove(filePath);
+ if (!dir.remove(filePath))
+ {
+ r = false;
+ }
dir.remove(sceneSettingFilePath);
- getScene()->removePage(d_page);
+ if (!getScene()->removePage(d_page))
+ {
+ r = false;
+ }
+
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCRemovePageCommand::undo()
void DCAddDirectoryCommand::redo()
{
- DCTreeViewWidget::addDirectory(d_path);
+ bool r = DCTreeViewWidget::addDirectory(d_path);
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCAddDirectoryCommand::undo()
}
/*--------------------------------*/
+DCRenameDirectoryCommand::DCRenameDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysOldFilePath, const QString &sysNewFilePath)
+ : DCCommand(requester, creator), d_oldPath(sysOldFilePath), d_newPath(sysNewFilePath)
+{
+
+}
+
+void DCRenameDirectoryCommand::redo()
+{
+ DCContainer *container = getController()->getCurrentContainer();
+ //TODO
+}
+
+void DCRenameDirectoryCommand::undo()
+{
+
+}
+
+
+/*--------------------------------*/
DCRemoveDirectoryCommand::DCRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysFilePath)
: DCCommand(requester, creator), d_path(sysFilePath)
{
void DCRemoveDirectoryCommand::redo()
{
- DCTreeViewWidget::removeDirectory(d_path);
+ bool r = DCTreeViewWidget::removeDirectory(d_path);
+ setCommandResult(r ? DCCommand::DCCOMMAND_SUCCEEDED : DCCommand::DCCOMMAND_FAILED);
}
void DCRemoveDirectoryCommand::undo()
//------------------------------------------
-class DCRemoveCellCodeClassCommand : public DCCommand
+class DCMoveCellCodeClassCommand : public DCCommand
{
- DCContainer *d_container;
- DCCellCode *d_cellCode;
+ QString d_name;
QString d_type;
public:
+ DCMoveCellCodeClassCommand(const void *requester, DCCreator *creator, const QString& name, const QString &type);
+ virtual ~DCMoveCellCodeClassCommand();
+ void undo();
+ void redo();
+};
+
+//------------------------------------------
+
+class DCRemoveCellCodeClassCommand : public DCCommand
+{
+ DCContainer *d_container;
+ QList<DCCellCode*> d_cellCodes;
+ QString d_type;
+
+public:
DCRemoveCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCellCode* cellCode);
+ DCRemoveCellCodeClassCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCellCode*> &cellcodes);
virtual ~DCRemoveCellCodeClassCommand();
void undo();
void redo();
//------------------------------------------
-class DCRemoveCellsCommand : public DCCommand
+class DCRenameCellCommand : public DCCommand
+{
+ DCCell *d_cell;
+ QString d_name;
+
+public:
+ DCRenameCellCommand(const void *requester, DCCreator *creator, DCCell *cell, const QString& newName);
+ virtual ~DCRenameCellCommand();
+ void undo();
+ void redo();
+};
+
+//------------------------------------------
+
+class DCMoveCellCommand : public DCCommand
+{
+ DCCell *d_cell;
+ DCVCPage *d_page;
+
+public:
+ DCMoveCellCommand(const void *requester, DCCreator *creator, DCCell *cell, DCVCPage *newPage);
+ virtual ~DCMoveCellCommand();
+ void undo();
+ void redo();
+};
+
+//------------------------------------------
+
+class DCRemoveCellCommand : public DCCommand
{
DCContainer *d_container;
QList<DCCell*> d_cells;
public:
- DCRemoveCellsCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCell*> &cells);
- virtual ~DCRemoveCellsCommand();
+ DCRemoveCellCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCell *cell);
+ DCRemoveCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCell*> &cells);
+ virtual ~DCRemoveCellCommand();
void undo();
void redo();
};
//------------------------------------------
+class DCMovePageCommand : public DCCommand
+{
+ QString d_oldPath;
+ QString d_newPath;
+
+public:
+ DCMovePageCommand(const void *requester, DCCreator *creator, const QString& oldContainerBasedPathName, const QString& newContainerBasedPathName);
+ virtual ~DCMovePageCommand();
+ void undo();
+ void redo();
+};
+
+//------------------------------------------
+
class DCRemovePageCommand : public DCCommand
{
DCVCPage *d_page;
//------------------------------------------
+class DCRenameDirectoryCommand : public DCCommand
+{
+ QString d_oldPath;
+ QString d_newPath;
+
+public:
+ DCRenameDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysOldFilePath, const QString& sysNewFilePath);
+ virtual ~DCRenameDirectoryCommand() {}
+ void undo();
+ void redo();
+};
+
+//------------------------------------------
+
class DCRemoveDirectoryCommand : public DCCommand
{
QString d_path;
}
return true;
}
+
+void DCCell::changeName(const QString &newName)
+{
+ mName = newName.toStdString();
+}
+
+void DCCell::changePath(const QString &newPath)
+{
+ mLocation = newPath.toStdString();
+}
Q_OBJECT
friend class DCComponentUtil;
+ friend class DCContainer;
+
DCCell(DCContainer *container, std::string location, std::string name, std::string type, bool canInterface);
void bindComponent(DCVPageComponent *component);
bool removeAllConnections();
+ /**
+ * Change name of this cell.
+ * DCContainer will call this method.
+ */
+ void changeName(const QString& newName);
+
+ /**
+ * Change the location path for this cell.
+ * DCContainer will call this method.
+ */
+ void changePath(const QString& newPath);
+
+
public:
virtual ~DCCell();
void setViewHeight(float height);
bool saveCustomScript(const QString& script);
- /* This method is exepected to be called from command classes (defined in dceditcommands.h).
- * This will remove receptor from the list
- * This will remove receptor object but won't remove the axon terminal connected to the receptor
+ /* Following methods are expected to be called from command classes (defined in dceditcommands.h).
+ */
+
+ /**
+ * Remove receptor from the list
+ * Note that this remove receptor object but won't remove the axon terminal connected to the receptor.
+ * This method is expected to be only called from command classes (defined in dceditcommands.h )
*/
bool removeReceptor(const QString &name);
+
+
+ /**
+ * Remove receptor from the list
+ * Note that this remove receptor object but won't remove the axon terminal connected to the receptor.
+ * This method is expected to be only called from command classes (defined in dceditcommands.h )
+ */
bool removeReceptor(DCReceptor *receptor);
- /* This method is exepected to be called from command.
+ /**
+ * Create a receptor with the given name and register it into this cell.
+ * This method is expected to be only called from command classes (defined in dceditcommands.h )
*/
virtual DCReceptor* createReceptor(const QString &receptorName);
#include "dcvccellcode.h"
#include "dccontainer.h"
+#include "utils/dcutil.h"
-DCCellCode::DCCellCode(std::string theName, std::string theCellAPIName)
- : TKCellCode(theName, theCellAPIName)
+DCCellCode::DCCellCode(DCContainer *container, std::string theName, std::string theCellAPIName)
+ : TKCellCode(theName, theCellAPIName), d_container(container)
{
}
{
}
-QString DCCellCode::getOwnScript(DCContainer *container) const
+QString DCCellCode::getOwnScript() const
{
- return container->readCellCodeScriptFromFile(this);
+ return d_container->readCellCodeScriptFromFile(this);
}
-void DCCellCode::saveScript(DCContainer *container, const QString &script)
+void DCCellCode::saveScript(const QString &script)
{
- container->saveClassScriptToWorkFile(this, script.toStdString());
+ d_container->saveClassScriptToWorkFile(this, script.toStdString());
}
DCVCPage* DCCellCode::getPageBelonging() const
{
- return mVComponent->getPageBelonging();
+ return d_vComponent->getPageBelonging();
}
+
+void DCCellCode::changeName(const QString &newName)
+{
+ QString fqnString = DCUtil::getFQNPath(getPageBelonging()->getLocationPath(), newName);
+ mFQNName = fqnString.toStdString();
+}
+
+void DCCellCode::changePath(const QString& newPath)
+{
+ QString name = DCUtil::getNameFromFQNPath(QString::fromStdString(mFQNName));
+ QString fqnString = DCUtil::getFQNPath(newPath, name);
+ mFQNName = fqnString.toStdString();
+}
+
class DCCellCode : public TKCellCode
{
friend class DCComponentUtil;
- DCCellCode(std::string theName, std::string theCellAPIName);
- void bindComponent(DCVPageComponent *component) { mVComponent = component; }
+ friend class DCContainer;
- DCVPageComponent *mVComponent;
+ DCCellCode(DCContainer *container, std::string theName, std::string theCellAPIName);
+ void bindComponent(DCVPageComponent *component) { d_vComponent = component; }
+
+ DCVPageComponent *d_vComponent;
+ DCContainer *d_container;
+
+ /**
+ * Change name of this cell code.
+ * DCContainer will call this method.
+ */
+ void changeName(const QString& newName);
+
+ /**
+ * Change the location path for this cell code.
+ * DCContainer will call this method.
+ */
+ void changePath(const QString& newPath);
public:
virtual ~DCCellCode();
virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) { return 0; }
- void saveScript(DCContainer *container, const QString& script);
- DCVPageComponent *getVComponent() const { return mVComponent; }
- DCVCPage* getPageBelonging() const;
- QString getOwnScript(DCContainer *container) const;
-
+ void saveScript(const QString& script);
+ DCVPageComponent* getVComponent() const { return d_vComponent; }
+ DCVCPage* getPageBelonging() const;
+ QString getOwnScript() const;
+ DCContainer* getContainer() const { return d_container; }
};
#endif // DCCELLCODE_H
#include "dcaxon.h"
#include "dcaxonterminal.h"
#include "dcreceptor.h"
-#include "DNUtils.h"
#include "dcscene.h"
#include "dccontent.h"
#include "dccreator.h"
#include <QDir>
#include <QDirIterator>
+
//static
TKContainer* TKContainer::createContainer()
{
{
if (location != d_factoryCachedLocation || d_factoryCachedPageObject.ref() == NULL)
{
- d_factoryCachedPageObject.assign(d_scene->findPage(location));
+ d_factoryCachedPageObject.assign(d_scene->getPage(location));
if (d_factoryCachedPageObject.ref() == NULL)
{
d_factoryCachedPageObject.assign(d_scene->addPage(location));
}
if (location != d_factoryCachedLocation || d_factoryCachedPageObject.ref() == NULL)
{
- d_factoryCachedPageObject.assign(d_scene->findPage(location));
+ d_factoryCachedPageObject.assign(d_scene->getPage(location));
if (d_factoryCachedPageObject.ref() == NULL)
{
d_factoryCachedPageObject.assign(d_scene->addPage(location));
d_factoryCachedLocation = location;
page = dynamic_cast<DCVCPage*>(d_factoryCachedPageObject.ref());
}
- return DCComponentUtil::createCellCode(page, name, cellapi);
+ return DCComponentUtil::createCellCode(this, page, name, cellapi);
}
void DCContainer::beganParsePage(const char *docRoot, const char *path)
}
std::string location = path;
- d_factoryCachedPageObject.assign(d_scene->findPage(location));
+ d_factoryCachedPageObject.assign(d_scene->getPage(location));
if (d_factoryCachedPageObject.ref() == NULL)
{
d_factoryCachedPageObject.assign(d_scene->addPage(location));
bool DCContainer::saveClassScriptToWorkFile(TKCellCode *cellCode, std::string code)
{
- QString qNamePath = QString::fromStdString(cellCode->getName());
- int idx = qNamePath.lastIndexOf("#");
- QString path;
- QString name;
- if (idx >= 0)
- {
- path = qNamePath.left(idx);
- name = qNamePath.mid(idx + 1);
- }
- else
- {
- path = "";
- name = qNamePath;
- }
+ QString qNamePath = QString::fromStdString(cellCode->getFQNName());
+ QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
+ QString name = DCUtil::getNameFromFQNPath(qNamePath);
QDir workdir(d_workDirCellCodeRoot + "/" + path);
if (!workdir.exists())
QString DCContainer::readCellCodeScriptFromFile(const DCCellCode *cellCode)
{
- QString qNamePath = QString::fromStdString(cellCode->getName());
- int idx = qNamePath.lastIndexOf("#");
- QString path;
- QString name;
- if (idx >= 0)
- {
- path = qNamePath.left(idx);
- name = qNamePath.mid(idx + 1);
- }
- else
- {
- path = "";
- name = qNamePath;
- }
+ QString qNamePath = QString::fromStdString(cellCode->getFQNName());
+ QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
+ QString name = DCUtil::getNameFromFQNPath(qNamePath);
QFile file(d_workDirCellCodeRoot + "/" + path + "/" + name + ".js");
if (!file.exists())
return out;
}
+QString DCContainer::sysFilePathToContainerBasedPath(const QString &sysFilePath)
+{
+ QString containerPath = QString::fromStdString(getContainerRootPath());
+ return "/" + QDir(containerPath).relativeFilePath(sysFilePath);
+}
+
+bool DCContainer::renameCell(DCCell *cell, const QString &newName)
+{
+ QString fqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
+ mCells.erase(fqnName.toStdString());
+
+ cell->changeName(newName);
+
+ QString newFqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
+ std::pair<TKCellMap::iterator, bool> r = mCells.insert(TKCellMap::value_type(newFqnName.toStdString(), cell));
+
+ return r.second;
+}
+
+bool DCContainer::moveCell(DCCell *cell, const QString& pageNewContainerBasedPathName)
+{
+ QString fqnName = DCUtil::getFQNPath(cell->getLocation(), cell->getName());
+ QString customScript = readCustomScriptFromWorkFile(cell);
+ mCells.erase(fqnName.toStdString());
+
+ cell->changePath(pageNewContainerBasedPathName);
+ saveCustomScriptToWorkFile(cell, customScript.toStdString());
+
+ QString newFqnName = DCUtil::getFQNPath(pageNewContainerBasedPathName.toStdString(), cell->getName());
+ std::pair<TKCellMap::iterator, bool> r = mCells.insert(TKCellMap::value_type(newFqnName.toStdString(), cell));
+ return r.second;
+}
+
+bool DCContainer::renameCellCodeClass(DCCellCode *cellcode, const QString &newName)
+{
+ mCellCodes.erase(cellcode->getFQNName());
+ cellcode->changeName(newName);
+ std::pair<TKCellCodeMap::iterator, bool> r = mCellCodes.insert(TKCellCodeMap::value_type(cellcode->getFQNName(), cellcode));
+
+ return r.second;
+}
+
+bool DCContainer::moveCellCodeClass(DCCellCode *cellcode, const QString& pageNewContainerBasedPathName)
+{
+ QString script = readCellCodeScriptFromFile(cellcode);
+ mCellCodes.erase(cellcode->getFQNName());
+
+ cellcode->changePath(pageNewContainerBasedPathName);
+ saveClassScriptToWorkFile(cellcode, script.toStdString());
+
+ std::pair<TKCellCodeMap::iterator, bool> r = mCellCodes.insert(TKCellCodeMap::value_type(cellcode->getFQNName(), cellcode));
+
+ return r.second;
+}
+
+DCVCPage* DCContainer::movePage(const QString &oldContainerBasedPathName, const QString &newContainerBasedPathName)
+{
+ bool r = false;
+ DCVCPage *newPage = NULL;
+ DCScene *scene = getScene();
+ if (scene)
+ {
+ DCVCPage *oldPage = getScene()->getPage(oldContainerBasedPathName.toStdString());
+ newPage = getScene()->addPage(newContainerBasedPathName.toStdString());
+
+ if (oldPage && newPage)
+ {
+ r = oldPage->moveComponentsTo(newPage);
+ }
+ }
+
+ return r ? newPage : NULL;
+}
virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
virtual TKCellCode* cellCodeFactory(std::string name, std::string cellapi, std::string code);
- /*
- * remove cell code from container and the page (DCVCPage) belonging.
+ /**
+ * @brief remove cell from container and the page (DCVCPage) belonging.
+ * @param cell
+ *
+ * All the axon terminals connected to this cell will also be removed after this.
+ * This expected to only be called from command classes which are defined in dceditcommands.h
+ *
+ * @return true for success, false for failure
+ */
+ bool removeCell(DCCell *cell);
+
+ /**
+ * @brief remove cell code from container and the page (DCVCPage) belonging.
+ * @param cellcode
+ *
* The cells which use the deleting cell code will have empty cell code after this.
* This expected to only be called from command classes which are defined in dceditcommands.h
+ *
+ * @return true for success, false for failure
*/
bool removeCellCode(DCCellCode *cellcode);
- /*
- * remove cell from container and the page (DCVCPage) belonging.
- * All the axon terminals connected to this cell will also be removed after this.
- * This expected to only be called from command classes which are defined in dceditcommands.h
+ /**
+ * @brief movePage
+ *
+ * @param oldContainerBasedPathName
+ * @param newContainerBasedPathName
+ *
+ * Change the name / path for a container file.
+ * All cells, cell codes and connections are updated accordingly.
+ * This expected to be called from command classes which are defined in dceditcommands.h
+ *
+ * @return pointer to a page object for the new file path or NULL when this failed.
*/
- bool removeCell(DCCell *cell);
+ DCVCPage* movePage(const QString &oldContainerBasedPathName, const QString &newContainerBasedPathName);
+
+ /**
+ * @brief change the path information of a cell.
+ * @param cell
+ * @param pageNewContainerBasedPathName
+ *
+ * @note This will be called from DCVCCell::changePageBelonging().
+ * This shouldn't be directly called from other methods.
+ * @return
+ */
+ bool moveCell(DCCell*cell, const QString& pageNewContainerBasedPathName);
+
+ /**
+ * @brief change the path information of a cell code.
+ * @param cellcode
+ * @param pageNewContainerBasedPathName
+ *
+ * @note This will be called from DCVCCellCode::changePageBelonging().
+ * This shouldn't be directly called from other methods.
+ * @return
+ */
+ bool moveCellCodeClass(DCCellCode*cellcode, const QString& pageNewContainerBasedPathName);
+
+ bool renameCell(DCCell *cell, const QString& newName);
+
+ bool renameCellCodeClass(DCCellCode *cellcode, const QString& newName);
+
//
DCContent* getContent() const { return d_content; }
DCScene* getScene() const { return d_scene; }
bool saveCustomScriptToWorkFile(TKCell *cell, std::string customScript);
bool saveClassScriptToWorkFile(TKCellCode *cellCode, std::string code);
+ QString sysFilePathToContainerBasedPath(const QString& sysFilePath);
QString readCustomScriptFromWorkFile(const DCCell *cell);
QString readCellCodeScriptFromFile(const DCCellCode *cellcode);
#include "dcaxonterminal.h"
#include "dcvpagecomponent.h"
#include "dcscene.h"
+#include "utils/dcutil.h"
#include <QDomDocument>
#include <QMap>
aCellCodeTag.setAttribute("parameter", "cellcode");
if (cell->getCellCode() && cell->getCellCode() != d_container->getEmptyCellCodeClass())
{
- aCellCodeTag.setAttribute("href", QString::fromStdString(cell->getCellCode()->getName()));
+ aCellCodeTag.setAttribute("href", QString::fromStdString(cell->getCellCode()->getFQNName()));
}
else
{
for (int i = 0; i < vcellcodeclasses->length(); i++)
{
DCCellCode *cellcodeclass = dynamic_cast<DCVCCellCode*>(vcellcodeclasses->at(i))->getOwnerCellCodeClass();
- QString cellCodeClassName = QString::fromStdString(cellcodeclass->getName());
- if (cellCodeClassName.indexOf("#") >= 0)
- cellCodeClassName = cellCodeClassName.mid(cellCodeClassName.indexOf("#")+1);
+ QString cellCodeClassName = DCUtil::getNameFromFQNPath(QString::fromStdString(cellcodeclass->getFQNName()));
QDomElement aCellCodeTag = doc.createElement("a");
aCellCodeTag.setAttribute("define", "cellcode");
DCCommandUtil::postAddPageCommand(requester, this, containerBasedPath);
}
+void DCCreator::doCommandMovePage(const void *requester, const QString &oldContainerBasedPath, const QString &newContainerBasedPath)
+{
+ DCCommandUtil::postMovePageCommand(requester, this, oldContainerBasedPath, newContainerBasedPath);
+}
+
void DCCreator::doCommandRemovePage(const void *requester, DCVCPage *page)
{
DCCommandUtil::postRemovePageCommand(requester, this, page);
DCCommandUtil::postAddDirectoryCommand(requester, this, sysFilePath);
}
-void DCCreator::doCommandRemoveDirectory(const void *requester, const QString &sysFilePath)
+void DCCreator::doCommandRenameDirectory(const void *requester, const QString &oldSysFilePath, const QString &newSysFilePath)
{
- DCCommandUtil::postRemoveDirectoryCommand(requester, this, sysFilePath);
+ DCCommandUtil::postRenameDirectoryCommand(requester, this, oldSysFilePath, newSysFilePath);
}
bool DCCreator::doCommandRenameDirectoryImmidiate(const void *requester, const QString &containerBasedPath, const QString &oldName, const QString &newName)
return false;
}
+void DCCreator::doCommandRemoveDirectory(const void *requester, const QString &sysFilePath)
+{
+ DCCommandUtil::postRemoveDirectoryCommand(requester, this, sysFilePath);
+}
+
DCContainer* DCCreator::getCurrentContainer() const
{
if (d_vcontent)
void doCommandAddCell(const void *requester, DCContainer *container, const QString& containerBasedPath, const QString& name, const QString& type);
void doCommandRemoveCells(const void *requester, DCContainer *container, const QList<DCCell*> &cells);
void doCommandAddPage(const void *requester, const QString& containerBasedPath);
+ void doCommandMovePage(const void *requester, const QString &oldContainerBasedPath, const QString &newContainerBasedPath);
void doCommandRemovePage(const void *requester, DCVCPage *page);
void doCommandAddDirectory(const void *requester, const QString& sysFilePath);
+ void doCommandRenameDirectory(const void *requester, const QString& oldSysFilePath, const QString& newSysFilePath);
void doCommandRemoveDirectory(const void *requester, const QString& sysFilePath);
bool doCommandRenameDirectoryImmidiate(const void *requester, const QString& containerBasedPath, const QString& oldName, const QString &newName);
#include <QVBoxLayout>
#include <QLabel>
+#include <QFileInfo>
-DCInputNewPageNameDialog::DCInputNewPageNameDialog(QWidget *parent) :
- QDialog(parent), d_result("")
+DCInputNewPageNameDialog::DCInputNewPageNameDialog(const QString &sysDir, const QString &windowTitle, const QString &fileName, QWidget *parent)
+ : QDialog(parent), d_dir(sysDir), d_result("")
{
- d_inputField = new QLineEdit();
+ setWindowTitle(windowTitle);
+
+ d_inputField = new QLineEdit(fileName);
QVBoxLayout *contentLayout = new QVBoxLayout;
contentLayout->addWidget(new QLabel(tr("name")));
QHBoxLayout *hlayout = new QHBoxLayout;
void DCInputNewPageNameDialog::inputChanged()
{
- // TODO:
- // Need to consider the case when the name has already existed.
- //
if (d_inputField->text().length() > 0)
{
- d_okButton->setEnabled(true);
+ QFileInfo fileInfo(d_dir + "/" + d_inputField->text() + ".xhtml");
+ if (!fileInfo.exists())
+ d_okButton->setEnabled(true);
+ else
+ d_okButton->setEnabled(false);
}
else
{
{
Q_OBJECT
+ QString d_dir;
QString d_result;
QLineEdit *d_inputField;
QPushButton *d_okButton;
QPushButton *d_cancelButton;
public:
- explicit DCInputNewPageNameDialog(QWidget *parent = 0);
+ DCInputNewPageNameDialog(const QString& sysDir, const QString& windowTitle, const QString& fileName = "", QWidget *parent = 0);
virtual ~DCInputNewPageNameDialog() {}
QString getName() const { return d_result + ".xhtml"; }
#define __INCLUDE_TKCELLCODE__
#include <string>
-#include <vector>
class TKReceptor;
class TKContainer;
class TKCellCode
{
public:
- TKCellCode(std::string theName, std::string theCellAPIName) : mName(theName), mCellAPIName(theCellAPIName) {}
+ TKCellCode(std::string theFQNName, std::string theCellAPIName) : mFQNName(theFQNName), mCellAPIName(theCellAPIName) {}
virtual ~TKCellCode() {}
- std::string getName() const { return mName; }
+ std::string getFQNName() const { return mFQNName; }
std::string getCellAPIName() const { return mCellAPIName; }
virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) = 0;
-private:
- std::string mName;
+protected:
+ std::string mFQNName;
std::string mCellAPIName;
};
const TKCellMap* getCells() { return &mCells; }
const TKCellCodeMap* getCellCodes() { return &mCellCodes; }
- void setContainerRootPath(std::string contentPath) { mContainerRootPath = contentPath; }
+ void setContainerRootPath(std::string containerPath) { mContainerRootPath = containerPath; }
std::string getContainerRootPath() { return mContainerRootPath; }
bool setDataStore(std::string storagePath);
DNStorage* getDataStore() { return mStorage; }
connect(d_creator, SIGNAL(destroyed(QObject*)), this, SLOT(creatorDestroyed()));
connect(&d_fileSystemModel, SIGNAL(directoryLoaded(QString)), this, SLOT(directoryLoaded(QString)));
-
+ connect(&d_fileSystemModel, SIGNAL(rowsRemoved(const QModelIndex, int, int)), this, SLOT(rowsRemoved()));
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(doContextMenu(const QPoint&)));
connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*)));
if (s_treeViewWidget)
{
QModelIndex index = s_treeViewWidget->d_fileSystemModel.index(path);
- if (index.isValid())
+ if (index.isValid() && s_treeViewWidget->d_fileSystemModel.fileInfo(index).isDir())
{
r = s_treeViewWidget->d_fileSystemModel.rmdir(index);
+ if (r)
+ {
+ //hack for prevening auto selection happing by removing row.
+ s_treeViewWidget->d_inSelectionChange = true;
+ }
+ }
+ }
+ else
+ {
+ Q_ASSERT(0);
+ }
+ return r;
+}
+
+//static
+bool DCTreeViewWidget::removeFile(const QString &path)
+{
+ bool r = false;
+
+ if (s_treeViewWidget)
+ {
+ QModelIndex index = s_treeViewWidget->d_fileSystemModel.index(path);
+ if (index.isValid() && s_treeViewWidget->d_fileSystemModel.fileInfo(index).isFile())
+ {
+ r = s_treeViewWidget->d_fileSystemModel.remove(index);
+ if (r)
+ {
+ //hack for prevening auto selection happing by removing row.
+ s_treeViewWidget->d_inSelectionChange = true;
+ }
}
}
else
if (showMenu)
{
- QString containerPath;
- QString containerBasedPath;
+ DCContainer *container = d_creator->getCurrentContainer();
- if (index.isValid())
+ if (container)
{
- containerPath = QString::fromStdString(d_creator->getCurrentContainer()->getContainerRootPath());
- containerBasedPath = "/" + QDir(containerPath).relativeFilePath(fileModel->filePath(index));
- }
+ QString containerBasedPath;
- QAction* selectedItem = menu.exec(globalPos);
- if (selectedItem)
- {
- if (selectedItem == addDictionaryAction)
- {
- if (index.isValid())
- d_creator->doCommandAddDirectory(this, fileModel->filePath(index));
- }
- else if (selectedItem == removeDirectoryAction)
+ if (index.isValid())
{
- if (index.isValid())
- d_creator->doCommandRemoveDirectory(this, fileModel->filePath(index));
+ containerBasedPath = container->sysFilePathToContainerBasedPath(fileModel->filePath(index));
}
- else if (selectedItem == addPageAction)
+
+ QAction* selectedItem = menu.exec(globalPos);
+ if (selectedItem)
{
- if (index.isValid())
+ if (selectedItem == addDictionaryAction)
+ {
+ if (index.isValid())
+ d_creator->doCommandAddDirectory(this, fileModel->filePath(index));
+ }
+ else if (selectedItem == removeDirectoryAction)
{
- if (containerBasedPath.length() >= 1)
+ if (index.isValid())
+ d_creator->doCommandRemoveDirectory(this, fileModel->filePath(index));
+ }
+ else if (selectedItem == addPageAction)
+ {
+ if (index.isValid())
{
- DCInputNewPageNameDialog dialog;
- if (dialog.exec())
+ if (containerBasedPath.length() >= 1)
{
- QString pageName = dialog.getName();
- if (pageName.length() > 0)
+ DCInputNewPageNameDialog dialog(fileModel->filePath(index), tr("Add new page"));
+ if (dialog.exec())
{
- QString pathName = containerBasedPath;
- if (containerBasedPath.length()>1)
- pathName.append("/");
- pathName.append(pageName);
- d_creator->doCommandAddPage(this, pathName);
+ QString pageName = dialog.getName();
+ if (pageName.length() > 0)
+ {
+ QString pathName = containerBasedPath;
+ if (containerBasedPath.length()>1)
+ pathName.append("/");
+ pathName.append(pageName);
+ d_creator->doCommandAddPage(this, pathName);
+ }
}
}
}
}
- }
- else if (selectedItem == renamePageAction)
- {
- //TODO
- QMessageBox msgBox;
- msgBox.setText("This command hasn't implemented yet");
- msgBox.exec();
- }
- else if (selectedItem == removePageAction)
- {
- if (index.isValid())
+ else if (selectedItem == renamePageAction)
{
- bool doExecute = true;
- DCVCPage *page = d_scene->findPage(containerBasedPath.toStdString());
- if (page->getCells()->length() > 0 || page->getCellCodeClasses()->length() > 0)
+ if (index.isValid())
{
- QMessageBox::StandardButton button = QMessageBox::warning(this,
- tr("Remove file"),
- tr("This Page has cells / cellcodes. Those cells / cell codes will be removed"),
- QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel);
-
- doExecute = (button == QMessageBox::Ok);
+ if (containerBasedPath.length() >= 1)
+ {
+ QFileInfo fileInfo = fileModel->filePath(index);
+ QString oldName = fileInfo.fileName().left(fileInfo.fileName().length() - fileInfo.completeSuffix().length() - 1);
+ DCInputNewPageNameDialog dialog(fileInfo.absolutePath(), tr("Rename"), oldName);
+ if (dialog.exec())
+ {
+ QString pageName = dialog.getName();
+ if (pageName.length() > 0)
+ {
+ QString pathName = container->sysFilePathToContainerBasedPath(fileInfo.absolutePath() + "/" + pageName);
+ d_creator->doCommandMovePage(this, containerBasedPath, pathName);
+ }
+ }
+ }
}
- if (doExecute)
+ }
+ else if (selectedItem == removePageAction)
+ {
+ if (index.isValid())
{
- d_creator->doCommandRemovePage(this, page);
+ bool doExecute = true;
+ DCVCPage *page = d_scene->getPage(containerBasedPath.toStdString());
+ if (page->getCells()->length() > 0 || page->getCellCodeClasses()->length() > 0)
+ {
+ QMessageBox::StandardButton button = QMessageBox::warning(this,
+ tr("Remove file"),
+ tr("This Page has cells / cellcodes. Those cells / cell codes will be removed"),
+ QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel);
+
+ doExecute = (button == QMessageBox::Ok);
+ }
+ if (doExecute)
+ {
+ d_creator->doCommandRemovePage(this, page);
+ }
}
}
- }
- else if (selectedItem == addCellAction )
- {
- if (index.isValid())
+ else if (selectedItem == addCellAction )
{
- DCAddCellDialog dialog(d_creator->getCurrentContainer(), d_creator, containerBasedPath);
- dialog.exec();
+ if (index.isValid())
+ {
+ DCAddCellDialog dialog(container, d_creator, containerBasedPath);
+ dialog.exec();
+ }
}
- }
- else if (selectedItem == addCellCodeClassAction)
- {
- if (index.isValid())
+ else if (selectedItem == addCellCodeClassAction)
{
- DCAddCellCodeClassDialog dialog(d_creator->getCurrentContainer(), d_creator, containerBasedPath);
- dialog.exec();
+ if (index.isValid())
+ {
+ DCAddCellCodeClassDialog dialog(container, d_creator, containerBasedPath);
+ dialog.exec();
+ }
}
- }
+ }
}
}
}
}
}
+void DCTreeViewWidget::rowsRemoved()
+{
+ //hack for prevening auto selection happing by removing row.
+ d_inSelectionChange = false;
+}
+
void DCTreeViewWidget::creatorDestroyed()
{
d_creator = NULL;
static bool addDirectory(const QString &path);
static bool removeDirectory(const QString &path);
+ static bool removeFile(const QString &path);
static void requestSelectionWhenRowAdded();
protected:
void sceneChanged(const void *requester, DCScene*scene);
void selectedPageChanged(const void *requester, const DCScene*scene);
void creatorDestroyed();
+ void rowsRemoved();
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
//static
void DCCommandUtil::postRemoveCellsCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCell*> &cells)
{
- postEvent(creator, new DCRemoveCellsCommand(requester, creator, container, cells));
+ postEvent(creator, new DCRemoveCellCommand(requester, creator, container, cells));
}
//static
}
//static
+void DCCommandUtil::postMovePageCommand(const void *requester, DCCreator *creator, const QString &oldContainerBasedPath, const QString &newContainerBasedPath)
+{
+ postEvent(creator, new DCMovePageCommand(requester, creator, oldContainerBasedPath, newContainerBasedPath));
+}
+
+//static
void DCCommandUtil::postRemovePageCommand(const void *requester, DCCreator *creator, DCVCPage *page)
{
postEvent(creator, new DCRemovePageCommand(requester, creator, page));
}
//static
+void DCCommandUtil::postRenameDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysOldFilePath, const QString &sysNewFilePath)
+{
+ postEvent(creator, new DCRenameDirectoryCommand(requester, creator, sysOldFilePath, sysNewFilePath));
+}
+
+//static
void DCCommandUtil::postRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString &sysFilePath)
{
postEvent(creator, new DCRemoveDirectoryCommand(requester, creator, sysFilePath));
static void postAddCellCommand(const void *requester, DCCreator *creator, DCContainer *container, const QString& containerBasedPath, const QString& name, const QString& type);
static void postRemoveCellsCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList<DCCell*> &cells);
static void postAddPageCommand(const void *requester, DCCreator *creator, const QString& containerBasedPath);
+ static void postMovePageCommand(const void *requester, DCCreator *creator, const QString &oldContainerBasedPath, const QString& newContainerBasedPath);
static void postRemovePageCommand(const void *requester, DCCreator *creator, DCVCPage *page);
static void postAddDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
+ static void postRenameDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysOldFilePath, const QString& sysNewFilePath);
static void postRemoveDirectoryCommand(const void *requester, DCCreator *creator, const QString& sysFilePath);
};
}
//static
-DCCellCode* DCComponentUtil::createCellCode(DCVCPage *page, std::string theName, std::string theCellAPIName)
+DCCellCode* DCComponentUtil::createCellCode(DCContainer *container, DCVCPage *page, std::string theName, std::string theCellAPIName)
{
- DCCellCode *cellcode = new DCCellCode(theName, theCellAPIName);
+ DCCellCode *cellcode = new DCCellCode(container, theName, theCellAPIName);
DCVPageComponent *vcompo = new DCVCCellCode(cellcode, page);
cellcode->bindComponent(vcompo);
if (page)
struct DCComponentUtil
{
static DCCell* createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterface);
- static DCCellCode* createCellCode(DCVCPage *page, std::string theName, std::string theCellAPIName);
+ static DCCellCode* createCellCode(DCContainer *container, DCVCPage *page, std::string theName, std::string theCellAPIName);
static DCAxon* createAxon(DCCell *theOwner);
static DCAxonTerminal* createAxonTerminal(DCAxon *theOwner);
static DCReceptor* createReceptor(DCCell *theOwner);
//
#include "dcutil.h"
+#include "DNUtils.h"
+
#include <QDir>
#include <QFileInfoList>
}
}
}
+
+//static
+QString DCUtil::getFQNPath(const QString& containerBasedPath, const QString& name)
+{
+ return QString::fromStdString(getFQNString(containerBasedPath.toLocal8Bit().data(), name.toLocal8Bit().data()));
+}
+
+//static
+QString DCUtil::getFQNPath(std::string containerBasedPath, std::string name)
+{
+ return QString::fromStdString(getFQNString(containerBasedPath.c_str(), name.c_str()));
+}
+
+//static
+QString DCUtil::getNameFromFQNPath(const QString& fqnString)
+{
+ if (fqnString.indexOf("#") >= 0)
+ return fqnString.mid(fqnString.indexOf("#")+1);
+ else
+ return "";
+}
+
+//static
+QString DCUtil::getContainerBasedPathFromFQNPath(const QString& fqnPath)
+{
+ if (fqnPath.indexOf("#") >= 0)
+ return fqnPath.left(fqnPath.indexOf("#"));
+ else
+ return "";
+}
struct DCUtil
{
static void removeDirRecursive(QString path);
+ static QString getFQNPath(const QString& containerBasedPath, const QString& name);
+ static QString getFQNPath(std::string containerBasedPath, std::string name);
+ static QString getNameFromFQNPath(const QString& fqnString);
+ static QString getContainerBasedPathFromFQNPath(const QString& fqnPath);
+
};
#endif // DCUTIL_H
void DCVCCell::changePageBelonging(DCVCPage *page)
{
- //TODO
+ if (page)
+ {
+ page->registerCell(this);
+ }
+ else
+ {
+ getPageBelonging()->unregisterCell(this);
+ }
+
+ DCContainer *container = dynamic_cast<DCContainer*> (d_owner->getContainer());
+ if (container)
+ {
+ if (getPageBelonging())
+ {
+ container->moveCell(getOwnerCell(), page->getLocationPath());
+ }
+ else
+ {
+ //TODO
+ }
+ }
}
void DCVCCell::prepareChildrenForDraw(bool isAnimationInterval)
QString label1;
if (d_owner->getCellCode() && d_owner->getCellCode()!= d_emptyCellCode)
{
- label1 = QString::fromStdString(d_owner->getCellCode()->getName());
+ label1 = QString::fromStdString(d_owner->getCellCode()->getFQNName());
label1 = label1.mid(label1.lastIndexOf("#") + 1);
}
else
virtual DCCell* getOwnerCell() const { return d_owner; }
virtual bool isResizingArea(float x, float y, float z) const;
+ /**
+ * @brief Change page this cell belongs.
+ * @param page
+ * @note DCVCPage will call this.
+ * Other classes shouldn't directly call this method.
+ * To move cell to other page, DCMoveCellCommand should be used.
+ */
virtual void changePageBelonging(DCVCPage *page);
+
virtual void prepareChildrenForDraw(bool isAnimationInterval);
virtual void drawChildren(bool isAnimationInterval);
virtual void drawChildrenForSelection(QList<DCVComponent*> *itemList);
#include "dcvccellcode.h"
#include "dcvcomponent.h"
+#include "dccellcode.h"
+#include "dccontainer.h"
DCVCCellCode::DCVCCellCode(DCCellCode *owner, DCVCPage *page) : DCVPageComponent(page), d_owner(owner)
{
void DCVCCellCode::changePageBelonging(DCVCPage *page)
{
- //TODO
+ if (getPageBelonging() != page)
+ {
+ if (page)
+ {
+ page->registerCellCodeClass(this);
+ }
+ else
+ {
+ getPageBelonging()->unregisterCellCodeClass(this);
+ }
+ }
+
+ DCContainer *container = d_owner->getContainer();
+ if (container)
+ {
+ if (getPageBelonging())
+ {
+ container->moveCellCodeClass(getOwnerCellCodeClass(), page->getLocationPath());
+ }
+ else
+ {
+ //TODO
+ }
+ }
}
virtual DCCell * getOwnerCell() const { return NULL; }
virtual bool isResizingArea(float x, float y, float z) const { return false; }
+ /**
+ * @brief Change page this cell code belongs.
+ * @param page
+ * @note DCVCPage will call this.
+ * Other classes shouldn't directly call this method.
+ * To move cell to other page, DCMoveCellCodeClassCommand should be used.
+ */
DCCellCode* getOwnerCellCodeClass() const { return d_owner; }
virtual void changePageBelonging(DCVCPage *page);
virtual void prepareChildrenForDraw(bool isAnimationInterval) {}
d_editCursor = NULL;
}
+bool DCVCPage::moveComponentsTo(DCVCPage *newPage)
+{
+ QList<DCVPageComponent*> cells = d_cells;
+ for (int i = 0; i < cells.size(); i++)
+ {
+ cells.at(i)->changePageBelonging(newPage);
+ }
+
+ QList<DCVPageComponent*> cellCodes = d_cellCodeClasses;
+ for (int i = 0; i < cellCodes.size(); i++)
+ {
+ cellCodes.at(i)->changePageBelonging(newPage);
+ }
+
+ if (d_editCursor)
+ {
+ d_editCursor->changePageBelonging(newPage);
+ }
+ return true;
+}
+
void DCVCPage::updateVisiblity(bool linkedCellVisible, bool linkedCellRenderFull, bool linkedCellSelectable, bool otherCellVisible, bool otherCellRenderFull, bool otherCellSelectable)
{
setVisible(linkedCellVisible || otherCellVisible ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE, linkedCellVisible || otherCellVisible ? DCV_VISIBLE_FULL : DCV_VISIBLE_NONE);
// 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.
+ // DCMoveCellCommand() should be used instead.
void registerCell(DCVPageComponent *cell);
void unregisterCell(DCVPageComponent *cell);
// 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.
+ // DCMoveCellCodeClassCommand should be used instead.
void registerCellCodeClass(DCVPageComponent *cellCodeClass);
void unregisterCellCodeClass(DCVPageComponent *cellCodeClass);
void registerEditCursor(DCVPageComponent *ecursor);
void unregisterEditCursor();
+ /**
+ * @brief Move cells and cell codes belong to this page to newPage.
+ * @param newPage : the target page cells and cell codes are moving into.
+ *
+ * This will move cells, cell codes and connections belong to this page to the page passed in the parameter.
+ * This expected to be called from DCContainer.
+ * This shouldn't be called directly.
+ * To change the path / file name for a container file, DCMovePageCommand should be used.
+ *
+ * @return true for succuss, false for failure.
+ */
+ bool moveComponentsTo(DCVCPage *newPage);
+
void updateVisiblity(bool linkedCellVisible, bool linkedCellRenderFull, bool linkedCellSelectable, bool otherCellVisible, bool otherCellRenderFull, bool otherCellSelectable);
virtual void prepareChildrenForDraw(bool isAnimationInterval);
emit modeInitialized();
}
-DCVCPage* DCScene::findPage(const std::string &location)
+DCVCPage* DCScene::getPage(const std::string &location) const
{
DNLocker(getSceneLock());
DCCell* getEditCellCodeCell() const { return d_editCellCodeCell; }
const QMap<QString,DCVCPage*>* getPages() const { return &d_pages; }
+ DCVCPage* getPage(const std::string& location) const;
bool getIsPageExist(const std::string& location) const;
QString getSceneSettingFilePathForPage(DCVCPage *page) const;
QString getSceneSettingFilePathForPage(const QString& containerRootPath, DCVCPage *page) const;
bool doAnimation();
void updateVisiblity();
- DCVCPage* findPage(const std::string& location);
-
DCVCPage* addPage(const std::string& location);
bool removePage(DCVCPage *page);
updateClassInformation();
d_uiClassGroupBox->setVisible(true);
titleString.append("CELL CODE : ");
- titleString.append(QString::fromStdString(cellCodeClass->getName()));
+ titleString.append(QString::fromStdString(cellCodeClass->getFQNName()));
titleString.append(" (");
titleString.append(QString::fromStdString(cellCodeClass->getCellAPIName()));
titleString.append(")");
updateClassInformation();
d_uiClassGroupBox->setVisible(true);
titleString.append("CELL CODE : ");
- titleString.append(QString::fromStdString(d_cellCodeClass->getName()));
+ titleString.append(QString::fromStdString(d_cellCodeClass->getFQNName()));
titleString.append(" (");
titleString.append(QString::fromStdString(d_cellCodeClass->getCellAPIName()));
titleString.append(")");
d_uiSwitchEditorButton->setText(tr("Switch to Custom Script"));
if (d_cellCodeClass && d_cellCodeClass != d_container->getEmptyCellCodeClass() && d_container)
{
- d_editor->setPlainText(d_cellCodeClass->getOwnScript(d_container));
+ d_editor->setPlainText(d_cellCodeClass->getOwnScript());
d_editor->setReadOnly(false);
}
else
{
if (d_cellCodeClass)
{
- d_uiClassName->setText(QString::fromStdString(d_cellCodeClass->getName()));
+ d_uiClassName->setText(QString::fromStdString(d_cellCodeClass->getFQNName()));
d_uiClassType->setText(QString::fromStdString(d_cellCodeClass->getCellAPIName()));
}
else
{
case CELLCLASS_EDIT_MODE:
if (d_cellCodeClass)
- d_cellCodeClass->saveScript(d_container, d_editor->toPlainText());
+ d_cellCodeClass->saveScript(d_editor->toPlainText());
break;
case CUSTOMSCRIPT_EDIT_MODE:
title.append(QString::fromStdString(cell->getName()));
if (cell->getCellCode() && cell->getCellCode() != getController()->getCurrentContainer()->getEmptyCellCodeClass())
{
- d_classButton->setText(QString::fromStdString(cell->getCellCode()->getName()));
+ d_classButton->setText(QString::fromStdString(cell->getCellCode()->getFQNName()));
}
else
{