BinEditor: Proliferate FilePath use

Change-Id: I1676ab03257b5acdc1f67e25f419939939707d53
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-08-25 09:19:38 +02:00
parent df939e15dd
commit 101fda5997
3 changed files with 15 additions and 14 deletions

View File

@@ -234,7 +234,7 @@ public:
{ {
QTC_ASSERT(!autoSave, return true); // bineditor does not support autosave - it would be a bit expensive QTC_ASSERT(!autoSave, return true); // bineditor does not support autosave - it would be a bit expensive
const FilePath &fileNameToUse = filePath.isEmpty() ? this->filePath() : filePath; const FilePath &fileNameToUse = filePath.isEmpty() ? this->filePath() : filePath;
if (m_widget->save(errorString, this->filePath().toString(), fileNameToUse.toString())) { if (m_widget->save(errorString, this->filePath(), fileNameToUse)) {
setFilePath(fileNameToUse); setFilePath(fileNameToUse);
return true; return true;
} }

View File

@@ -60,6 +60,7 @@
#include <QWheelEvent> #include <QWheelEvent>
using namespace Core; using namespace Core;
using namespace Utils;
namespace BinEditor { namespace BinEditor {
namespace Internal { namespace Internal {
@@ -402,25 +403,25 @@ bool BinEditorWidget::isReadOnly() const
return m_readOnly; return m_readOnly;
} }
bool BinEditorWidget::save(QString *errorString, const QString &oldFileName, const QString &newFileName) bool BinEditorWidget::save(QString *errorString, const FilePath &oldFilePath, const FilePath &newFilePath)
{ {
if (oldFileName != newFileName) { if (oldFilePath != newFilePath) {
QString tmpName; FilePath tmpName;
{ {
QTemporaryFile tmp(newFileName + QLatin1String("_XXXXXX.new")); QTemporaryFile tmp(newFilePath.toString() + QLatin1String("_XXXXXX.new"));
if (!tmp.open()) if (!tmp.open())
return false; return false;
tmpName = tmp.fileName(); tmpName = FilePath::fromString(tmp.fileName());
} }
if (!QFile::copy(oldFileName, tmpName)) if (!oldFilePath.copyFile(tmpName))
return false; return false;
if (QFile::exists(newFileName) && !QFile::remove(newFileName)) if (newFilePath.exists() && !newFilePath.removeFile())
return false; return false;
if (!QFile::rename(tmpName, newFileName)) if (!tmpName.renameFile(newFilePath))
return false; return false;
} }
Utils::FileSaver saver(Utils::FilePath::fromString(newFileName),
QIODevice::ReadWrite); // QtBug: WriteOnly truncates. FileSaver saver(newFilePath, QIODevice::ReadWrite); // QtBug: WriteOnly truncates.
if (!saver.hasError()) { if (!saver.hasError()) {
QFile *output = saver.file(); QFile *output = saver.file();
const qint64 size = output->size(); const qint64 size = output->size();

View File

@@ -29,15 +29,15 @@
#include "markup.h" #include "markup.h"
#include "bineditorservice.h" #include "bineditorservice.h"
#include <utils/filepath.h>
#include <utils/optional.h> #include <utils/optional.h>
#include <QAbstractScrollArea>
#include <QBasicTimer> #include <QBasicTimer>
#include <QMap> #include <QMap>
#include <QSet> #include <QSet>
#include <QStack> #include <QStack>
#include <QString> #include <QString>
#include <QAbstractScrollArea>
#include <QTextDocument> #include <QTextDocument>
#include <QTextFormat> #include <QTextFormat>
@@ -78,7 +78,7 @@ public:
bool newWindowRequestAllowed() const { return m_canRequestNewWindow; } bool newWindowRequestAllowed() const { return m_canRequestNewWindow; }
void updateContents(); void updateContents();
bool save(QString *errorString, const QString &oldFileName, const QString &newFileName); bool save(QString *errorString, const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath);
void zoomF(float delta); void zoomF(float delta);