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
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);
return true;
}

View File

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

View File

@@ -29,15 +29,15 @@
#include "markup.h"
#include "bineditorservice.h"
#include <utils/filepath.h>
#include <utils/optional.h>
#include <QAbstractScrollArea>
#include <QBasicTimer>
#include <QMap>
#include <QSet>
#include <QStack>
#include <QString>
#include <QAbstractScrollArea>
#include <QTextDocument>
#include <QTextFormat>
@@ -78,7 +78,7 @@ public:
bool newWindowRequestAllowed() const { return m_canRequestNewWindow; }
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);