}
}
-bool DCContainer::isScriptableCell(DCCell *cell)
+bool DCContainer::isScriptableCell(DCCell *cell) const
{
bool noScript = false;
bool DCContainer::saveCustomScriptToWorkFile(const DCCell *cell, std::string customScript)
{
- QDir workdir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
- if (!workdir.exists())
+ QFile workfile(getWorkFilePathForCustomScript(cell));
+ QFileInfo fileInfo(workfile);
+ if (!fileInfo.absoluteDir().exists())
{
- workdir.mkpath(workdir.absolutePath());
+ QDir dir;
+ dir.mkpath(fileInfo.absolutePath());
}
- QFile workfile(workdir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+
workfile.open(QIODevice::WriteOnly);
QTextStream out(&workfile);
out << QString::fromStdString(customScript);
bool DCContainer::saveClassScriptToWorkFile(const DCCellCode *cellCode, std::string code)
{
QString qNamePath = QString::fromStdString(cellCode->getFQNName());
- QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
QString name = DCUtil::getNameFromFQNPath(qNamePath);
if (name.length() == 0)
return false;
- QDir workdir(d_workDirCellCodeRoot + path);
- if (!workdir.exists())
+ QFile workfile(getWorkFilePathForCellCode(cellCode));
+ QFileInfo fileInfo(workfile);
+ if (!fileInfo.absoluteDir().exists())
{
- workdir.mkpath(workdir.absolutePath());
+ QDir dir;
+ dir.mkpath(fileInfo.absolutePath());
}
- QFile workfile(workdir.absoluteFilePath(name + ".js"));
workfile.open(QIODevice::WriteOnly);
QTextStream out(&workfile);
out << QString::fromStdString(code);
QString DCContainer::readCustomScriptFromWorkFile(const DCCell *cell)
{
- QFile file(d_workDirCellRoot + QString::fromStdString(cell->getLocation()) + "/" + QString::fromStdString(cell->getName()) + ".js");
+ QFile file(getWorkFilePathForCustomScript(cell));
if (!file.exists())
{
QString DCContainer::readCellCodeScriptFromFile(const DCCellCode *cellCode)
{
QString qNamePath = QString::fromStdString(cellCode->getFQNName());
- QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
QString name = DCUtil::getNameFromFQNPath(qNamePath);
if (name.length() == 0)
return false;
- QFile file(d_workDirCellCodeRoot + path + "/" + name + ".js");
+ QFile file(getWorkFilePathForCellCode(cellCode));
if (!file.exists())
{
return "";
return true;
QString customScript = readCustomScriptFromWorkFile(cell);
- QDir workDir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
- QFile workFileOld(workDir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+ QFile workFileOld(getWorkFilePathForCustomScript(cell));
cell->changeName(newName);
if (!saveCustomScriptToWorkFile(cell, customScript.toStdString()))
return true;
QString customScript = readCustomScriptFromWorkFile(cell);
- QDir workDirOld(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
- QFile workFileOld(workDirOld.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js"));
+ QFile workFileOld(getWorkFilePathForCustomScript(cell));
cell->changePath(pageNewContainerBasedPathName);
if (!saveCustomScriptToWorkFile(cell, customScript.toStdString()))
if (oldName == newName)
return true;
- QFile oldFile(d_workDirCellCodeRoot + oldPath + "/" + oldName + ".js");
+ QFile oldFile(getWorkFilePathForCellCode(cellcode));
QString script = readCellCodeScriptFromFile(cellcode);
cellcode->changeName(newName);
if (oldPath == pageNewContainerBasedPathName)
return true;
- QFile oldFile(d_workDirCellCodeRoot + oldPath + "/" + oldName + ".js");
+ QFile oldFile(getWorkFilePathForCellCode(cellcode));
QString script = readCellCodeScriptFromFile(cellcode);
cellcode->changePath(pageNewContainerBasedPathName);
return false;
}
+QString DCContainer::getWorkFilePathForCustomScript(const DCCell *cell) const
+{
+ QDir workdir(d_workDirCellRoot + QString::fromStdString(cell->getLocation()));
+ return workdir.absoluteFilePath(QString::fromStdString(cell->getName()) + ".js");
+}
+
+QString DCContainer::getWorkFilePathForCellCode(const DCCellCode *cellCode) const
+{
+ QString qNamePath = QString::fromStdString(cellCode->getFQNName());
+ QString path = DCUtil::getContainerBasedPathFromFQNPath(qNamePath);
+ QString name = DCUtil::getNameFromFQNPath(qNamePath);
+
+ QDir workdir(d_workDirCellCodeRoot + path);
+ return workdir.absoluteFilePath(name + ".js");
+}
DCContainer();
virtual ~DCContainer();
- bool getIsModified() const;
+ bool getIsModified() const;
+
+ DCContent* getContent() const { return d_content; }
+ DCScene* getScene() const { return d_scene; }
+ QList<DCVComponent*> getSelectedCellObjects() const;
+ virtual float getValue(std::string key) const { Q_UNUSED(key); return 0; }
+
+ TKCellCode* getEmptyCellCodeClass() const { return mEmptyCellClass; }
+ bool isScriptableCell(DCCell *cell) const;
+
+ QString getWorkFilePathForCustomScript(const DCCell *cell) const;
+ QString getWorkFilePathForCellCode(const DCCellCode *cellcode) const;
virtual TKCell* addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
bool renameCellCodeClass(DCCellCode *cellcode, const QString& newName);
- //
- DCContent* getContent() const { return d_content; }
- DCScene* getScene() const { return d_scene; }
- QList<DCVComponent*> getSelectedCellObjects() const;
- virtual float getValue(std::string key) const { Q_UNUSED(key); return 0; }
-
- TKCellCode* getEmptyCellCodeClass() const { return mEmptyCellClass; }
- bool isScriptableCell(DCCell *cell);
-
- //
void setContent(DCContent *content);
void unselectCellObjectAll();
QString readCustomScriptFromWorkFile(const DCCell *cell);
QString readCellCodeScriptFromFile(const DCCellCode *cellcode);
-
/***************************************************************************
* Cell type rules
**************************************************************************/