Skip to content
Snippets Groups Projects
Commit 57c07ee5 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

RealModel: delete old files

parent c9354752
No related branches found
No related tags found
1 merge request!1293GUI: simplify save/load machinery
......@@ -49,7 +49,7 @@ JobModel* ApplicationModels::jobModel() const
return m_jobModel.get();
}
void ApplicationModels::writeTo(QXmlStreamWriter* w, const QString& projectDir) const
void ApplicationModels::writeTo(QXmlStreamWriter* w, const QString& projectDir)
{
// real model
w->writeStartElement(Tag::RealModel);
......
......@@ -33,7 +33,7 @@ public:
RealModel* realModel() const;
JobModel* jobModel() const;
void writeTo(QXmlStreamWriter* w, const QString &projectDir) const;
void writeTo(QXmlStreamWriter* w, const QString &projectDir);
void readFrom(QXmlStreamReader* r, const QString& projectDir, MessageService* messageService);
//! Returns all data items
......
......@@ -52,7 +52,7 @@ void RealModel::clear()
removeRealItem(realItem);
}
void RealModel::writeToProject(QXmlStreamWriter* w, const QString& projectDir) const
void RealModel::writeToProject(QXmlStreamWriter* w, const QString& projectDir)
{
XML::writeAttribute(w, XML::Attrib::version, uint(1));
......@@ -63,6 +63,7 @@ void RealModel::writeToProject(QXmlStreamWriter* w, const QString& projectDir) c
realItem->writeTo(w, projectDir);
w->writeEndElement();
}
deleteOldDataFiles(projectDir);
}
void RealModel::readFromProject(QXmlStreamReader* r, const QString& projectDir,
......@@ -155,6 +156,7 @@ QVector<RealItem*> RealModel::realItems2D() const
void RealModel::removeRealItem(RealItem* realItem)
{
ASSERT(realItem);
m_realItemFilesToDelete.append(realItem->dataItem()->fileName());
int index = realItems().indexOf(realItem);
m_realItems.erase(m_realItems.begin() + index);
emit realDataAddedOrRemoved();
......@@ -167,3 +169,10 @@ QStringList RealModel::realItemNames() const
result.append(item->realItemName());
return result;
}
void RealModel::deleteOldDataFiles(const QString& projectDir)
{
for(QString fileName : m_realItemFilesToDelete)
QFile::remove(projectDir + "/" + fileName);
m_realItemFilesToDelete.clear();
}
......@@ -30,7 +30,7 @@ public:
QVector<DataItem*> dataItems() const;
void clear() override;
void writeToProject(QXmlStreamWriter* w, const QString &projectDir) const;
void writeToProject(QXmlStreamWriter* w, const QString &projectDir);
void readFromProject(QXmlStreamReader* r, const QString& projectDir,
MessageService* messageService = nullptr);
......@@ -53,7 +53,10 @@ signals:
void realDataAddedOrRemoved();
private:
void deleteOldDataFiles(const QString& projectDir);
std::vector<std::unique_ptr<RealItem>> m_realItems;
QStringList m_realItemFilesToDelete;
};
#endif // BORNAGAIN_GUI_MODEL_MODEL_REALMODEL_H
......@@ -71,7 +71,7 @@ void DatafieldIOService::saveDataFiles(const QString& projectDir)
// dealing with files
QStringList oldFiles = m_history.savedFileNames(projectDir);
QStringList newFiles = newHistory.savedFileNames();
cleanOldFiles(projectDir, oldFiles, newFiles);
// cleanOldFiles(projectDir, oldFiles, newFiles);
// if oldHistory contained some deleted items, that info will be dropped here
m_history.setHistory(projectDir, newHistory);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment