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