Use QSaveFile class for saving a layout.
This commit is contained in:
parent
742c1c3eb3
commit
b638be5b2e
|
@ -32,6 +32,7 @@
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QSvgGenerator>
|
#include <QSvgGenerator>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QSaveFile>
|
||||||
|
|
||||||
#include "ui_vpmainwindow.h"
|
#include "ui_vpmainwindow.h"
|
||||||
#include "dialogs/vpdialogabout.h"
|
#include "dialogs/vpdialogabout.h"
|
||||||
|
@ -268,21 +269,33 @@ void VPMainWindow::SetCurrentFile(const QString &fileName)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VPMainWindow::SaveLayout(const QString &path, QString &error) -> bool
|
auto VPMainWindow::SaveLayout(const QString &path, QString &error) -> bool
|
||||||
{
|
{
|
||||||
QFile file(path);
|
bool success = false;
|
||||||
file.open(QIODevice::WriteOnly);
|
QSaveFile file(path);
|
||||||
|
// cppcheck-suppress ConfigurationNotChecked
|
||||||
VPLayoutFileWriter fileWriter;
|
if (file.open(QIODevice::WriteOnly))
|
||||||
fileWriter.WriteFile(m_layout, &file);
|
|
||||||
|
|
||||||
if (fileWriter.hasError())
|
|
||||||
{
|
{
|
||||||
error = tr("Fail to create layout.");
|
VPLayoutFileWriter fileWriter;
|
||||||
return false;
|
fileWriter.WriteFile(m_layout, &file);
|
||||||
|
|
||||||
|
if (fileWriter.hasError())
|
||||||
|
{
|
||||||
|
error = tr("Fail to create layout.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
success = file.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCurrentFile(path);
|
if (success)
|
||||||
LayoutWasSaved(true);
|
{
|
||||||
return true;
|
SetCurrentFile(path);
|
||||||
|
LayoutWasSaved(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = file.errorString();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -137,7 +137,7 @@ auto GrainlineArrowDirrectionToString(GrainlineArrowDirection type) -> QString
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPLayoutFileWriter::WriteFile(VPLayout *layout, QFile *file)
|
void VPLayoutFileWriter::WriteFile(VPLayout *layout, QIODevice *file)
|
||||||
{
|
{
|
||||||
setDevice(file);
|
setDevice(file);
|
||||||
setAutoFormatting(true);
|
setAutoFormatting(true);
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
VPLayoutFileWriter()= default;
|
VPLayoutFileWriter()= default;
|
||||||
~VPLayoutFileWriter()= default;
|
~VPLayoutFileWriter()= default;
|
||||||
|
|
||||||
void WriteFile(VPLayout *layout, QFile *file);
|
void WriteFile(VPLayout *layout, QIODevice *file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteLayout(VPLayout *layout);
|
void WriteLayout(VPLayout *layout);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user