mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Ref T306, remember directories value class
This commit is contained in:
104
src/blackmisc/directories.cpp
Normal file
104
src/blackmisc/directories.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Copyright (C) 2018
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/directories.h"
|
||||
#include "directoryutils.h"
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
QString CDirectories::getFlightPlanDirectoryOrDefault() const
|
||||
{
|
||||
return this->existingOrDefaultDir(this->getFlightPlanDirectory(), CDirectoryUtils::documentationDirectory());
|
||||
}
|
||||
|
||||
QString CDirectories::getLastViewJsonDirectoryOrDefault() const
|
||||
{
|
||||
return this->existingOrDefaultDir(this->getLastViewJsonDirectory(), CDirectoryUtils::documentationDirectory());
|
||||
}
|
||||
|
||||
QString CDirectories::getLastModelDirectoryOrDefault() const
|
||||
{
|
||||
return this->existingOrDefaultDir(this->getLastModelDirectory(), this->getLastViewJsonDirectoryOrDefault());
|
||||
}
|
||||
|
||||
void CDirectories::setLastModelDirectory(const QString &dir)
|
||||
{
|
||||
m_dirLastModelJson = dir;
|
||||
if (this->hasLastViewJsonDirectory()) { return; }
|
||||
this->setLastViewJsonDirectory(dir);
|
||||
}
|
||||
|
||||
QString CDirectories::getLastModelStashDirectoryOrDefault() const
|
||||
{
|
||||
return this->existingOrDefaultDir(this->getLastModelStashDirectory(), this->getLastModelDirectoryOrDefault());
|
||||
}
|
||||
|
||||
void CDirectories::setLastModelStashDirectory(const QString &dir)
|
||||
{
|
||||
m_dirLastModelStashJson = dir;
|
||||
if (this->hasLastModelDirectory()) { return; }
|
||||
this->setLastModelDirectory(dir);
|
||||
}
|
||||
|
||||
QString CDirectories::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return m_dirFlightPlan;
|
||||
}
|
||||
|
||||
CVariant CDirectories::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDirFlightPlan: return CVariant::fromValue(m_dirFlightPlan);
|
||||
case IndexDirFlightPlanOrDefault: return CVariant::fromValue(this->getFlightPlanDirectoryOrDefault());
|
||||
case IndexDirLastViewJson: return CVariant::fromValue(m_dirLastViewJson);
|
||||
case IndexDirLastViewJsonOrDefault: return CVariant::fromValue(this->getLastViewJsonDirectoryOrDefault());
|
||||
case IndexDirLastModelJson: return CVariant::fromValue(m_dirLastModelStashJson);
|
||||
case IndexDirLastModelJsonOrDefault: return CVariant::fromValue(this->getLastModelDirectoryOrDefault());
|
||||
case IndexDirLastModelStashJson: return CVariant::fromValue(m_dirLastModelStashJson);
|
||||
case IndexDirLastModelStashJsonOrDefault: return CVariant::fromValue(this->getLastModelStashDirectoryOrDefault());
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CDirectories::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CDirectories>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDirFlightPlan: this->setFlightPlanDirectory(variant.toQString()); break;
|
||||
case IndexDirLastViewJsonOrDefault:
|
||||
case IndexDirLastViewJson: this->setLastViewJsonDirectory(variant.toQString()); break;
|
||||
case IndexDirLastModelJsonOrDefault:
|
||||
case IndexDirLastModelJson: this->setLastModelDirectory(variant.toQString()); break;
|
||||
case IndexDirLastModelStashJsonOrDefault:
|
||||
case IndexDirLastModelStashJson: this->setLastModelStashDirectory(variant.toQString()); break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CDirectories::fileNameToDirectory(const QString &fileName)
|
||||
{
|
||||
const QFileInfo fi(fileName);
|
||||
return fi.dir().absolutePath();
|
||||
}
|
||||
|
||||
QString CDirectories::existingOrDefaultDir(const QString &checkDir, const QString &defaultDir) const
|
||||
{
|
||||
const QDir d(checkDir);
|
||||
if (d.exists()) { return checkDir; }
|
||||
return defaultDir;
|
||||
}
|
||||
} // namespace
|
||||
135
src/blackmisc/directories.h
Normal file
135
src/blackmisc/directories.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* Copyright (C) 2018
|
||||
* Swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_DIRECTORIES_H
|
||||
#define BLACKMISC_DIRECTORIES_H
|
||||
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* Directories (swift data directories)
|
||||
* \remark the main purpose of this class is to serve as setting's value object
|
||||
*/
|
||||
class BLACKMISC_EXPORT CDirectories : public CValueObject<CDirectories>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDirFlightPlan = CPropertyIndex::GlobalIndexCDirectories,
|
||||
IndexDirFlightPlanOrDefault,
|
||||
IndexDirLastViewJson,
|
||||
IndexDirLastViewJsonOrDefault,
|
||||
IndexDirLastModelJson,
|
||||
IndexDirLastModelJsonOrDefault,
|
||||
IndexDirLastModelStashJson,
|
||||
IndexDirLastModelStashJsonOrDefault
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
CDirectories() {}
|
||||
|
||||
//! Flight plan directory
|
||||
const QString &getFlightPlanDirectory() const { return m_dirFlightPlan; }
|
||||
|
||||
//! Flight plan directory or default
|
||||
QString getFlightPlanDirectoryOrDefault() const;
|
||||
|
||||
//! Flight plan directory
|
||||
void setFlightPlanDirectory(const QString &dir) { m_dirFlightPlan = dir; }
|
||||
|
||||
//! Last view JSON directory
|
||||
const QString &getLastViewJsonDirectory() const { return m_dirLastViewJson; }
|
||||
|
||||
//! Has a view JSON directory?
|
||||
bool hasLastViewJsonDirectory() const { return !m_dirLastViewJson.isEmpty(); }
|
||||
|
||||
//! Last view JSON directory or default
|
||||
QString getLastViewJsonDirectoryOrDefault() const;
|
||||
|
||||
//! Last view JSON directory (default if not more specific)
|
||||
void setLastViewJsonDirectory(const QString &dir) { m_dirLastViewJson = dir; }
|
||||
|
||||
//! Last view JSON model stash directory
|
||||
const QString &getLastModelDirectory() const { return m_dirLastModelJson; }
|
||||
|
||||
//! Last view JSON model directory or default
|
||||
QString getLastModelDirectoryOrDefault() const;
|
||||
|
||||
//! Last view JSON model directory
|
||||
void setLastModelDirectory(const QString &dir);
|
||||
|
||||
//! Has a model JSON directory?
|
||||
bool hasLastModelDirectory() const { return !m_dirLastModelJson.isEmpty(); }
|
||||
|
||||
//! Last view JSON model directory
|
||||
const QString &getLastModelStashDirectory() const { return m_dirLastModelStashJson; }
|
||||
|
||||
//! Last view JSON model stash directory or default
|
||||
QString getLastModelStashDirectoryOrDefault() const;
|
||||
|
||||
//! Last view JSON model stash directory
|
||||
void setLastModelStashDirectory(const QString &dir);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! Convert to directory
|
||||
static QString fileNameToDirectory(const QString &fileName);
|
||||
|
||||
private:
|
||||
QString m_dirFlightPlan; //!< directory for flight plans
|
||||
QString m_dirLastViewJson; //!< last JSON save directory
|
||||
QString m_dirLastModelJson; //!< last JSON model directory
|
||||
QString m_dirLastModelStashJson; //!< last JSON model stash save directory
|
||||
|
||||
//! Return checkDir if existing, defaultDir otherwise
|
||||
QString existingOrDefaultDir(const QString &checkDir, const QString &defaultDir) const;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CDirectories,
|
||||
BLACK_METAMEMBER(dirFlightPlan),
|
||||
BLACK_METAMEMBER(dirLastViewJson),
|
||||
BLACK_METAMEMBER(dirLastModelJson),
|
||||
BLACK_METAMEMBER(dirLastModelStashJson)
|
||||
);
|
||||
};
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
//! ATC stations settings
|
||||
struct TDirectorySettings : public TSettingTrait<CDirectories>
|
||||
{
|
||||
//! \copydoc BlackCore::TSettingTrait::key
|
||||
static const char *key() { return "swiftdirectories"; }
|
||||
|
||||
//! \copydoc BlackCore::TSettingTrait::humanReadable
|
||||
static const QString &humanReadable() { static const QString name("swift directories"); return name; }
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::CDirectories)
|
||||
|
||||
#endif // guard
|
||||
@@ -88,6 +88,7 @@ namespace BlackMisc
|
||||
GlobalIndexCCountry = 900,
|
||||
GlobalIndexCPlatform = 1000,
|
||||
GlobalIndexCApplicationInfo = 1100,
|
||||
GlobalIndexCDirectories = 1200,
|
||||
GlobalIndexCCallsign = 2000,
|
||||
GlobalIndexCAircraftSituation = 2100,
|
||||
GlobalIndexCAircraftSituationChange = 2200,
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
#include "blackmisc/input/registermetadatainput.h"
|
||||
#include "blackmisc/geo/registermetadatageo.h"
|
||||
#include "blackmisc/pq/registermetadatapq.h"
|
||||
|
||||
#include "blackmisc/applicationinfolist.h"
|
||||
#include "blackmisc/countrylist.h"
|
||||
#include "blackmisc/dbus.h"
|
||||
#include "blackmisc/directories.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/identifierlist.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
@@ -59,6 +61,7 @@ namespace BlackMisc
|
||||
CApplicationInfoList::registerMetadata();
|
||||
CCountry::registerMetadata();
|
||||
CCountryList::registerMetadata();
|
||||
CDirectories::registerMetadata();
|
||||
CIcon::registerMetadata();
|
||||
CIconList::registerMetadata();
|
||||
CIdentifier::registerMetadata();
|
||||
@@ -78,7 +81,6 @@ namespace BlackMisc
|
||||
CPropertyIndexVariantMap::registerMetadata();
|
||||
CRgbColor::registerMetadata();
|
||||
CStatusMessage::registerMetadata();
|
||||
qDBusRegisterMetaType<CStatusMessage::StatusSeverity>();
|
||||
CStatusMessageList::registerMetadata();
|
||||
CValueCachePacket::registerMetadata();
|
||||
CVariant::registerMetadata();
|
||||
|
||||
@@ -294,7 +294,8 @@ namespace BlackMisc
|
||||
void CStatusMessage::registerMetadata()
|
||||
{
|
||||
CValueObject<CStatusMessage>::registerMetadata();
|
||||
qRegisterMetaType<StatusSeverity>();
|
||||
qRegisterMetaType<CStatusMessage::StatusSeverity>();
|
||||
qDBusRegisterMetaType<CStatusMessage::StatusSeverity>();
|
||||
}
|
||||
|
||||
CStatusMessage::StatusSeverity CStatusMessage::stringToSeverity(const QString &severity)
|
||||
|
||||
Reference in New Issue
Block a user