You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.6 KiB
93 lines
3.6 KiB
7 years ago
|
#ifndef QTMVVM_SETTINGSSETUPLOADER_P_H
|
||
|
#define QTMVVM_SETTINGSSETUPLOADER_P_H
|
||
|
|
||
|
#include <tuple>
|
||
|
|
||
|
#include <QtCore/QObject>
|
||
|
#include <QtCore/QIODevice>
|
||
|
#include <QtCore/QCache>
|
||
|
#include <QtCore/QXmlStreamReader>
|
||
|
#include <QtCore/QFile>
|
||
|
|
||
7 years ago
|
#include "qtmvvmcore_global.h"
|
||
7 years ago
|
#include "settingssetup.h"
|
||
|
|
||
|
namespace QtMvvm {
|
||
|
|
||
7 years ago
|
class Q_MVVMCORE_EXPORT SettingsSetupLoader : public QObject, public ISettingsSetupLoader
|
||
7 years ago
|
{
|
||
|
Q_OBJECT
|
||
|
Q_INTERFACES(QtMvvm::ISettingsSetupLoader)
|
||
|
|
||
|
public:
|
||
7 years ago
|
Q_INVOKABLE SettingsSetupLoader(QObject *parent = nullptr);
|
||
7 years ago
|
|
||
7 years ago
|
void changeDefaultIcon(const QUrl &defaultIcon) override;
|
||
|
SettingsElements::Setup loadSetup(const QString &filePath, const QString &frontend, const QFileSelector *selector) const final;
|
||
7 years ago
|
|
||
|
bool event(QEvent *event) override;
|
||
7 years ago
|
|
||
|
private:
|
||
7 years ago
|
QUrl _defaultIcon;
|
||
|
mutable QCache<QString, SettingsElements::Setup> _cache;
|
||
7 years ago
|
|
||
7 years ago
|
//Functions to read the settings XML
|
||
7 years ago
|
SettingsElements::Category readCategory(QXmlStreamReader &reader) const;
|
||
|
SettingsElements::Category readDefaultCategory(QXmlStreamReader &reader) const;
|
||
|
void readCategoryChildren(QXmlStreamReader &reader, SettingsElements::Category &category) const;
|
||
7 years ago
|
|
||
7 years ago
|
SettingsElements::Section readSection(QXmlStreamReader &reader) const;
|
||
|
SettingsElements::Section readDefaultSection(QXmlStreamReader &reader) const;
|
||
|
void readSectionChildren(QXmlStreamReader &reader, SettingsElements::Section §ion) const;
|
||
7 years ago
|
|
||
7 years ago
|
SettingsElements::Group readGroup(QXmlStreamReader &reader) const;
|
||
|
SettingsElements::Group readDefaultGroup(QXmlStreamReader &reader) const;
|
||
|
void readGroupChildren(QXmlStreamReader &reader, SettingsElements::Group &group) const;
|
||
7 years ago
|
|
||
7 years ago
|
SettingsElements::Entry readEntry(QXmlStreamReader &reader) const;
|
||
7 years ago
|
|
||
7 years ago
|
SettingsElements::Category createDefaultCategory() const;
|
||
|
SettingsElements::Section createDefaultSection() const;
|
||
7 years ago
|
|
||
|
std::tuple<QString, QVariant> readProperty(QXmlStreamReader &reader) const;
|
||
|
QVariant readElement(QXmlStreamReader &reader) const;
|
||
|
|
||
7 years ago
|
//Functions to read included files
|
||
7 years ago
|
bool readCategoryInclude(QXmlStreamReader &reader, SettingsElements::Category &category) const;
|
||
|
bool readSectionInclude(QXmlStreamReader &reader, SettingsElements::Section §ion) const;
|
||
|
bool readGroupInclude(QXmlStreamReader &reader, SettingsElements::Group &group) const;
|
||
|
bool readEntryInclude(QXmlStreamReader &reader, SettingsElements::Entry &entry) const;
|
||
7 years ago
|
bool readInclude(QXmlStreamReader &reader, const std::function<void(QXmlStreamReader&)> &readFn, const QString &typeName) const;
|
||
|
|
||
7 years ago
|
//Functions to filter the elements
|
||
7 years ago
|
void clearSetup(SettingsElements::Setup &setup, const QString &frontend, const QStringList &selectors) const;
|
||
|
void clearCategory(SettingsElements::Category &category, const QString &frontend, const QStringList &selectors) const;
|
||
|
void clearSection(SettingsElements::Section §ion, const QString &frontend, const QStringList &selectors) const;
|
||
|
void clearGroup(SettingsElements::Group &group, const QString &frontend, const QStringList &selectors) const;
|
||
7 years ago
|
template <typename T>
|
||
|
bool isUsable(const T &configElement, const QString &frontend, const QStringList &selectors) const;
|
||
|
};
|
||
|
|
||
7 years ago
|
class Q_MVVMCORE_EXPORT SettingsXmlException : public SettingsLoaderException
|
||
7 years ago
|
{
|
||
|
public:
|
||
|
SettingsXmlException(const QXmlStreamReader &reader);
|
||
|
SettingsXmlException(QXmlStreamReader &reader, const QByteArray &customError, bool forceOverwrite = false);
|
||
|
SettingsXmlException(const QFile &fileError);
|
||
|
|
||
|
const char *what() const noexcept override;
|
||
|
|
||
|
void raise() const override;
|
||
|
QException *clone() const override;
|
||
|
|
||
|
protected:
|
||
|
SettingsXmlException(const SettingsXmlException * const other);
|
||
|
|
||
|
private:
|
||
|
const QByteArray _what;
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif // QTMVVM_SETTINGSSETUPLOADER_P_H
|