mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #618, allow to set file name for saving in views
This commit is contained in:
@@ -101,6 +101,7 @@ namespace BlackGui
|
||||
Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (this->m_modelLoader && this->m_modelLoader->supportsSimulator(simInfo))
|
||||
{
|
||||
this->setSaveFileName(simInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -123,10 +124,18 @@ namespace BlackGui
|
||||
bool c = connect(this->m_modelLoader.get(), &IAircraftModelLoader::loadingFinished, this, &CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect for model loader");
|
||||
Q_UNUSED(c);
|
||||
this->setSaveFileName(simInfo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void CDbOwnModelsComponent::setSaveFileName(const CSimulatorInfo &sim)
|
||||
{
|
||||
Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
const QString n("simulator models " + sim.toQString(true));
|
||||
this->ui->tvp_OwnAircraftModels->setSaveFileName(n);
|
||||
}
|
||||
|
||||
void CDbOwnModelsComponent::CLoadModelsMenu::customMenu(QMenu &menu) const
|
||||
{
|
||||
CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators();
|
||||
|
||||
@@ -82,6 +82,9 @@ namespace BlackGui
|
||||
//! Init model loader
|
||||
bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
|
||||
|
||||
//! File name for savinf
|
||||
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);
|
||||
|
||||
//! The menu for loading and handling own models for mapping tasks
|
||||
//! \note This is specific for that very component
|
||||
class CLoadModelsMenu : public BlackGui::Menus::IMenuDelegate
|
||||
|
||||
@@ -31,7 +31,8 @@ namespace BlackGui
|
||||
ui->setupUi(this);
|
||||
ui->tvp_OwnModelSet->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping);
|
||||
ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh | CAircraftModelView::MenuStashing | CAircraftModelView::MenuBackend | CAircraftModelView::MenuRefresh);
|
||||
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows);
|
||||
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuClear);
|
||||
ui->tvp_OwnModelSet->addFilterDialog();
|
||||
connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
|
||||
connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
|
||||
}
|
||||
@@ -52,6 +53,7 @@ namespace BlackGui
|
||||
this->ui->pb_SaveAsSetForSimulator->setText("save for " + simulator.toQString());
|
||||
this->ui->pb_SaveAsSetForSimulator->setEnabled(!models.isEmpty());
|
||||
this->m_simulator = simulator;
|
||||
this->setSaveFileName(simulator);
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::setMappingComponent(CDbMappingComponent *component)
|
||||
@@ -111,5 +113,12 @@ namespace BlackGui
|
||||
this->ui->tvp_OwnModelSet->showFileLoadDialog();
|
||||
}
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::setSaveFileName(const CSimulatorInfo &sim)
|
||||
{
|
||||
Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
const QString n("modelset" + sim.toQString(true));
|
||||
this->ui->tvp_OwnModelSet->setSaveFileName(n);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -62,6 +62,9 @@ namespace BlackGui
|
||||
void ps_buttonClicked();
|
||||
|
||||
private:
|
||||
//! Default file name
|
||||
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);
|
||||
|
||||
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
|
||||
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulator;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "viewbase.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackgui/models/allmodels.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
@@ -25,7 +26,6 @@
|
||||
#include <QPainter>
|
||||
#include <QShortcut>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
#include <limits>
|
||||
|
||||
@@ -371,29 +371,30 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
QString CViewBaseNonTemplate::getDefaultFilename() const
|
||||
QString CViewBaseNonTemplate::getDefaultFilename(bool load) const
|
||||
{
|
||||
// some logic to find a useful default name
|
||||
const QStringList pathes(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation));
|
||||
QString name;
|
||||
if (this->getDockWidgetInfoArea()) { name = this->getDockWidgetInfoArea()->windowTitle(); }
|
||||
else if (!windowTitle().isEmpty()) { name = this->windowType(); }
|
||||
else { name = this->metaObject()->className(); }
|
||||
name += ".json";
|
||||
QString dir = CProject::getDocumentationDirectory();
|
||||
|
||||
if (!pathes.isEmpty())
|
||||
if (load)
|
||||
{
|
||||
QString p(CFileUtils::appendFilePaths(pathes.first(), "swift/" + name));
|
||||
if (!QDir(p).exists())
|
||||
{
|
||||
p = CFileUtils::appendFilePaths(pathes.first(), "swift " + name);
|
||||
}
|
||||
return p;
|
||||
return CFileUtils::appendFilePaths(dir, CFileUtils::jsonWildcardAppendix());
|
||||
}
|
||||
else
|
||||
|
||||
// Save file path
|
||||
QString name(this->m_saveFileName);
|
||||
if (name.isEmpty())
|
||||
{
|
||||
return name;
|
||||
// create a name
|
||||
if (this->getDockWidgetInfoArea()) { name = this->getDockWidgetInfoArea()->windowTitle(); }
|
||||
else if (!windowTitle().isEmpty()) { name = this->windowType(); }
|
||||
else { name = this->metaObject()->className(); }
|
||||
}
|
||||
if (!name.endsWith(CFileUtils::jsonAppendix(), Qt::CaseInsensitive))
|
||||
{
|
||||
name += CFileUtils::jsonAppendix();
|
||||
}
|
||||
return CFileUtils::appendFilePaths(dir, name);
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::menuRemoveItems(Menu menusToRemove)
|
||||
@@ -959,7 +960,7 @@ namespace BlackGui
|
||||
{
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||
const QString fileName = QFileDialog::getOpenFileName(nullptr,
|
||||
tr("Load data file"), getDefaultFilename(),
|
||||
tr("Load data file"), getDefaultFilename(true),
|
||||
tr("swift (*.json *.txt)"));
|
||||
if (fileName.isEmpty()) { return CStatusMessage(cats, CStatusMessage::SeverityDebug, "Load canceled"); }
|
||||
QString json(CFileUtils::readFileToString(fileName));
|
||||
@@ -978,7 +979,7 @@ namespace BlackGui
|
||||
{
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||
const QString fileName = QFileDialog::getSaveFileName(nullptr,
|
||||
tr("Save data file"), getDefaultFilename(),
|
||||
tr("Save data file"), getDefaultFilename(false),
|
||||
tr("swift (*.json *.txt)"));
|
||||
if (fileName.isEmpty()) { return CStatusMessage(cats, CStatusMessage::SeverityDebug, "Save canceled"); }
|
||||
const QString json(this->toJsonString());
|
||||
|
||||
@@ -203,6 +203,9 @@ namespace BlackGui
|
||||
//! Show file save dialog
|
||||
BlackMisc::CStatusMessage showFileSaveDialog() const;
|
||||
|
||||
//! Save file name (optional)
|
||||
void setSaveFileName(const QString &saveName) { this->m_saveFileName = saveName; }
|
||||
|
||||
signals:
|
||||
//! Ask for new data from currently loaded data
|
||||
void requestUpdate();
|
||||
@@ -305,11 +308,12 @@ namespace BlackGui
|
||||
void init();
|
||||
|
||||
//! Default file for load/save operations
|
||||
QString getDefaultFilename() const;
|
||||
QString getDefaultFilename(bool load) const;
|
||||
|
||||
QString m_saveFileName; //!< save file name (JSON)
|
||||
ResizeMode m_resizeMode = PresizeSubset; //!< mode
|
||||
RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height
|
||||
SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set
|
||||
SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set
|
||||
int m_resizeCount = 0; //!< flag / counter, how many resize activities
|
||||
int m_skipResizeThreshold = 40; //!< when to skip resize (rows count)
|
||||
int m_resizeAutoNthTime = 1; //!< with ResizeAuto, resize every n-th time
|
||||
@@ -322,8 +326,8 @@ namespace BlackGui
|
||||
bool m_displayAutomatically = true; //!< display directly when loaded
|
||||
bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget or dialog
|
||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||
BlackGui::Menus::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
Menu m_menus = MenuDefault; //!< Default menu settings
|
||||
BlackGui::Menus::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded
|
||||
|
||||
protected slots:
|
||||
|
||||
@@ -15,6 +15,18 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
const QString &CFileUtils::jsonAppendix()
|
||||
{
|
||||
static const QString j(".json");
|
||||
return j;
|
||||
}
|
||||
|
||||
const QString &CFileUtils::jsonWildcardAppendix()
|
||||
{
|
||||
static const QString jw("*" + jsonAppendix());
|
||||
return jw;
|
||||
}
|
||||
|
||||
bool CFileUtils::writeStringToFile(const QString &content, const QString &fileNameAndPath)
|
||||
{
|
||||
if (fileNameAndPath.isEmpty()) { return false; }
|
||||
|
||||
@@ -25,6 +25,12 @@ namespace BlackMisc
|
||||
class BLACKMISC_EXPORT CFileUtils
|
||||
{
|
||||
public:
|
||||
//! Our JSON file name appendix
|
||||
static const QString &jsonAppendix();
|
||||
|
||||
//! JSON wildcard + appendix
|
||||
static const QString &jsonWildcardAppendix();
|
||||
|
||||
//! Write string to text file
|
||||
static bool writeStringToFile(const QString &content, const QString &fileNameAndPath);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <QStringList>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#if !defined(BLACK_VERSION)
|
||||
#error Missing version
|
||||
@@ -349,6 +350,22 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
QString getDocumentationDirectoryImpl()
|
||||
{
|
||||
QStringList pathes(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation));
|
||||
QString d = pathes.first();
|
||||
d = CFileUtils::appendFilePaths(d, "/swift");
|
||||
QDir dir(d);
|
||||
if (dir.exists()) { return dir.absolutePath(); }
|
||||
return pathes.first();
|
||||
}
|
||||
|
||||
const QString &CProject::getDocumentationDirectory()
|
||||
{
|
||||
static const QString d(getDocumentationDirectoryImpl());
|
||||
return d;
|
||||
}
|
||||
|
||||
const QString &CProject::compiledWithInfo(bool shortVersion)
|
||||
{
|
||||
if (shortVersion)
|
||||
|
||||
@@ -105,6 +105,9 @@ namespace BlackMisc
|
||||
//! Where images are located
|
||||
static const QString &getImagesDir();
|
||||
|
||||
//! Directory where data can be stored
|
||||
static const QString &getDocumentationDirectory();
|
||||
|
||||
//! Info string about compilation
|
||||
static const QString &compiledWithInfo(bool shortVersion = true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user