Init measurements database.
This commit is contained in:
parent
b145a25abf
commit
856e472587
|
@ -34,19 +34,24 @@
|
||||||
#include "../ifc/exception/vexceptionobjecterror.h"
|
#include "../ifc/exception/vexceptionobjecterror.h"
|
||||||
#include "../ifc/exception/vexceptionwrongid.h"
|
#include "../ifc/exception/vexceptionwrongid.h"
|
||||||
#include "../qmuparser/qmuparsererror.h"
|
#include "../qmuparser/qmuparsererror.h"
|
||||||
|
#include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h"
|
||||||
#include "../vganalytics/def.h"
|
#include "../vganalytics/def.h"
|
||||||
#include "../vganalytics/vganalytics.h"
|
#include "../vganalytics/vganalytics.h"
|
||||||
#include "../vmisc/projectversion.h"
|
#include "../vmisc/projectversion.h"
|
||||||
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
||||||
#include "../vmisc/theme/vtheme.h"
|
#include "../vmisc/theme/vtheme.h"
|
||||||
#include "../vmisc/vsysexits.h"
|
#include "../vmisc/vsysexits.h"
|
||||||
|
#include "qtpreprocessorsupport.h"
|
||||||
#include "tmainwindow.h"
|
#include "tmainwindow.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "vtapeshortcutmanager.h"
|
#include "vtapeshortcutmanager.h"
|
||||||
|
|
||||||
|
#include "QtConcurrent/qtconcurrentrun.h"
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QFuture>
|
||||||
#include <QGlobalStatic>
|
#include <QGlobalStatic>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
|
@ -578,6 +583,7 @@ void MApplication::OpenSettings()
|
||||||
settings = new VTapeSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(),
|
settings = new VTapeSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(),
|
||||||
QCoreApplication::applicationName(), this);
|
QCoreApplication::applicationName(), this);
|
||||||
connect(settings, &VTapeSettings::SVGFontsPathChanged, this, &MApplication::SVGFontsPathChanged);
|
connect(settings, &VTapeSettings::SVGFontsPathChanged, this, &MApplication::SVGFontsPathChanged);
|
||||||
|
connect(settings, &VTapeSettings::KnownMeasurementsPathChanged, this, &MApplication::KnownMeasurementsPathChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -725,6 +731,36 @@ auto MApplication::VApp() -> MApplication *
|
||||||
return qobject_cast<MApplication *>(QCoreApplication::instance());
|
return qobject_cast<MApplication *>(QCoreApplication::instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto MApplication::KnownMeasurementsDatabase() -> VKnownMeasurementsDatabase *
|
||||||
|
{
|
||||||
|
if (m_knownMeasurementsDatabase == nullptr)
|
||||||
|
{
|
||||||
|
m_knownMeasurementsDatabase = new VKnownMeasurementsDatabase();
|
||||||
|
|
||||||
|
RestartKnownMeasurementsDatabaseWatcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_knownMeasurementsDatabase->IsPopulated())
|
||||||
|
{
|
||||||
|
m_knownMeasurementsDatabase->PopulateMeasurementsDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_knownMeasurementsDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::RestartKnownMeasurementsDatabaseWatcher()
|
||||||
|
{
|
||||||
|
if (m_knownMeasurementsDatabase != nullptr)
|
||||||
|
{
|
||||||
|
delete m_knownMeasurementsDatabaseWatcher;
|
||||||
|
m_knownMeasurementsDatabaseWatcher = new QFileSystemWatcher({settings->GetPathKnownMeasurements()}, this);
|
||||||
|
connect(m_knownMeasurementsDatabaseWatcher, &QFileSystemWatcher::directoryChanged, this,
|
||||||
|
&MApplication::RepopulateMeasurementsDatabase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto MApplication::NewMainWindow() -> TMainWindow *
|
auto MApplication::NewMainWindow() -> TMainWindow *
|
||||||
{
|
{
|
||||||
|
@ -773,6 +809,30 @@ void MApplication::NewLocalSocketConnection()
|
||||||
MainWindow()->activateWindow();
|
MainWindow()->activateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::RepopulateMeasurementsDatabase(const QString &path)
|
||||||
|
{
|
||||||
|
Q_UNUSED(path)
|
||||||
|
if (m_knownMeasurementsDatabase != nullptr)
|
||||||
|
{
|
||||||
|
QFuture<void> future =
|
||||||
|
QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath)
|
||||||
|
{
|
||||||
|
if (oldPath != newPath)
|
||||||
|
{
|
||||||
|
if (m_knownMeasurementsDatabase != nullptr)
|
||||||
|
{
|
||||||
|
RestartKnownMeasurementsDatabaseWatcher();
|
||||||
|
RepopulateMeasurementsDatabase(newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MApplication::Clean()
|
void MApplication::Clean()
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
class TMainWindow;
|
class TMainWindow;
|
||||||
class QLocalServer;
|
class QLocalServer;
|
||||||
class QCommandLineParser;
|
class QCommandLineParser;
|
||||||
|
class VKnownMeasurementsDatabase;
|
||||||
|
|
||||||
enum class SocketConnection : bool
|
enum class SocketConnection : bool
|
||||||
{
|
{
|
||||||
|
@ -77,6 +78,9 @@ public:
|
||||||
|
|
||||||
static auto VApp() -> MApplication *;
|
static auto VApp() -> MApplication *;
|
||||||
|
|
||||||
|
auto KnownMeasurementsDatabase() -> VKnownMeasurementsDatabase *;
|
||||||
|
void RestartKnownMeasurementsDatabaseWatcher();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ProcessCMD();
|
void ProcessCMD();
|
||||||
|
|
||||||
|
@ -89,6 +93,8 @@ protected slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void NewLocalSocketConnection();
|
void NewLocalSocketConnection();
|
||||||
|
void RepopulateMeasurementsDatabase(const QString &path);
|
||||||
|
void KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// cppcheck-suppress unknownMacro
|
// cppcheck-suppress unknownMacro
|
||||||
|
@ -98,6 +104,8 @@ private:
|
||||||
VTranslateVars *m_trVars{nullptr};
|
VTranslateVars *m_trVars{nullptr};
|
||||||
QPointer<DialogMDataBase> m_dataBase{};
|
QPointer<DialogMDataBase> m_dataBase{};
|
||||||
bool m_testMode{false};
|
bool m_testMode{false};
|
||||||
|
VKnownMeasurementsDatabase *m_knownMeasurementsDatabase{nullptr};
|
||||||
|
QFileSystemWatcher *m_knownMeasurementsDatabaseWatcher{nullptr};
|
||||||
|
|
||||||
void Clean();
|
void Clean();
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "../mainwindow.h"
|
#include "../mainwindow.h"
|
||||||
#include "../qmuparser/qmuparsererror.h"
|
#include "../qmuparser/qmuparsererror.h"
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
#include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h"
|
||||||
#include "../vganalytics/def.h"
|
#include "../vganalytics/def.h"
|
||||||
#include "../vganalytics/vganalytics.h"
|
#include "../vganalytics/vganalytics.h"
|
||||||
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
||||||
|
@ -48,9 +49,12 @@
|
||||||
#include "../vmisc/backport/text.h"
|
#include "../vmisc/backport/text.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "QtConcurrent/qtconcurrentrun.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QFuture>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
@ -784,6 +788,36 @@ auto VApplication::LogFile() -> QTextStream *
|
||||||
return m_out.get();
|
return m_out.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VApplication::KnownMeasurementsDatabase() -> VKnownMeasurementsDatabase *
|
||||||
|
{
|
||||||
|
if (m_knownMeasurementsDatabase == nullptr)
|
||||||
|
{
|
||||||
|
m_knownMeasurementsDatabase = new VKnownMeasurementsDatabase();
|
||||||
|
|
||||||
|
RestartKnownMeasurementsDatabaseWatcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_knownMeasurementsDatabase->IsPopulated())
|
||||||
|
{
|
||||||
|
m_knownMeasurementsDatabase->PopulateMeasurementsDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_knownMeasurementsDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::RestartKnownMeasurementsDatabaseWatcher()
|
||||||
|
{
|
||||||
|
if (m_knownMeasurementsDatabase != nullptr)
|
||||||
|
{
|
||||||
|
delete m_knownMeasurementsDatabaseWatcher;
|
||||||
|
m_knownMeasurementsDatabaseWatcher = new QFileSystemWatcher({settings->GetPathKnownMeasurements()}, this);
|
||||||
|
connect(m_knownMeasurementsDatabaseWatcher, &QFileSystemWatcher::directoryChanged, this,
|
||||||
|
&VApplication::RepopulateMeasurementsDatabase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VApplication::TrVars() -> const VTranslateVars *
|
auto VApplication::TrVars() -> const VTranslateVars *
|
||||||
{
|
{
|
||||||
|
@ -850,6 +884,30 @@ void VApplication::AboutToQuit()
|
||||||
Settings()->sync();
|
Settings()->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::RepopulateMeasurementsDatabase(const QString &path)
|
||||||
|
{
|
||||||
|
Q_UNUSED(path)
|
||||||
|
if (m_knownMeasurementsDatabase != nullptr)
|
||||||
|
{
|
||||||
|
QFuture<void> future =
|
||||||
|
QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath)
|
||||||
|
{
|
||||||
|
if (oldPath != newPath)
|
||||||
|
{
|
||||||
|
if (m_knownMeasurementsDatabase != nullptr)
|
||||||
|
{
|
||||||
|
RestartKnownMeasurementsDatabaseWatcher();
|
||||||
|
RepopulateMeasurementsDatabase(newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VApplication::IsGUIMode() -> bool
|
auto VApplication::IsGUIMode() -> bool
|
||||||
{
|
{
|
||||||
|
@ -871,6 +929,14 @@ auto VApplication::IsPedantic() const -> bool
|
||||||
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsPedantic();
|
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsPedantic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::OpenSettings()
|
||||||
|
{
|
||||||
|
VAbstractValApplication::OpenSettings();
|
||||||
|
connect(settings, &VValentinaSettings::KnownMeasurementsPathChanged, this,
|
||||||
|
&VApplication::KnownMeasurementsPathChanged);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VApplication::VApp() -> VApplication *
|
auto VApplication::VApp() -> VApplication *
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "vcmdexport.h"
|
#include "vcmdexport.h"
|
||||||
|
|
||||||
class VApplication; // use in define
|
class VApplication; // use in define
|
||||||
|
class VKnownMeasurementsDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VApplication class reimplamentation QApplication class.
|
* @brief The VApplication class reimplamentation QApplication class.
|
||||||
|
@ -65,12 +66,17 @@ public:
|
||||||
void StartLogging();
|
void StartLogging();
|
||||||
auto LogFile() -> QTextStream *;
|
auto LogFile() -> QTextStream *;
|
||||||
|
|
||||||
|
auto KnownMeasurementsDatabase() -> VKnownMeasurementsDatabase *;
|
||||||
|
void RestartKnownMeasurementsDatabaseWatcher();
|
||||||
|
|
||||||
auto TrVars() -> const VTranslateVars * override;
|
auto TrVars() -> const VTranslateVars * override;
|
||||||
|
|
||||||
auto static IsGUIMode() -> bool;
|
auto static IsGUIMode() -> bool;
|
||||||
auto IsAppInGUIMode() const -> bool override;
|
auto IsAppInGUIMode() const -> bool override;
|
||||||
auto IsPedantic() const -> bool override;
|
auto IsPedantic() const -> bool override;
|
||||||
|
|
||||||
|
void OpenSettings() override;
|
||||||
|
|
||||||
static auto VApp() -> VApplication *;
|
static auto VApp() -> VApplication *;
|
||||||
static auto CommandLine() -> VCommandLinePtr;
|
static auto CommandLine() -> VCommandLinePtr;
|
||||||
|
|
||||||
|
@ -80,6 +86,8 @@ protected:
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void AboutToQuit() override;
|
void AboutToQuit() override;
|
||||||
|
void RepopulateMeasurementsDatabase(const QString &path);
|
||||||
|
void KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// cppcheck-suppress unknownMacro
|
// cppcheck-suppress unknownMacro
|
||||||
|
@ -90,6 +98,9 @@ private:
|
||||||
QSharedPointer<VLockGuard<QFile>> m_lockLog{};
|
QSharedPointer<VLockGuard<QFile>> m_lockLog{};
|
||||||
std::shared_ptr<QTextStream> m_out{nullptr};
|
std::shared_ptr<QTextStream> m_out{nullptr};
|
||||||
|
|
||||||
|
VKnownMeasurementsDatabase *m_knownMeasurementsDatabase{nullptr};
|
||||||
|
QFileSystemWatcher *m_knownMeasurementsDatabaseWatcher{nullptr};
|
||||||
|
|
||||||
static auto LogDirPath() -> QString;
|
static auto LogDirPath() -> QString;
|
||||||
static auto LogPath() -> QString;
|
static auto LogPath() -> QString;
|
||||||
static auto CreateLogDir() -> bool;
|
static auto CreateLogDir() -> bool;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#ifndef VKNOWNMEASUREMENTS_H
|
#ifndef VKNOWNMEASUREMENTS_H
|
||||||
#define VKNOWNMEASUREMENTS_H
|
#define VKNOWNMEASUREMENTS_H
|
||||||
|
|
||||||
#include "xml/vpatternimage.h"
|
#include "../ifc/xml/vpatternimage.h"
|
||||||
#include <QSharedDataPointer>
|
#include <QSharedDataPointer>
|
||||||
#include <QTypeInfo>
|
#include <QTypeInfo>
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,12 @@
|
||||||
#ifndef VKNOWNMEASUREMENTSDATABASE_H
|
#ifndef VKNOWNMEASUREMENTSDATABASE_H
|
||||||
#define VKNOWNMEASUREMENTSDATABASE_H
|
#define VKNOWNMEASUREMENTSDATABASE_H
|
||||||
|
|
||||||
|
#include "vknownmeasurements.h"
|
||||||
#include <QCache>
|
#include <QCache>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
class VKnownMeasurements;
|
|
||||||
|
|
||||||
struct VKnownMeasurementsHeader
|
struct VKnownMeasurementsHeader
|
||||||
{
|
{
|
||||||
QUuid uid{};
|
QUuid uid{};
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
|
|
||||||
#include "vabstractapplication.h"
|
#include "vabstractapplication.h"
|
||||||
|
|
||||||
|
#include "QtConcurrent/qtconcurrentrun.h"
|
||||||
|
#include "compatibility.h"
|
||||||
|
#include "svgfont/vsvgfontdatabase.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
|
@ -40,10 +43,6 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#include "QtConcurrent/qtconcurrentrun.h"
|
|
||||||
#include "compatibility.h"
|
|
||||||
#include "svgfont/vsvgfontdatabase.h"
|
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
#include "literals.h"
|
#include "literals.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -350,9 +350,11 @@ auto VCommonSettings::GetPathSVGFonts() const -> QString
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VCommonSettings::SetPathSVGFonts(const QString &value)
|
void VCommonSettings::SetPathSVGFonts(const QString &value)
|
||||||
{
|
{
|
||||||
const QString oldPath = GetDefPathSVGFonts();
|
const QString oldPath = GetPathSVGFonts();
|
||||||
|
|
||||||
setValue(*settingPathsSVGFonts, value);
|
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
|
||||||
|
settings.setValue(*settingPathsSVGFonts, value);
|
||||||
|
settings.sync();
|
||||||
|
|
||||||
if (oldPath != value)
|
if (oldPath != value)
|
||||||
{
|
{
|
||||||
|
@ -397,9 +399,16 @@ auto VCommonSettings::GetPathKnownMeasurements() const -> QString
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VCommonSettings::SetPathKnownMeasurements(const QString &value)
|
void VCommonSettings::SetPathKnownMeasurements(const QString &value)
|
||||||
{
|
{
|
||||||
|
const QString oldPath = GetPathKnownMeasurements();
|
||||||
|
|
||||||
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
|
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
|
||||||
settings.setValue(*settingPathsKnownMeasurements, value);
|
settings.setValue(*settingPathsKnownMeasurements, value);
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
|
||||||
|
if (oldPath != value)
|
||||||
|
{
|
||||||
|
emit KnownMeasurementsPathChanged(oldPath, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -344,6 +344,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SVGFontsPathChanged(const QString &oldPath, const QString &newPath);
|
void SVGFontsPathChanged(const QString &oldPath, const QString &newPath);
|
||||||
|
void KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user