23 #include <QElapsedTimer>
24 #include <QXmlStreamReader>
27 const QString minimal_supported_version =
"1.6.0";
31 : m_applicationModels(nullptr)
34 , m_messageService(nullptr)
37 setObjectName(
"ProjectDocument");
105 QFile file(project_file_name);
106 if (!file.open(QFile::ReadWrite | QIODevice::Truncate | QFile::Text))
107 throw GUIHelpers::Error(
"ProjectDocument::save_project_file() -> Error. Can't open "
109 + project_file_name +
"' for writing.");
131 QElapsedTimer timer1, timer2;
138 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
139 QString message = QString(
"Open file error '%1'").arg(file.errorString());
157 }
catch (
const std::exception& ex) {
158 QString message = QString(
"Exception thrown '%1'").arg(QString(ex.what()));
214 if (result.isEmpty())
228 QXmlStreamReader reader(device);
230 while (!reader.atEnd()) {
232 if (reader.isStartElement()) {
239 minimal_supported_version)) {
241 QString message = QString(
"Can't open document version '%1', "
242 "minimal supported version '%2'")
244 .arg(minimal_supported_version);
249 while (reader.readNextStartElement())
251 reader.skipCurrentElement();
261 if (reader.hasError()) {
263 QString message = QString(
"Format error '%1'").arg(reader.errorString());
271 QXmlStreamWriter writer(device);
272 writer.setAutoFormatting(
true);
273 writer.writeStartDocument();
280 writer.writeEndElement();
284 writer.writeEndElement();
285 writer.writeEndDocument();
Defines class holding all application models.
#define ASSERT(condition)
Defines class GUIHelpers functions.
Defines MessageService class.
Defines class OutputDataIOService.
Defines ProjectUtils namespace.
void readFrom(class QXmlStreamReader *reader, MessageService *messageService)
void writeTo(class QXmlStreamWriter *writer)
Writes all model in file one by one.
The service to collect messages from different senders.
void send_error(QObject *sender, const QString &description)
int messageCount(const QObject *sender, const QString &message_type="") const
Reports number of messages of given type reported by the sender.
int warningCount(const QObject *sender=0) const
Returns number of warnings for given sender.
Provide read/write of heavy data files in a separate thread.
void load(const QString &projectDir, MessageService *messageService=nullptr)
void setApplicationModels(ApplicationModels *models)
QVector< SaveLoadInterface * > nonXMLItems() const
Returns all non-XML items available for save/load.
void save(const QString &projectDir)
OutputDataIOService * m_dataService
void setApplicationModels(ApplicationModels *applicationModels)
static QString projectFileExtension()
QString projectFileName() const
MessageService * m_messageService
void setProjectDir(const QString &text)
QString documentVersion() const
QString projectName() const
bool hasValidNameAndPath()
void load(const QString &project_file_name)
void readFrom(QIODevice *device)
void setProjectName(const QString &text)
void writeTo(QIODevice *device)
void setLogger(MessageService *messageService)
ApplicationModels * m_applicationModels
ProjectFlags::DocumentStatus m_documentStatus
void save_project_data(const QString &project_file_name)
QString projectDir() const
void setProjectFileName(const QString &text)
ProjectDocument(const QString &projectFileName="")
void save(const QString &project_file_name, bool autoSave=false)
void save_project_file(const QString &project_file_name, bool autoSave=false)
ProjectFlags::DocumentStatus documentStatus() const
void setModified(bool flag)
static void setFlag(ProjectFlags::DocumentStatus &flags, EDocumentStatus status)
QString getBornAgainVersionString()
bool isVersionMatchMinimal(const QString &version, const QString &minimal_version)
returns true if current BornAgain version match minimal required version
const QString InfoTag("DocumentInfo")
const QString InfoNameAttribute("ProjectName")
const QString BornAgainVersionAttribute("Version")
const QString BornAgainTag("BornAgain")
QString projectName(const QString &projectFileName)
Returns project name deduced from project file name.
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.
Defines class ProjectDocument.