diff --git a/app/ui/FileDialog/filedialogbackend.cpp b/app/ui/FileDialog/filedialogbackend.cpp index 1c485182..f895055b 100644 --- a/app/ui/FileDialog/filedialogbackend.cpp +++ b/app/ui/FileDialog/filedialogbackend.cpp @@ -11,6 +11,8 @@ Q_LOGGING_CATEGORY(gmFileDialog, "gm.files.dialog") FileDialogBackend::FileDialogBackend(QObject *parent) : QObject(parent) { + setCurrentDir(File::getHomeDir()); + connect(this, &FileDialogBackend::currentDirChanged, &FileDialogBackend::onCurrentDirChanged); } diff --git a/app/ui/FileDialog/filedialogbackend.h b/app/ui/FileDialog/filedialogbackend.h index 7eac45fa..53a7649f 100644 --- a/app/ui/FileDialog/filedialogbackend.h +++ b/app/ui/FileDialog/filedialogbackend.h @@ -38,6 +38,7 @@ public slots: void forward(); void back(); void createFolder(const QString &folderName); + void updateFileList(); signals: void currentDirChanged(const QString &dir); @@ -50,7 +51,6 @@ public slots: QFuture m_currentFuture; - void updateFileList(); void clearFileList(); void stopCurrentRequest(); void clearForward(); diff --git a/app/ui/common/CustomFileDialog.qml b/app/ui/common/CustomFileDialog.qml index 73b97584..9960e81e 100644 --- a/app/ui/common/CustomFileDialog.qml +++ b/app/ui/common/CustomFileDialog.qml @@ -17,22 +17,48 @@ Dialog { modal: true - property alias selectedPath: selection_text_field.text + enum Mode { + OpenOne, + Save + } + + function getSelectedPath() { + if (main_list_view.currentIndex >= 0) { + return backend.getSelected(main_list_view.currentIndex); + } + let result = backend.getSelected(main_list_view.currentIndex); + if (root.mode === CustomFileDialog.Mode.Save) { + result += "/" + selectedEntryName; + } + return result; + } + + property alias selectedEntryName: selection_text_field.text property alias folder: backend.currentDir property alias foldersOnly: backend.folderMode property var textField: undefined property string replacePath: "" + property int mode: CustomFileDialog.Mode.OpenOne FileDialogBackend { id: backend } + onOpened: { + backend.updateFileList(); + if (root.mode === CustomFileDialog.Mode.Save) { + selection_text_field.forceActiveFocus(); + selection_text_field.selectAll(); + } + main_list_view.currentIndex = -1; + } + onAccepted: { if (textField) { if (replacePath) { - textField.text = selection_text_field.text.replace(replacePath, ""); + textField.text = root.getSelectedPath().replace(replacePath, ""); } else { - textField.text = selection_text_field.text; + textField.text = root.getSelectedPath(); } if (textField.savePath) { textField.savePath(); @@ -84,6 +110,8 @@ Dialog { onClicked: { new_folder_form.visible = !new_folder_form.visible; + new_folder_form_row_text_field.forceActiveFocus(); + new_folder_form_row_text_field.selectAll(); } } } @@ -114,6 +142,7 @@ Dialog { } TextField { + id: new_folder_form_row_text_field placeholderText: qsTr("New Folder") height: parent.height anchors.verticalCenter: parent.verticalCenter @@ -147,8 +176,8 @@ Dialog { visible: main_list_view.contentHeight > main_list_view.height } - onCurrentIndexChanged: { - selection_text_field.text = backend.getSelected(currentIndex); + onModelChanged: { + currentIndex = -1; } model: backend.entries @@ -197,8 +226,25 @@ Dialog { id: delegate_mouse_area anchors.fill: delegate_item hoverEnabled: true - onClicked: main_list_view.currentIndex = delegate_item.index - onDoubleClicked: backend.enterFolder(delegate_item.index) + + onClicked: { + main_list_view.currentIndex = delegate_item.index; + if (root.mode === CustomFileDialog.Mode.Save) { + selection_text_field.text = delegate_item.modelData.name; + } + } + + onDoubleClicked: { + if (delegate_item.modelData.isFolder) { + backend.enterFolder(delegate_item.index); + return; + } + main_list_view.currentIndex = delegate_item.index; + if (root.mode === CustomFileDialog.Mode.Save) { + selection_text_field.text = delegate_item.modelData.name; + } + root.accept(); + } } } @@ -219,6 +265,12 @@ Dialog { anchors.left: parent.left anchors.right: buttons.left anchors.margins: 5 + + visible: root.mode === CustomFileDialog.Mode.Save + + onAccepted: { + root.accept(); + } } Row { @@ -231,7 +283,7 @@ Dialog { Button { id: open_button - text: qsTr("Open") + text: root.mode === CustomFileDialog.Mode.Save ? qsTr("Save") : qsTr("Open") anchors.top: parent.top anchors.bottom: parent.bottom diff --git a/app/ui/tools/CombatTracker.qml b/app/ui/tools/CombatTracker.qml index 773ab6ed..697c696f 100644 --- a/app/ui/tools/CombatTracker.qml +++ b/app/ui/tools/CombatTracker.qml @@ -4,6 +4,7 @@ import CustomComponents import IconFonts import src import ".." +import "../common" import "./combat_tracker" Page { @@ -14,6 +15,23 @@ Page { Component.onCompleted: CombatTrackerTool.loadData() + CustomFileDialog { + id: file_dialog + + onAccepted: { + switch (file_dialog.mode) { + case CustomFileDialog.Mode.OpenOne: + CombatTrackerTool.loadFile(file_dialog.getSelectedPath()); + break; + case CustomFileDialog.Mode.Save: + CombatTrackerTool.saveFile(file_dialog.getSelectedPath()); + break; + default: + break; + } + } + } + // Top Bar header: ToolBar { id: top_bar @@ -36,7 +54,28 @@ Page { buttonText: qsTr("Add") usesFixedWidth: false onClicked: { - add_rect.visible = !add_rect.visible + add_rect.visible = !add_rect.visible; + } + } + + CustomToolBarButton { + iconText: FontAwesome.fileArrowUp + buttonText: qsTr("Load") + usesFixedWidth: false + onClicked: { + file_dialog.mode = CustomFileDialog.Mode.OpenOne; + file_dialog.open(); + } + } + + CustomToolBarButton { + iconText: FontAwesome.fileArrowDown + buttonText: qsTr("Save") + usesFixedWidth: false + onClicked: { + file_dialog.mode = CustomFileDialog.Mode.Save; + file_dialog.selectedEntryName = "combat-state.json"; + file_dialog.open(); } } diff --git a/app/ui/tools/audio/editor/views/EditorFileListView.qml b/app/ui/tools/audio/editor/views/EditorFileListView.qml index 6d3ec37f..0d39f709 100644 --- a/app/ui/tools/audio/editor/views/EditorFileListView.qml +++ b/app/ui/tools/audio/editor/views/EditorFileListView.qml @@ -17,7 +17,7 @@ Item { foldersOnly: true onAccepted: { - AudioTool.editor.replaceFileFolder(index, selectedPath); + AudioTool.editor.replaceFileFolder(index, getSelectedPath()); } } diff --git a/src/filesystem/file.cpp b/src/filesystem/file.cpp index f32ee37d..0b6cda94 100755 --- a/src/filesystem/file.cpp +++ b/src/filesystem/file.cpp @@ -85,6 +85,12 @@ auto File::checkAsync(const QStringList &paths, Options options, std::shared_ptr return access ? access->checkAsync(paths, options) : QFuture(); } +auto File::getHomeDir(std::shared_ptr fileAccess) -> QString +{ + auto access = getFileAccess(fileAccess); + return access ? access->getHomeDir() : u"/"_s; +} + void File::updateFileAccess() { const auto cloudMode = SettingsManager::instance()->get(u"cloudMode"_s, u"local"_s); diff --git a/src/filesystem/file.h b/src/filesystem/file.h index 87bb6c90..eb077319 100755 --- a/src/filesystem/file.h +++ b/src/filesystem/file.h @@ -58,6 +58,8 @@ class File static auto checkAsync(const QStringList &paths, Options options = Option::AllowCache, std::shared_ptr fileAccess = nullptr) -> QFuture; + static auto getHomeDir(std::shared_ptr fileAccess = nullptr) -> QString; + static void updateFileAccess(); private: diff --git a/src/filesystem/fileaccess.h b/src/filesystem/fileaccess.h index c98b9016..6be0c6a9 100755 --- a/src/filesystem/fileaccess.h +++ b/src/filesystem/fileaccess.h @@ -31,6 +31,7 @@ class FileAccess virtual auto createDirAsync(const QString &path) -> QFuture = 0; virtual auto checkAsync(const QString &path, Options options) -> QFuture = 0; virtual auto checkAsync(const QStringList &paths, Options options) -> QFuture = 0; + virtual auto getHomeDir() -> QString = 0; static auto getInstance() -> std::shared_ptr { diff --git a/src/filesystem/fileaccesslocal.cpp b/src/filesystem/fileaccesslocal.cpp index f3b31a41..9c6d8cca 100755 --- a/src/filesystem/fileaccesslocal.cpp +++ b/src/filesystem/fileaccesslocal.cpp @@ -280,13 +280,18 @@ auto FileAccessLocal::checkAsync(const QStringList &paths, Options options) -> Q .then(&m_context, [](FileMultiCheckResult &&result) { return std::move(result); }); } +auto FileAccessLocal::getHomeDir() -> QString +{ + return QDir::homePath(); +} + auto FileAccessLocal::getDirFilter(bool files, bool folders) -> QFlags { - if (files && folders) return QDir::NoDotAndDotDot | QDir::AllEntries; + if (files && folders) return QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden; - if (files) return QDir::NoDotAndDotDot | QDir::Files; + if (files) return QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden; - if (folders) return QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Drives; + if (folders) return QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Drives | QDir::Hidden; return QDir::NoDotAndDotDot; } diff --git a/src/filesystem/fileaccesslocal.h b/src/filesystem/fileaccesslocal.h index 50802046..d8ed708c 100755 --- a/src/filesystem/fileaccesslocal.h +++ b/src/filesystem/fileaccesslocal.h @@ -24,6 +24,7 @@ class FileAccessLocal : public FileAccess auto createDirAsync(const QString &path) -> QFuture override; auto checkAsync(const QString &path, Options options) -> QFuture override; auto checkAsync(const QStringList &paths, Options options) -> QFuture override; + auto getHomeDir() -> QString override; private: static auto getData(const QString &path) -> FileDataResult; diff --git a/src/filesystem/fileaccessnextcloud.cpp b/src/filesystem/fileaccessnextcloud.cpp index 977d396d..72740898 100644 --- a/src/filesystem/fileaccessnextcloud.cpp +++ b/src/filesystem/fileaccessnextcloud.cpp @@ -318,6 +318,11 @@ auto FileAccessNextcloud::checkAsync(const QStringList &paths, Options options) return FileAccess::multiCheckAsync(MultiGetHelper(paths), options); } +auto FileAccessNextcloud::getHomeDir() -> QString +{ + return u"/"_s; +} + auto FileAccessNextcloud::encodePath(const QString &data) -> QByteArray { return QUrl::toPercentEncoding(data, "/"); diff --git a/src/filesystem/fileaccessnextcloud.h b/src/filesystem/fileaccessnextcloud.h index 48d10b5e..d117696f 100644 --- a/src/filesystem/fileaccessnextcloud.h +++ b/src/filesystem/fileaccessnextcloud.h @@ -25,6 +25,7 @@ class FileAccessNextcloud : public FileAccess auto createDirAsync(const QString &path) -> QFuture override; auto checkAsync(const QString &path, Options options) -> QFuture override; auto checkAsync(const QStringList &paths, Options options) -> QFuture override; + auto getHomeDir() -> QString override; private: Services::NextCloud &m_nc; diff --git a/src/tools/combat_tracker/combattracker.cpp b/src/tools/combat_tracker/combattracker.cpp index 72ac4575..55831374 100644 --- a/src/tools/combat_tracker/combattracker.cpp +++ b/src/tools/combat_tracker/combattracker.cpp @@ -1,4 +1,6 @@ #include "combattracker.h" +#include "filesystem/file.h" +#include "filesystem/results/filedataresult.h" #include "utils/fileutils.h" #include "utils/utils.h" #include @@ -10,6 +12,7 @@ #include using namespace Qt::Literals::StringLiterals; +using namespace Files; Q_LOGGING_CATEGORY(gmCombatTracker, "gm.combat.tracker") @@ -32,7 +35,7 @@ void CombatTracker::reset() { sortByIni(false); m_state.reset(); - saveToDisk(); + saveToTempFile(); } /** @@ -44,7 +47,7 @@ void CombatTracker::clear(bool saveAfterClear) if (saveAfterClear) { - saveToDisk(); + saveToTempFile(); } } @@ -64,7 +67,7 @@ void CombatTracker::next() } qCDebug(gmCombatTracker()) << "New index:" << currentIndex(); - saveToDisk(); + saveToTempFile(); } /** @@ -88,7 +91,7 @@ auto CombatTracker::add(const QString &name, int ini, int health, int priority, m_state.currentIndex(0); } - saveToDisk(); + saveToTempFile(); return true; } @@ -97,7 +100,7 @@ auto CombatTracker::add(const QString &name, int ini, int health, int priority, sortByIni(); } - saveToDisk(); + saveToTempFile(); return false; } @@ -110,7 +113,7 @@ auto CombatTracker::remove(int index) -> bool if (Q_UNLIKELY(!Utils::isInBounds(combatants(), index))) return false; m_state.removeCombatant(index); - saveToDisk(); + saveToTempFile(); return true; } @@ -141,7 +144,7 @@ auto CombatTracker::setIni(Combatant *combatant, int ini) -> bool combatant->ini(ini); sortByIni(true); - saveToDisk(); + saveToTempFile(); return true; } @@ -180,7 +183,7 @@ auto CombatTracker::setHealth(int index, int health) -> bool if (Q_UNLIKELY(!combatant)) return false; combatant->health(health); - saveToDisk(); + saveToTempFile(); return true; } @@ -197,7 +200,7 @@ auto CombatTracker::modifyHealth(int index, int steps) -> bool auto health = combatant->health(); health += steps; combatant->health(health); - saveToDisk(); + saveToTempFile(); return true; } @@ -209,7 +212,7 @@ auto CombatTracker::setPriority(Combatant *combatant, int priority) -> bool combatant->priority(priority); sortByIni(true); - saveToDisk(); + saveToTempFile(); return true; } @@ -240,7 +243,7 @@ auto CombatTracker::setNotes(int index, const QString ¬es) -> bool if (Q_UNLIKELY(!combatant)) return false; combatant->notes(notes); - saveToDisk(); + saveToTempFile(); return true; } @@ -252,7 +255,7 @@ auto CombatTracker::delayTurn(int index) -> bool combatant->delay(true); m_state.moveCombatantToBack(index); - saveToDisk(); + saveToTempFile(); return true; } @@ -265,7 +268,7 @@ auto CombatTracker::getCombatant(int index) -> Combatant * { if (Q_LIKELY(Utils::isInBounds(combatants(), index))) { - return combatants()[index]; + return combatants().at(index); } return nullptr; @@ -278,7 +281,7 @@ void CombatTracker::resetDelayForAll() const if (Q_LIKELY(combatant)) combatant->delay(false); } - saveToDisk(); + saveToTempFile(); } void CombatTracker::loadData() @@ -297,7 +300,29 @@ void CombatTracker::loadData() setIsDataLoaded(true); } -void CombatTracker::saveToDisk() const +auto CombatTracker::loadFile(const QString &file) -> QFuture +{ + return File::getDataAsync(file).then([this](const FileDataResult &result) { + if (!result.success()) + { + qCWarning(gmCombatTracker()) << "Could not load file:" << result.errorMessage(); + return; + } + + const auto json = QJsonDocument::fromJson(result.data()); + m_state.load(json); + + setIsDataLoaded(true); + }); +} + +auto CombatTracker::saveFile(const QString &file) -> QFuture +{ + const auto data = m_state.serialize().toJson(); + return File::saveAsync(file, data); +} + +void CombatTracker::saveToTempFile() const { auto json = m_state.serialize(); auto tempFile = getCacheFile(); diff --git a/src/tools/combat_tracker/combattracker.h b/src/tools/combat_tracker/combattracker.h index d44af813..b4fa5e39 100644 --- a/src/tools/combat_tracker/combattracker.h +++ b/src/tools/combat_tracker/combattracker.h @@ -1,9 +1,9 @@ -#ifndef COMBATTRACKER_H -#define COMBATTRACKER_H +#pragma once #include "abstracttool.h" #include "combatant.h" #include "combattrackerstate.h" +#include "filesystem/results/fileresult.h" #include #include #include @@ -62,6 +62,9 @@ class CombatTracker : public AbstractTool Q_INVOKABLE void sortByIni(bool keepDelay = false); Q_INVOKABLE bool delayTurn(int index); + Q_INVOKABLE QFuture loadFile(const QString &file); + Q_INVOKABLE QFuture saveFile(const QString &file); + public slots: void loadData() override; @@ -74,12 +77,10 @@ public slots: [[nodiscard]] auto getCombatant(int index) -> Combatant *; void resetDelayForAll() const; - void saveToDisk() const; + void saveToTempFile() const; static auto getCacheFile() -> QFile; private: CombatTrackerState m_state; }; - -#endif // COMBATTRACKER_H diff --git a/tests/filesystem/abstractaccesstest.cpp b/tests/filesystem/abstractaccesstest.cpp index f0219dfc..98d04dfe 100644 --- a/tests/filesystem/abstractaccesstest.cpp +++ b/tests/filesystem/abstractaccesstest.cpp @@ -34,6 +34,7 @@ void AbstractAccessTest::createTestFiles() createTestFile(u"test5"_s, "To be moved."); createTestFile(u"test6"_s, "To be deleted."); createTestFile(u"test7"_s, "To be copied."); + createTestFile(u".test8"_s, "This is test 8."); #ifndef Q_OS_WIN // windows can't handle filenames with special characters @@ -262,6 +263,8 @@ void AbstractAccessTest::listAsync() EXPECT_GT(future.result().files().length(), 2) << "Could not list files."; EXPECT_TRUE(future.result().files().contains("test1")) << "List does not include test file 1."; EXPECT_TRUE(future.result().files().contains("test2")) << "List does not include test file 2."; + EXPECT_TRUE(future.result().files().contains(".test8")) + << "List does not include test file 8 that starts with a dot."; #ifndef Q_OS_WIN EXPECT_TRUE(future.result().files().contains("file&with\"special characters")) << "List does not include file with special characters in it's name."; diff --git a/tests/filesystem/testfiledialog.cpp b/tests/filesystem/testfiledialog.cpp index 71715344..151ae39d 100644 --- a/tests/filesystem/testfiledialog.cpp +++ b/tests/filesystem/testfiledialog.cpp @@ -1,7 +1,9 @@ #include "app/ui/FileDialog/filedialogbackend.h" #include "app/ui/FileDialog/fileobject.h" +#include "src/common/settings/settingsmanager.h" #include "src/filesystem/file.h" #include "src/filesystem/fileaccess.h" +#include "tests/testhelper/staticabstracttest.h" #include #include #include @@ -9,6 +11,7 @@ #include using namespace Files; +using namespace Common::Settings; using namespace Qt::Literals::StringLiterals; class FileDialogTest : public ::testing::Test @@ -16,23 +19,24 @@ class FileDialogTest : public ::testing::Test public: FileDialogTest() { + cloudMode = SettingsManager::instance()->get(u"cloudMode"_s, u"local"_s); + File::init(nullptr); + createTestFiles(); dialog = std::make_unique(nullptr); } - ~FileDialogTest() + ~FileDialogTest() override { tempDir.remove(); + + SettingsManager::instance()->set(u"cloudMode"_s, cloudMode); } protected: - void enterAndGetTopLevel(); - void enterTopLevelFoldersOnly(); - void moveThroughStructure(); - -private: QTemporaryDir tempDir; std::unique_ptr dialog = nullptr; + std::shared_ptr fileAccess = nullptr; static constexpr int WAIT_TIME_MS = 1000; const QStringList topLevelFiles = {"file1", "file2", "file3", "file4"}; @@ -59,18 +63,21 @@ class FileDialogTest : public ::testing::Test void goBack(const QString &dir, bool canGoForward, bool canGoBack, const QStringList &expectedFiles, const QStringList &expectedFolders); + +private: + QString cloudMode; }; void FileDialogTest::createFile(const QString &file) { auto future = File::saveAsync(tempDir.filePath(file), QByteArray()); - future.waitForFinished(); + StaticAbstractTest::testFutureNoAuth(future, "saveAsync", []() {}); } void FileDialogTest::createDir(const QString &directory) { auto future = File::createDirAsync(tempDir.filePath(directory)); - future.waitForFinished(); + StaticAbstractTest::testFutureNoAuth(future, "createDir", []() {}); } void FileDialogTest::createTestFiles() @@ -183,19 +190,19 @@ void FileDialogTest::goBack(const QString &dir, bool canGoForward, bool canGoBac enterDir(enter, dir, canGoForward, canGoBack, expectedFiles, expectedFolders); } -void FileDialogTest::enterAndGetTopLevel() +TEST_F(FileDialogTest, CanEnterAndGetTopLevel) { dialog->folderMode(false); enterDir(tempDir.path(), false, true, topLevelFiles, topLevelFolders); } -void FileDialogTest::enterTopLevelFoldersOnly() +TEST_F(FileDialogTest, CanEnterTopLevelFoldersOnly) { dialog->folderMode(true); enterDir(tempDir.path(), false, true, {}, topLevelFolders); } -void FileDialogTest::moveThroughStructure() +TEST_F(FileDialogTest, MoveThroughStructure) { dialog->folderMode(false); enterDir(tempDir.path(), false, true, topLevelFiles, topLevelFolders); diff --git a/tests/filesystem/testlocalaccess.cpp b/tests/filesystem/testlocalaccess.cpp index dc344601..1556f406 100755 --- a/tests/filesystem/testlocalaccess.cpp +++ b/tests/filesystem/testlocalaccess.cpp @@ -1,4 +1,5 @@ #include "abstractaccesstest.h" +#include "src/filesystem/file.h" #include "src/filesystem/fileaccesslocal.h" #include @@ -28,3 +29,9 @@ TEST_F(LocalAccessTest, TestFileAccess) { runAllTests(); } + +TEST_F(LocalAccessTest, VerifyHomeDir) +{ + const auto homeDir = File::getHomeDir(fileAccess); + EXPECT_FALSE(homeDir.isEmpty()); +} diff --git a/tests/filesystem/testnextcloudaccess.cpp b/tests/filesystem/testnextcloudaccess.cpp index 0971d2ce..392cd397 100644 --- a/tests/filesystem/testnextcloudaccess.cpp +++ b/tests/filesystem/testnextcloudaccess.cpp @@ -1,6 +1,7 @@ #include "abstractaccesstest.h" #include "mocknextcloud.h" #include "settings/settingsmanager.h" +#include "src/filesystem/file.h" #include "src/filesystem/fileaccessnextcloud.h" #include "src/services/nextcloud/nextcloud.h" #include @@ -86,3 +87,9 @@ TEST_F(NextcloudAccessTest, TestFileAccess) { runAllTests(); } + +TEST_F(NextcloudAccessTest, VerifyHomeDir) +{ + const auto homeDir = File::getHomeDir(fileAccess); + EXPECT_EQ(homeDir.toStdString(), "/"); +} diff --git a/tests/tools/testcombattracker.cpp b/tests/tools/testcombattracker.cpp index c96ce5b0..06bdbc83 100644 --- a/tests/tools/testcombattracker.cpp +++ b/tests/tools/testcombattracker.cpp @@ -1,4 +1,6 @@ +#include "src/filesystem/results/fileresult.h" #include "src/tools/combat_tracker/combattracker.h" +#include "tests/testhelper/staticabstracttest.h" #include using namespace Qt::Literals::StringLiterals; @@ -28,9 +30,9 @@ class CombatTrackerTest : public ::testing::Test return combatTracker.combatants(); } - static void saveToDisk(AccessibleCombatTracker &combatTracker) + static void saveToTempFile(AccessibleCombatTracker &combatTracker) { - combatTracker.saveToDisk(); + combatTracker.saveToTempFile(); } static void resetDelayForAll(AccessibleCombatTracker &combatTracker) @@ -186,7 +188,7 @@ TEST_F(CombatTrackerTest, CanRemoveSecondLastAndActiveCombatant) EXPECT_EQ(combatTracker.model()->rowCount(QModelIndex()), 4); } -TEST_F(CombatTrackerTest, TestSaveLoad) +TEST_F(CombatTrackerTest, TestSaveLoadToTempFile) { AccessibleCombatTracker combatTracker(nullptr); createTestData(combatTracker); @@ -202,7 +204,7 @@ TEST_F(CombatTrackerTest, TestSaveLoad) const auto priority = combatant->priority(); const auto delay = combatant->delay(); - saveToDisk(combatTracker); + saveToTempFile(combatTracker); combatTracker.clear(false); EXPECT_EQ(combatTracker.currentIndex(), 0); @@ -224,6 +226,27 @@ TEST_F(CombatTrackerTest, TestSaveLoad) EXPECT_EQ(loadedCombatant->delay(), delay); } +TEST_F(CombatTrackerTest, TestSaveLoadToFile) +{ + AccessibleCombatTracker combatTracker(nullptr); + createTestData(combatTracker); + + QTemporaryFile file; + file.open(); + file.close(); + + auto future = combatTracker.saveFile(file.fileName()); + StaticAbstractTest::testFutureNoAuth(future, "saveFile", [future]() { EXPECT_TRUE(future.result().success()); }); + + combatTracker.clear(false); + + EXPECT_EQ(combatTracker.model()->rowCount(QModelIndex()), 0); + + auto future2 = combatTracker.loadFile(file.fileName()); + StaticAbstractTest::testFutureNoAuth(future2, "loadFile", []() {}); + EXPECT_GT(combatTracker.model()->rowCount(QModelIndex()), 0); +} + TEST_F(CombatTrackerTest, CanAccessModel) { AccessibleCombatTracker combatTracker(nullptr);