Browse Source

general code cleanups

pull/2/head
Skycoder42 7 years ago
parent
commit
c61d86e7b2
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 2
      .qmake.conf
  2. 2
      src/imports/mvvmcore/mvvmcore.pro
  3. 10
      src/imports/mvvmcore/qqmlmvvmmessage.cpp
  4. 2
      src/imports/mvvmdatasynccore/mvvmdatasynccore.pro
  5. 2
      src/imports/mvvmdatasyncquick/mvvmdatasyncquick.pro
  6. 2
      src/imports/mvvmquick/androidfilechooser.cpp
  7. 2
      src/imports/mvvmquick/androidfilechooser.h
  8. 2
      src/imports/mvvmquick/multifilterproxymodel.cpp
  9. 5
      src/imports/mvvmquick/qqmlquickpresenter.cpp
  10. 4
      src/imports/mvvmquick/qqmlquickpresenter.h
  11. 14
      src/imports/mvvmquick/settingsentrymodel.cpp
  12. 2
      src/imports/mvvmquick/settingsentrymodel.h
  13. 16
      src/imports/mvvmquick/settingssectionmodel.cpp
  14. 2
      src/imports/mvvmquick/settingssectionmodel.h
  15. 24
      src/imports/mvvmquick/settingsuibuilder.cpp
  16. 8
      src/imports/mvvmquick/settingsuibuilder.h
  17. 18
      src/mvvmcore/binding.cpp
  18. 12
      src/mvvmcore/binding_p.h
  19. 2
      src/mvvmcore/coreapp.cpp
  20. 2
      src/mvvmcore/coreapp.h
  21. 2
      src/mvvmcore/ipresenter.h
  22. 55
      src/mvvmcore/message.cpp
  23. 8
      src/mvvmcore/message.h
  24. 4
      src/mvvmcore/message_p.h
  25. 18
      src/mvvmcore/qtmvvmcore_helpertypes.h
  26. 16
      src/mvvmcore/serviceregistry.cpp
  27. 12
      src/mvvmcore/serviceregistry.h
  28. 5
      src/mvvmcore/serviceregistry_p.h
  29. 2
      src/mvvmcore/settingssetup.h
  30. 23
      src/mvvmcore/settingssetuploader.cpp
  31. 2
      src/mvvmcore/settingssetuploader_p.h
  32. 2
      src/mvvmcore/settingsviewmodel.cpp
  33. 2
      src/mvvmcore/settingsviewmodel.h
  34. 12
      src/mvvmcore/viewmodel.cpp
  35. 16
      src/mvvmcore/viewmodel.h
  36. 6
      src/mvvmcore/viewmodel_p.h
  37. 2
      src/mvvmdatasynccore/accountmodel.cpp
  38. 2
      src/mvvmdatasynccore/accountmodel.h
  39. 12
      src/mvvmdatasynccore/changeremoteviewmodel.cpp
  40. 8
      src/mvvmdatasynccore/changeremoteviewmodel_p.h
  41. 34
      src/mvvmdatasynccore/datasyncviewmodel.cpp
  42. 4
      src/mvvmdatasynccore/datasyncviewmodel.h
  43. 4
      src/mvvmdatasynccore/datasyncviewmodel_p.h
  44. 7
      src/mvvmdatasynccore/exchangedevicesmodel.cpp
  45. 2
      src/mvvmdatasynccore/exchangedevicesmodel.h
  46. 8
      src/mvvmdatasynccore/exportsetupviewmodel.cpp
  47. 4
      src/mvvmdatasynccore/exportsetupviewmodel_p.h
  48. 7
      src/mvvmdatasynccore/identityeditviewmodel.cpp
  49. 4
      src/mvvmdatasynccore/identityeditviewmodel_p.h
  50. 22
      src/mvvmdatasynccore/networkexchangeviewmodel.cpp
  51. 2
      src/mvvmdatasynccore/networkexchangeviewmodel.h
  52. 6
      src/mvvmdatasynccore/networkexchangeviewmodel_p.h
  53. 2
      src/mvvmdatasyncwidgets/changeremotedialog.cpp
  54. 2
      src/mvvmdatasyncwidgets/changeremotedialog_p.h
  55. 2
      src/mvvmdatasyncwidgets/datasyncwindow.cpp
  56. 2
      src/mvvmdatasyncwidgets/datasyncwindow.h
  57. 2
      src/mvvmdatasyncwidgets/exportsetupdialog.cpp
  58. 2
      src/mvvmdatasyncwidgets/exportsetupdialog_p.h
  59. 2
      src/mvvmdatasyncwidgets/identityeditdialog.cpp
  60. 2
      src/mvvmdatasyncwidgets/identityeditdialog_p.h
  61. 4
      src/mvvmdatasyncwidgets/networkexchangewindow.cpp
  62. 2
      src/mvvmdatasyncwidgets/networkexchangewindow.h
  63. 2
      src/mvvmquick/inputviewfactory.cpp
  64. 2
      src/mvvmquick/inputviewfactory.h
  65. 13
      src/mvvmquick/quickpresenter.cpp
  66. 2
      src/mvvmquick/quickpresenter.h
  67. 6
      src/mvvmquick/quickpresenter_p.h
  68. 2
      src/mvvmwidgets/inputwidgetfactory.cpp
  69. 2
      src/mvvmwidgets/inputwidgetfactory.h
  70. 2
      src/mvvmwidgets/ipresentingview.h
  71. 2
      src/mvvmwidgets/selectcombobox.cpp
  72. 2
      src/mvvmwidgets/selectcombobox_p.h
  73. 30
      src/mvvmwidgets/settingsdialog.cpp
  74. 2
      src/mvvmwidgets/settingsdialog.h
  75. 14
      src/mvvmwidgets/settingsdialog_p.h
  76. 18
      src/mvvmwidgets/widgetspresenter.cpp
  77. 2
      src/mvvmwidgets/widgetspresenter.h
  78. 4
      src/mvvmwidgets/widgetspresenter_p.h

2
.qmake.conf

@ -7,6 +7,6 @@ DEFINES += QT_DEPRECATED_WARNINGS QT_ASCII_CAST_WARNINGS
MODULE_VERSION_MAJOR = 1 MODULE_VERSION_MAJOR = 1
MODULE_VERSION_MINOR = 0 MODULE_VERSION_MINOR = 0
MODULE_VERSION_PATCH = 0 MODULE_VERSION_PATCH = 2
MODULE_VERSION_IMPORT = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR} MODULE_VERSION_IMPORT = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}
MODULE_VERSION = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}.$${MODULE_VERSION_PATCH} MODULE_VERSION = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}.$${MODULE_VERSION_PATCH}

2
src/imports/mvvmcore/mvvmcore.pro

@ -20,7 +20,7 @@ OTHER_FILES += qmldir
generate_qmltypes { generate_qmltypes {
typeextra1.target = qmltypes typeextra1.target = qmltypes
typeextra1.depends += export LD_LIBRARY_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/lib/:$(LD_LIBRARY_PATH)" typeextra1.depends += export LD_LIBRARY_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/lib/:$$[QT_INSTALL_LIBS]:$(LD_LIBRARY_PATH)"
typeextra2.target = qmltypes typeextra2.target = qmltypes
typeextra2.depends += export QML2_IMPORT_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/qml/" typeextra2.depends += export QML2_IMPORT_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/qml/"
QMAKE_EXTRA_TARGETS += typeextra1 typeextra2 QMAKE_EXTRA_TARGETS += typeextra1 typeextra2

10
src/imports/mvvmcore/qqmlmvvmmessage.cpp

@ -55,7 +55,7 @@ void QQmlMvvmMessage::getInput(const QString &title, const QString &text, const
{ {
if(onResult.isCallable()) { if(onResult.isCallable()) {
auto engine = _engine; auto engine = _engine;
QtMvvm::getInput(title, text, qUtf8Printable(inputType), this, [engine, onResult](QVariant result){ QtMvvm::getInput(title, text, qUtf8Printable(inputType), this, [engine, onResult](const QVariant &result){
QJSValue(onResult).call({engine->toScriptValue(result)}); QJSValue(onResult).call({engine->toScriptValue(result)});
}, defaultValue, viewProperties, okText, cancelText); }, defaultValue, viewProperties, okText, cancelText);
} else } else
@ -66,7 +66,7 @@ void QQmlMvvmMessage::getExistingDirectory(const QJSValue &onResult, const QStri
{ {
if(onResult.isCallable()) { if(onResult.isCallable()) {
auto engine = _engine; auto engine = _engine;
QtMvvm::getExistingDirectory(this, [engine, onResult](QUrl url){ QtMvvm::getExistingDirectory(this, [engine, onResult](const QUrl &url){
QJSValue(onResult).call({engine->toScriptValue(url)}); QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, dir); }, title, dir);
} else } else
@ -77,7 +77,7 @@ void QQmlMvvmMessage::getOpenFile(const QJSValue &onResult, const QString &title
{ {
if(onResult.isCallable()) { if(onResult.isCallable()) {
auto engine = _engine; auto engine = _engine;
QtMvvm::getOpenFile(this, [engine, onResult](QUrl url){ QtMvvm::getOpenFile(this, [engine, onResult](const QUrl &url){
QJSValue(onResult).call({engine->toScriptValue(url)}); QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, supportedMimeTypes, dir); }, title, supportedMimeTypes, dir);
} else } else
@ -88,7 +88,7 @@ void QQmlMvvmMessage::getOpenFiles(const QJSValue &onResult, const QString &titl
{ {
if(onResult.isCallable()) { if(onResult.isCallable()) {
auto engine = _engine; auto engine = _engine;
QtMvvm::getOpenFiles(this, [engine, onResult](QList<QUrl> url){ QtMvvm::getOpenFiles(this, [engine, onResult](const QList<QUrl> &url){
QJSValue(onResult).call({engine->toScriptValue(url)}); QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, supportedMimeTypes, dir); }, title, supportedMimeTypes, dir);
} else } else
@ -99,7 +99,7 @@ void QQmlMvvmMessage::getSaveFile(const QJSValue &onResult, const QString &title
{ {
if(onResult.isCallable()) { if(onResult.isCallable()) {
auto engine = _engine; auto engine = _engine;
QtMvvm::getSaveFile(this, [engine, onResult](QUrl url){ QtMvvm::getSaveFile(this, [engine, onResult](const QUrl &url){
QJSValue(onResult).call({engine->toScriptValue(url)}); QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, supportedMimeTypes, dir); }, title, supportedMimeTypes, dir);
} else } else

2
src/imports/mvvmdatasynccore/mvvmdatasynccore.pro

@ -16,7 +16,7 @@ OTHER_FILES += qmldir
generate_qmltypes { generate_qmltypes {
typeextra1.target = qmltypes typeextra1.target = qmltypes
typeextra1.depends += export LD_LIBRARY_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/lib/:$(LD_LIBRARY_PATH)" typeextra1.depends += export LD_LIBRARY_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/lib/:$$[QT_INSTALL_LIBS]:$(LD_LIBRARY_PATH)"
typeextra2.target = qmltypes typeextra2.target = qmltypes
typeextra2.depends += export QML2_IMPORT_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/qml/" typeextra2.depends += export QML2_IMPORT_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/qml/"
QMAKE_EXTRA_TARGETS += typeextra1 typeextra2 QMAKE_EXTRA_TARGETS += typeextra1 typeextra2

2
src/imports/mvvmdatasyncquick/mvvmdatasyncquick.pro

@ -27,7 +27,7 @@ OTHER_FILES += qmldir
generate_qmltypes { generate_qmltypes {
typeextra1.target = qmltypes typeextra1.target = qmltypes
typeextra1.depends += export LD_LIBRARY_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/lib/:$(LD_LIBRARY_PATH)" typeextra1.depends += export LD_LIBRARY_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/lib/:$$[QT_INSTALL_LIBS]:$(LD_LIBRARY_PATH)"
typeextra2.target = qmltypes typeextra2.target = qmltypes
typeextra2.depends += export QML2_IMPORT_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/qml/" typeextra2.depends += export QML2_IMPORT_PATH := "$$shadowed($$dirname(_QMAKE_CONF_))/qml/"
QMAKE_EXTRA_TARGETS += typeextra1 typeextra2 QMAKE_EXTRA_TARGETS += typeextra1 typeextra2

2
src/imports/mvvmquick/androidfilechooser.cpp

@ -14,7 +14,7 @@ AndroidFileChooser::AndroidFileChooser(QObject *parent) :
_result() _result()
{} {}
AndroidFileChooser::~AndroidFileChooser() {} AndroidFileChooser::~AndroidFileChooser() = default;
AndroidFileChooser::ChooserFlags AndroidFileChooser::chooserFlags() const AndroidFileChooser::ChooserFlags AndroidFileChooser::chooserFlags() const
{ {

2
src/imports/mvvmquick/androidfilechooser.h

@ -130,7 +130,7 @@ public:
//! @private //! @private
explicit AndroidFileChooser(QObject *parent = nullptr); explicit AndroidFileChooser(QObject *parent = nullptr);
~AndroidFileChooser(); ~AndroidFileChooser() override;
//! @private //! @private
ChooserFlags chooserFlags() const; ChooserFlags chooserFlags() const;

2
src/imports/mvvmquick/multifilterproxymodel.cpp

@ -39,7 +39,7 @@ bool MultiFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &
auto rData = sourceModel()->data(sourceModel()->index(source_row, 0, source_parent), role); auto rData = sourceModel()->data(sourceModel()->index(source_row, 0, source_parent), role);
//try as stringlist //try as stringlist
auto strList = rData.toStringList(); auto strList = rData.toStringList();
for(auto str : strList) { for(const auto &str : strList) {
if(_filterRegex.match(str).hasMatch()) if(_filterRegex.match(str).hasMatch())
return true; return true;
} }

5
src/imports/mvvmquick/qqmlquickpresenter.cpp

@ -51,7 +51,8 @@ QStringList QQmlQuickPresenter::mimeTypeFilters(const QStringList &mimeTypes) co
{ {
QMimeDatabase db; QMimeDatabase db;
QStringList filters; QStringList filters;
for(auto mime : mimeTypes) { filters.reserve(mimeTypes.size());
for(const auto &mime : mimeTypes) {
auto mType = db.mimeTypeForName(mime); auto mType = db.mimeTypeForName(mime);
if(mType.isValid()) if(mType.isValid())
filters.append(mType.filterString()); filters.append(mType.filterString());
@ -183,7 +184,7 @@ void QQmlQuickPresenter::statusChanged(QQmlComponent::Status status)
} }
} }
void QQmlQuickPresenter::addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent) void QQmlQuickPresenter::addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, const QPointer<ViewModel> &parent)
{ {
if(!_qmlPresenter) { if(!_qmlPresenter) {
logWarning() << "No QML-Presenter registered! Unable to present viewModel of type" logWarning() << "No QML-Presenter registered! Unable to present viewModel of type"

4
src/imports/mvvmquick/qqmlquickpresenter.h

@ -158,7 +158,7 @@ private Q_SLOTS:
void statusChanged(QQmlComponent::Status status); void statusChanged(QQmlComponent::Status status);
private: private:
typedef std::tuple<ViewModel*, QVariantHash, QPointer<ViewModel>> PresentTuple; using PresentTuple = std::tuple<ViewModel*, QVariantHash, QPointer<ViewModel>>;
QQmlEngine *_engine; QQmlEngine *_engine;
QPointer<QObject> _qmlPresenter; QPointer<QObject> _qmlPresenter;
@ -166,7 +166,7 @@ private:
QCache<QUrl, QQmlComponent> _componentCache; QCache<QUrl, QQmlComponent> _componentCache;
QHash<QQmlComponent*, PresentTuple> _loadCache; QHash<QQmlComponent*, PresentTuple> _loadCache;
void addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent); void addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, const QPointer<ViewModel> &parent);
}; };
} }

14
src/imports/mvvmquick/settingsentrymodel.cpp

@ -22,8 +22,8 @@ void SettingsEntryModel::setup(const SettingsElements::Section &section, Setting
_entries.clear(); _entries.clear();
_viewModel = viewModel; _viewModel = viewModel;
auto rIndex = 0; auto rIndex = 0;
for(auto group : section.groups) { for(const auto &group : section.groups) {
for(auto entry : group.entries) { for(const auto &entry : group.entries) {
auto url = factory->getDelegate(entry.type, entry.properties); auto url = factory->getDelegate(entry.type, entry.properties);
if(group.title.isEmpty()) // unnamed groups are presented first if(group.title.isEmpty()) // unnamed groups are presented first
_entries.insert(rIndex++, EntryInfo{entry, url}); _entries.insert(rIndex++, EntryInfo{entry, url});
@ -104,14 +104,14 @@ Qt::ItemFlags SettingsEntryModel::flags(const QModelIndex &index) const
SettingsEntryModel::EntryInfo::EntryInfo(SettingsElements::Entry entry, const QUrl &delegateUrl, SettingsElements::Group group) : SettingsEntryModel::EntryInfo::EntryInfo(SettingsElements::Entry entry, QUrl delegateUrl, SettingsElements::Group group) :
Entry(entry), Entry(std::move(entry)),
delegateUrl(delegateUrl), delegateUrl(std::move(delegateUrl)),
group(group) group(std::move(group))
{ {
static const QRegularExpression nameRegex(QStringLiteral("&(?!&)"), static const QRegularExpression nameRegex(QStringLiteral("&(?!&)"),
QRegularExpression::DontCaptureOption | QRegularExpression::DontCaptureOption |
QRegularExpression::OptimizeOnFirstUsageOption); QRegularExpression::OptimizeOnFirstUsageOption);
title.remove(nameRegex); title.remove(nameRegex);
group.entries.clear(); this->group.entries.clear();
} }

2
src/imports/mvvmquick/settingsentrymodel.h

@ -43,7 +43,7 @@ public:
private: private:
struct EntryInfo : public SettingsElements::Entry { struct EntryInfo : public SettingsElements::Entry {
public: public:
EntryInfo(SettingsElements::Entry entry = {}, const QUrl &delegateUrl = {}, SettingsElements::Group group = {}); EntryInfo(SettingsElements::Entry entry = {}, QUrl delegateUrl = {}, SettingsElements::Group group = {});
QUrl delegateUrl; QUrl delegateUrl;
SettingsElements::Group group; SettingsElements::Group group;

16
src/imports/mvvmquick/settingssectionmodel.cpp

@ -21,12 +21,12 @@ void SettingsSectionModel::setup(const SettingsElements::Setup &setup)
_sections.clear(); _sections.clear();
_hasSections = false; _hasSections = false;
auto rIndex = 0; auto rIndex = 0;
for(auto category : setup.categories) { for(const auto &category : setup.categories) {
if(category.sections.size() == 1) { // single sects are always at the beginning if(category.sections.size() == 1) { // single sects are always at the beginning
_hasSections = true; _hasSections = true;
_sections.insert(rIndex++, category); _sections.insert(rIndex++, category);
} else { } else {
for(auto section : category.sections) for(const auto &section : category.sections)
_sections.append(SectionInfo{section, category}); _sections.append(SectionInfo{section, category});
} }
} }
@ -62,9 +62,9 @@ QVariant SettingsSectionModel::data(const QModelIndex &index, int role) const
{ {
const auto &section = _sections[index.row()]; const auto &section = _sections[index.row()];
if(section.searchKeys.isEmpty()) { if(section.searchKeys.isEmpty()) {
for(auto group : section.groups) { for(const auto &group : section.groups) {
section.searchKeys.append(group.title); section.searchKeys.append(group.title);
for(auto entry : group.entries) { for(const auto &entry : group.entries) {
section.searchKeys.append(entry.title); section.searchKeys.append(entry.title);
section.searchKeys.append(entry.tooltip); section.searchKeys.append(entry.tooltip);
section.searchKeys.append(entry.searchKeys); section.searchKeys.append(entry.searchKeys);
@ -97,13 +97,13 @@ bool SettingsSectionModel::hasSections() const
SettingsSectionModel::SectionInfo::SectionInfo(SettingsElements::Section section, SettingsElements::Category category) : SettingsSectionModel::SectionInfo::SectionInfo(SettingsElements::Section section, SettingsElements::Category category) :
Section(section), Section(std::move(section)),
category(category) category(std::move(category))
{ {
category.sections.clear(); this->category.sections.clear();
} }
SettingsSectionModel::SectionInfo::SectionInfo(SettingsElements::Category category) : SettingsSectionModel::SectionInfo::SectionInfo(const SettingsElements::Category &category) :
Section{category.title, category.icon, category.tooltip, category.sections.first().groups, {}, {}}, Section{category.title, category.icon, category.tooltip, category.sections.first().groups, {}, {}},
category() category()
{} {}

2
src/imports/mvvmquick/settingssectionmodel.h

@ -40,7 +40,7 @@ private:
struct SectionInfo : public SettingsElements::Section { struct SectionInfo : public SettingsElements::Section {
public: public:
SectionInfo(SettingsElements::Section section = {}, SettingsElements::Category category = {}); SectionInfo(SettingsElements::Section section = {}, SettingsElements::Category category = {});
SectionInfo(SettingsElements::Category category); SectionInfo(const SettingsElements::Category &category);
SettingsElements::Category category; SettingsElements::Category category;
mutable QStringList searchKeys; mutable QStringList searchKeys;

24
src/imports/mvvmquick/settingsuibuilder.cpp

@ -14,16 +14,10 @@ using namespace QtMvvm;
SettingsUiBuilder::SettingsUiBuilder(QObject *parent) : SettingsUiBuilder::SettingsUiBuilder(QObject *parent) :
QObject(parent), QObject(parent),
_buildView(nullptr),
_viewModel(nullptr),
_filterText(),
_allowSearch(true),
_allowRestore(true),
_sectionFilterModel(new MultiFilterProxyModel(this)), _sectionFilterModel(new MultiFilterProxyModel(this)),
_sectionModel(new SettingsSectionModel(this)), _sectionModel(new SettingsSectionModel(this)),
_entryFilterModel(new MultiFilterProxyModel(this)), _entryFilterModel(new MultiFilterProxyModel(this)),
_entryModel(new SettingsEntryModel(this)), _entryModel(new SettingsEntryModel(this))
_currentSetup()
{ {
_sectionFilterModel->setSourceModel(_sectionModel); _sectionFilterModel->setSourceModel(_sectionModel);
_sectionFilterModel->addFilterRoles(SettingsSectionModel::FilterRoles); _sectionFilterModel->addFilterRoles(SettingsSectionModel::FilterRoles);
@ -55,7 +49,7 @@ void SettingsUiBuilder::showDialog(const QString &key, const QString &title, con
_viewModel->callAction(key, properties.value(QStringLiteral("args")).toMap()); _viewModel->callAction(key, properties.value(QStringLiteral("args")).toMap());
else { else {
qmlDebug(this) << "Creating input dialog for settings entry" << key; qmlDebug(this) << "Creating input dialog for settings entry" << key;
getInput(title + tr(":"), QString(), qUtf8Printable(type), this, [this, key](QVariant value) { getInput(title + tr(":"), QString(), qUtf8Printable(type), this, [this, key](const QVariant &value) {
if(value.isValid()) if(value.isValid())
_viewModel->saveValue(key, value); _viewModel->saveValue(key, value);
}, _viewModel->loadValue(key, defaultValue), properties); }, _viewModel->loadValue(key, defaultValue), properties);
@ -71,10 +65,10 @@ void SettingsUiBuilder::restoreDefaults()
connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton btn) { connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton btn) {
if(btn != MessageConfig::Yes) if(btn != MessageConfig::Yes)
return; return;
for(auto category : qAsConst(_currentSetup.categories)) { for(const auto &category : qAsConst(_currentSetup.categories)) {
for(auto section : category.sections) { for(const auto &section : category.sections) {
for(auto group : section.groups) { for(const auto &group : section.groups) {
for(auto entry : group.entries) for(const auto &entry : group.entries)
_viewModel->resetValue(entry.key); _viewModel->resetValue(entry.key);
} }
} }
@ -88,10 +82,10 @@ void SettingsUiBuilder::setFilterText(QString filterText)
if (_filterText == filterText) if (_filterText == filterText)
return; return;
_filterText = filterText; _filterText = std::move(filterText);
emit filterTextChanged(filterText); emit filterTextChanged(_filterText);
QRegularExpression regex(filterText, QRegularExpression regex(_filterText,
QRegularExpression::CaseInsensitiveOption | QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption | QRegularExpression::UseUnicodePropertiesOption |
QRegularExpression::DontCaptureOption); QRegularExpression::DontCaptureOption);

8
src/imports/mvvmquick/settingsuibuilder.h

@ -51,12 +51,12 @@ private Q_SLOTS:
void startBuildUi(); void startBuildUi();
private: private:
QQuickItem* _buildView; QQuickItem* _buildView = nullptr;
SettingsViewModel *_viewModel; SettingsViewModel *_viewModel = nullptr;
QString _filterText; QString _filterText;
bool _allowSearch; bool _allowSearch = true;
bool _allowRestore; bool _allowRestore = true;
MultiFilterProxyModel *_sectionFilterModel; MultiFilterProxyModel *_sectionFilterModel;
SettingsSectionModel *_sectionModel; SettingsSectionModel *_sectionModel;

18
src/mvvmcore/binding.cpp

@ -90,10 +90,10 @@ Binding::Binding() :
{} {}
Binding::Binding(QPointer<BindingPrivate> d_ptr) : Binding::Binding(QPointer<BindingPrivate> d_ptr) :
d(d_ptr) d(std::move(d_ptr))
{} {}
Binding::~Binding() {} Binding::~Binding() = default;
bool Binding::isValid() const bool Binding::isValid() const
{ {
@ -110,26 +110,26 @@ void Binding::unbind()
// ------------- Private Implementation ------------- // ------------- Private Implementation -------------
Binding BindingPrivate::bind(QObject *viewModel, const QMetaProperty &viewModelProperty, QObject *view, const QMetaProperty &viewProperty, Binding::BindingDirection type, const QMetaMethod &viewModelChangeSignal, const QMetaMethod &viewChangeSignal) Binding BindingPrivate::bind(QObject *viewModel, QMetaProperty viewModelProperty, QObject *view, QMetaProperty viewProperty, Binding::BindingDirection type, QMetaMethod viewModelChangeSignal, QMetaMethod viewChangeSignal)
{ {
QPointer<BindingPrivate> binderPrivate = new BindingPrivate(viewModel, viewModelProperty, view, viewProperty); QPointer<BindingPrivate> binderPrivate = new BindingPrivate(viewModel, std::move(viewModelProperty), view, std::move(viewProperty));
if(type.testFlag(Binding::SingleInit)) if(type.testFlag(Binding::SingleInit))
binderPrivate->init(); binderPrivate->init();
if(type.testFlag(Binding::OneWayToView)) if(type.testFlag(Binding::OneWayToView))
binderPrivate->bindFrom(viewModelChangeSignal); binderPrivate->bindFrom(std::move(viewModelChangeSignal));
if(type.testFlag(Binding::OneWayToViewModel)) if(type.testFlag(Binding::OneWayToViewModel))
binderPrivate->bindTo(viewChangeSignal); binderPrivate->bindTo(std::move(viewChangeSignal));
return binderPrivate; return binderPrivate;
} }
BindingPrivate::BindingPrivate(QObject *viewModel, const QMetaProperty &viewModelProperty, QObject *view, const QMetaProperty &viewProperty) : BindingPrivate::BindingPrivate(QObject *viewModel, QMetaProperty viewModelProperty, QObject *view, QMetaProperty viewProperty) :
QObject(view), QObject(view),
viewModel(viewModel), viewModel(viewModel),
view(view), view(view),
viewModelProperty(viewModelProperty), viewModelProperty(std::move(viewModelProperty)),
viewProperty(viewProperty) viewProperty(std::move(viewProperty))
{ {
connect(viewModel, &QObject::destroyed, connect(viewModel, &QObject::destroyed,
this, &BindingPrivate::deleteLater); this, &BindingPrivate::deleteLater);

12
src/mvvmcore/binding_p.h

@ -15,19 +15,19 @@ class BindingPrivate : public QObject
Q_OBJECT Q_OBJECT
public: public:
static Binding bind(QObject *viewModel, const QMetaProperty &viewModelProperty, static Binding bind(QObject *viewModel, QMetaProperty viewModelProperty,
QObject *view, const QMetaProperty &viewProperty, QObject *view, QMetaProperty viewProperty,
Binding::BindingDirection type, Binding::BindingDirection type,
const QMetaMethod &viewModelChangeSignal, QMetaMethod viewModelChangeSignal,
const QMetaMethod &viewChangeSignal); QMetaMethod viewChangeSignal);
private Q_SLOTS: private Q_SLOTS:
void viewModelTrigger(); void viewModelTrigger();
void viewTrigger(); void viewTrigger();
private: private:
BindingPrivate(QObject *viewModel, const QMetaProperty &viewModelProperty, BindingPrivate(QObject *viewModel, QMetaProperty viewModelProperty,
QObject *view, const QMetaProperty &viewProperty); QObject *view, QMetaProperty viewProperty);
void init(); void init();
void bindFrom(QMetaMethod changeSignal); void bindFrom(QMetaMethod changeSignal);

2
src/mvvmcore/coreapp.cpp

@ -15,7 +15,7 @@ CoreApp::CoreApp(QObject *parent) :
d(new CoreAppPrivate()) d(new CoreAppPrivate())
{} {}
CoreApp::~CoreApp() {} CoreApp::~CoreApp() = default;
CoreApp *CoreApp::instance() CoreApp *CoreApp::instance()
{ {

2
src/mvvmcore/coreapp.h

@ -24,7 +24,7 @@ class Q_MVVMCORE_EXPORT CoreApp : public QObject
public: public:
//! Default Constructor //! Default Constructor
explicit CoreApp(QObject *parent = nullptr); explicit CoreApp(QObject *parent = nullptr);
~CoreApp(); ~CoreApp() override;
//! Returns the current CoreApp instance //! Returns the current CoreApp instance
static CoreApp *instance(); static CoreApp *instance();

2
src/mvvmcore/ipresenter.h

@ -35,7 +35,9 @@ protected:
//! The interface for a GUI view presenter //! The interface for a GUI view presenter
class Q_MVVMCORE_EXPORT IPresenter class Q_MVVMCORE_EXPORT IPresenter
{ {
Q_DISABLE_COPY(IPresenter)
public: public:
inline IPresenter() = default;
inline virtual ~IPresenter() = default; inline virtual ~IPresenter() = default;
//! Called to present a viewmodel //! Called to present a viewmodel

55
src/mvvmcore/message.cpp

@ -30,17 +30,15 @@ MessageConfig::MessageConfig(const QByteArray &type, const QByteArray &subType)
resetButtons(); resetButtons();
} }
MessageConfig::MessageConfig(const MessageConfig &other) : MessageConfig::MessageConfig(MessageConfig &&other)= default;
d(other.d)
{}
MessageConfig::~MessageConfig() {} MessageConfig::MessageConfig(const MessageConfig &other) = default;
MessageConfig &MessageConfig::operator=(const MessageConfig &other) MessageConfig::~MessageConfig() = default;
{
d = other.d; MessageConfig &MessageConfig::operator=(const MessageConfig &other) = default;
return (*this);
} MessageConfig &MessageConfig::operator=(MessageConfig &&other) = default;
QByteArray MessageConfig::type() const QByteArray MessageConfig::type() const
{ {
@ -194,7 +192,7 @@ MessageResult::MessageResult() :
d(new MessageResultPrivate()) d(new MessageResultPrivate())
{} {}
MessageResult::~MessageResult() {} MessageResult::~MessageResult() = default;
bool MessageResult::hasResult() const bool MessageResult::hasResult() const
{ {
@ -256,7 +254,7 @@ void MessageResult::discardMessage()
void MessageResult::setResult(QVariant result) void MessageResult::setResult(QVariant result)
{ {
QMutexLocker lock(&d->mutex); QMutexLocker lock(&d->mutex);
d->result = result; d->result = std::move(result);
} }
void MessageResult::setAutoDelete(bool autoDelete) void MessageResult::setAutoDelete(bool autoDelete)
@ -270,29 +268,13 @@ void MessageResult::setAutoDelete(bool autoDelete)
// ------------- Private Implementation ------------- // ------------- Private Implementation -------------
QtMvvm::MessageConfigPrivate::MessageConfigPrivate(const QByteArray &type, const QByteArray &subType) : QtMvvm::MessageConfigPrivate::MessageConfigPrivate(QByteArray type, QByteArray subType) :
QSharedData(), QSharedData(),
type(type), type(std::move(type)),
subType(subType), subType(std::move(subType))
title(),
text(),
buttons(MessageConfig::Ok),
buttonTexts(),
defaultValue(),
editProperties()
{} {}
QtMvvm::MessageConfigPrivate::MessageConfigPrivate(const QtMvvm::MessageConfigPrivate &other) : QtMvvm::MessageConfigPrivate::MessageConfigPrivate(const QtMvvm::MessageConfigPrivate &other) = default;
QSharedData(other),
type(other.type),
subType(other.subType),
title(other.title),
text(other.text),
buttons(other.buttons),
buttonTexts(other.buttonTexts),
defaultValue(other.defaultValue),
editProperties(other.editProperties)
{}
// ------------- Namespace methods implementation ------------- // ------------- Namespace methods implementation -------------
@ -409,8 +391,7 @@ MessageResult *QtMvvm::about(const QString &description, const QUrl &websiteUrl,
config.setViewProperty(QStringLiteral("addQtVersion"), addQtVersion); config.setViewProperty(QStringLiteral("addQtVersion"), addQtVersion);
config.setTitle(MessageConfig::tr("%1 — Version %2") config.setTitle(MessageConfig::tr("%1 — Version %2")
.arg(QGuiApplication::applicationDisplayName()) .arg(QGuiApplication::applicationDisplayName(), QCoreApplication::applicationVersion()));
.arg(QCoreApplication::applicationVersion()));
//create the content string: //create the content string:
//basic text //basic text
@ -431,7 +412,7 @@ MessageResult *QtMvvm::about(const QString &description, const QUrl &websiteUrl,
} }
if(!extraTopInfos.isEmpty()) { if(!extraTopInfos.isEmpty()) {
auto withBr = addQtVersion; auto withBr = addQtVersion;
for(auto info : extraTopInfos) { for(const auto &info : extraTopInfos) {
text += info + (withBr ? br : QString()); text += info + (withBr ? br : QString());
withBr = true; withBr = true;
} }
@ -443,14 +424,12 @@ MessageResult *QtMvvm::about(const QString &description, const QUrl &websiteUrl,
.arg(companyName.isEmpty() ? QCoreApplication::organizationName() : companyName); .arg(companyName.isEmpty() ? QCoreApplication::organizationName() : companyName);
if(websiteUrl.isValid()) { if(websiteUrl.isValid()) {
text += br + MessageConfig::tr("Project Website: <a href=\"%1\">%2</a>") text += br + MessageConfig::tr("Project Website: <a href=\"%1\">%2</a>")
.arg(QString::fromUtf8(websiteUrl.toEncoded())) .arg(QString::fromUtf8(websiteUrl.toEncoded()), websiteUrl.toString());
.arg(websiteUrl.toString());
} }
if(!licenseName.isEmpty()) { if(!licenseName.isEmpty()) {
if(licenseUrl.isValid()) { if(licenseUrl.isValid()) {
text += br + MessageConfig::tr("License: <a href=\"%1\">%2</a>") text += br + MessageConfig::tr("License: <a href=\"%1\">%2</a>")
.arg(QString::fromUtf8(licenseUrl.toEncoded())) .arg(QString::fromUtf8(licenseUrl.toEncoded()), licenseName);
.arg(licenseName);
} else { } else {
text += br + MessageConfig::tr("License: %1") text += br + MessageConfig::tr("License: %1")
.arg(licenseName); .arg(licenseName);

8
src/mvvmcore/message.h

@ -112,10 +112,12 @@ public:
MessageConfig(const QByteArray &type = TypeMessageBox, const QByteArray &subType = {}); MessageConfig(const QByteArray &type = TypeMessageBox, const QByteArray &subType = {});
//! Copy constructor //! Copy constructor
MessageConfig(const MessageConfig &other); MessageConfig(const MessageConfig &other);
MessageConfig(MessageConfig &&other);
~MessageConfig(); ~MessageConfig();
//! Assignment operator //! Assignment operator
MessageConfig &operator=(const MessageConfig &other); MessageConfig &operator=(const MessageConfig &other);
MessageConfig &operator=(MessageConfig &&other);
//! @readAcFn{MessageConfig::type} //! @readAcFn{MessageConfig::type}
QByteArray type() const; QByteArray type() const;
@ -180,7 +182,7 @@ class Q_MVVMCORE_EXPORT MessageResult : public QObject
public: public:
explicit MessageResult(); explicit MessageResult();
~MessageResult(); ~MessageResult() override;
//! Checks if the dialog has a result //! Checks if the dialog has a result
bool hasResult() const; bool hasResult() const;
@ -361,7 +363,7 @@ inline void getInput(const QString &title,
const QVariantMap &viewProperties = {}, const QVariantMap &viewProperties = {},
const QString &okText = {}, const QString &okText = {},
const QString &cancelText = {}) { const QString &cancelText = {}) {
getInput(title, text, QMetaType::typeName(qMetaTypeId<TEdit>()), scope, [onResult](QVariant v) { getInput(title, text, QMetaType::typeName(qMetaTypeId<TEdit>()), scope, [onResult](const QVariant &v) {
onResult(v.template value<TEdit>(), v.isValid()); onResult(v.template value<TEdit>(), v.isValid());
}, QVariant::fromValue(defaultValue), viewProperties, okText, cancelText); }, QVariant::fromValue(defaultValue), viewProperties, okText, cancelText);
} }
@ -374,7 +376,7 @@ inline void getInput(const QString &title,
const QVariantMap &viewProperties = {}, const QVariantMap &viewProperties = {},
const QString &okText = {}, const QString &okText = {},
const QString &cancelText = {}) { const QString &cancelText = {}) {
getInput(title, text, QMetaType::typeName(qMetaTypeId<TEdit>()), [onResult](QVariant v) { getInput(title, text, QMetaType::typeName(qMetaTypeId<TEdit>()), [onResult](const QVariant &v) {
onResult(v.template value<TEdit>(), v.isValid()); onResult(v.template value<TEdit>(), v.isValid());
}, QVariant::fromValue(defaultValue), viewProperties, okText, cancelText); }, QVariant::fromValue(defaultValue), viewProperties, okText, cancelText);
} }

4
src/mvvmcore/message_p.h

@ -14,14 +14,14 @@ namespace QtMvvm {
class MessageConfigPrivate : public QSharedData class MessageConfigPrivate : public QSharedData
{ {
public: public:
MessageConfigPrivate(const QByteArray &type, const QByteArray &subType); MessageConfigPrivate(QByteArray type, QByteArray subType);
MessageConfigPrivate(const MessageConfigPrivate &other); MessageConfigPrivate(const MessageConfigPrivate &other);
QByteArray type; QByteArray type;
QByteArray subType; QByteArray subType;
QString title; QString title;
QString text; QString text;
MessageConfig::StandardButtons buttons; MessageConfig::StandardButtons buttons = MessageConfig::Ok;
QHash<MessageConfig::StandardButton, QString> buttonTexts; QHash<MessageConfig::StandardButton, QString> buttonTexts;
QVariant defaultValue; QVariant defaultValue;
QVariantMap editProperties; QVariantMap editProperties;

18
src/mvvmcore/qtmvvmcore_helpertypes.h

@ -44,22 +44,22 @@ inline QByteArray inject_iid() {
} }
template <typename TFunc, typename T1, typename... TArgs> template <typename TFunc, typename T1, typename... TArgs>
inline std::function<QObject*(QObjectList)> pack_function_imp(const TFunc &fn, QByteArrayList &injectables); inline std::function<QObject*(QObjectList)> pack_function_imp(TFunc fn, QByteArrayList &injectables);
template <typename TFunc> template <typename TFunc>
inline std::function<QObject*(QObjectList)> pack_function_imp(const TFunc &fn, QByteArrayList &injectables); inline std::function<QObject*(QObjectList)> pack_function_imp(TFunc fn, QByteArrayList &injectables);
template <typename TFunc, typename T1, typename... TArgs> template <typename TFunc, typename T1, typename... TArgs>
inline std::function<QObject*(QObjectList)> pack_function_imp(const TFunc &fn, QByteArrayList &injectables) { inline std::function<QObject*(QObjectList)> pack_function_imp(TFunc fn, QByteArrayList &injectables) {
injectables.append(inject_iid<T1>()); injectables.append(inject_iid<T1>());
auto subFn = [fn](const QObjectList &params, int index, TArgs... tArgs) { auto subFn = [fn](const QObjectList &params, int index, TArgs... tArgs) {
--index; --index;
return fn(params, index, qobject_cast<T1>(params[index]), tArgs...); return fn(params, index, qobject_cast<T1>(params[index]), tArgs...);
}; };
return pack_function_imp<decltype(subFn), TArgs...>(subFn, injectables); return pack_function_imp<decltype(subFn), TArgs...>(std::move(subFn), injectables);
} }
template <typename TFunc> template <typename TFunc>
inline std::function<QObject*(QObjectList)> pack_function_imp(const TFunc &fn, QByteArrayList &injectables) { inline std::function<QObject*(QObjectList)> pack_function_imp(TFunc fn, QByteArrayList &injectables) {
Q_UNUSED(injectables) Q_UNUSED(injectables)
return [fn](const QObjectList &params) { return [fn](const QObjectList &params) {
return fn(params, params.size()); return fn(params, params.size());
@ -73,19 +73,19 @@ template <typename TClass, typename TRet, typename... TArgs>
struct fn_info<TRet(TClass::*)(TArgs...) const> struct fn_info<TRet(TClass::*)(TArgs...) const>
{ {
template <typename TFunctor> template <typename TFunctor>
static inline std::function<QObject*(QObjectList)> pack(const TFunctor &fn, QByteArrayList &injectables) { static inline std::function<QObject*(QObjectList)> pack(TFunctor fn, QByteArrayList &injectables) {
auto subFn = [fn](const QObjectList &params, int index, TArgs... args) -> QObject* { auto subFn = [fn](const QObjectList &params, int index, TArgs... args) -> QObject* {
Q_UNUSED(params) Q_UNUSED(params)
Q_ASSERT_X(index == 0, Q_FUNC_INFO, "number of params does not equal recursion depth"); Q_ASSERT_X(index == 0, Q_FUNC_INFO, "number of params does not equal recursion depth");
return fn(args...); return fn(args...);
}; };
return pack_function_imp<decltype(subFn), TArgs...>(subFn, injectables); return pack_function_imp<decltype(subFn), TArgs...>(std::move(subFn), injectables);
} }
}; };
template <typename TFunc> template <typename TFunc>
inline std::function<QObject*(QObjectList)> pack_function(const TFunc &fn, QByteArrayList &injectables) { inline std::function<QObject*(QObjectList)> pack_function(TFunc fn, QByteArrayList &injectables) {
return fn_info<TFunc>::pack(fn, injectables); return fn_info<TFunc>::pack(std::move(fn), injectables);
} }

16
src/mvvmcore/serviceregistry.cpp

@ -17,7 +17,7 @@ ServiceRegistry::ServiceRegistry(ServiceRegistryPrivate *d_ptr) :
d(d_ptr) d(d_ptr)
{} {}
ServiceRegistry::~ServiceRegistry() {} ServiceRegistry::~ServiceRegistry() = default;
ServiceRegistry *ServiceRegistry::instance() ServiceRegistry *ServiceRegistry::instance()
{ {
@ -58,14 +58,12 @@ QObject *ServiceRegistry::serviceObj(const QByteArray &iid)
void ServiceRegistry::injectServices(QObject *object) void ServiceRegistry::injectServices(QObject *object)
{ {
auto &d = ServiceRegistry::instance()->d;
QMutexLocker _(&d->serviceMutex); QMutexLocker _(&d->serviceMutex);
d->injectLocked(object); d->injectLocked(object);
} }
QObject *ServiceRegistry::constructInjected(const QMetaObject *metaObject, QObject *parent) QObject *ServiceRegistry::constructInjected(const QMetaObject *metaObject, QObject *parent)
{ {
auto &d = ServiceRegistry::instance()->d;
QMutexLocker _(&d->serviceMutex); QMutexLocker _(&d->serviceMutex);
return d->constructInjectedLocked(metaObject, parent); return d->constructInjectedLocked(metaObject, parent);
} }
@ -138,8 +136,7 @@ void ServiceRegistryPrivate::injectLocked(QObject *object)
ServiceRegistryPrivate::ServiceInfo::ServiceInfo(bool weak) : ServiceRegistryPrivate::ServiceInfo::ServiceInfo(bool weak) :
_weak(weak), _weak{weak}
_instance(nullptr)
{} {}
ServiceRegistryPrivate::ServiceInfo::~ServiceInfo() ServiceRegistryPrivate::ServiceInfo::~ServiceInfo()
@ -174,16 +171,17 @@ QObject *ServiceRegistryPrivate::ServiceInfo::instance(ServiceRegistryPrivate *d
ServiceRegistryPrivate::FnServiceInfo::FnServiceInfo(const std::function<QObject*(QObjectList)> &creator, const QByteArrayList &injectables, bool weak) : ServiceRegistryPrivate::FnServiceInfo::FnServiceInfo(std::function<QObject*(QObjectList)> creator, QByteArrayList injectables, bool weak) :
ServiceInfo(weak), ServiceInfo(weak),
creator(creator), creator(std::move(creator)),
injectables(injectables) injectables(std::move(injectables))
{} {}
QObject *ServiceRegistryPrivate::FnServiceInfo::construct(ServiceRegistryPrivate *d) const QObject *ServiceRegistryPrivate::FnServiceInfo::construct(ServiceRegistryPrivate *d) const
{ {
QObjectList params; QObjectList params;
for(auto iid : injectables) { params.reserve(injectables.size());
for(const auto &iid : injectables) {
auto ref = d->services.value(iid); auto ref = d->services.value(iid);
if(!ref) if(!ref)
throw ServiceDependencyException(iid); throw ServiceDependencyException(iid);

12
src/mvvmcore/serviceregistry.h

@ -35,7 +35,7 @@ public:
void registerInterface(bool weak = false); void registerInterface(bool weak = false);
//! Register a service for its interface via a constructor function //! Register a service for its interface via a constructor function
template <typename TInterface, typename TService, typename TFunc> template <typename TInterface, typename TService, typename TFunc>
void registerInterface(const TFunc &fn, bool weak = false); void registerInterface(TFunc fn, bool weak = false);
//! Register a service for its interface via an already existing instance //! Register a service for its interface via an already existing instance
template <typename TInterface, typename TService> template <typename TInterface, typename TService>
void registerInterface(TService *service, bool weak = false); void registerInterface(TService *service, bool weak = false);
@ -44,7 +44,7 @@ public:
void registerObject(bool weak = false); void registerObject(bool weak = false);
//! Register a service via a constructor function //! Register a service via a constructor function
template <typename TService, typename TFunc> template <typename TService, typename TFunc>
void registerObject(const TFunc &fn, bool weak = false); void registerObject(TFunc fn, bool weak = false);
//! Register a service via an already existing instance //! Register a service via an already existing instance
template <typename TService> template <typename TService>
void registerObject(TService *service, bool weak = false); void registerObject(TService *service, bool weak = false);
@ -159,11 +159,11 @@ void ServiceRegistry::registerInterface(bool weak)
} }
template <typename TInterface, typename TService, typename TFunc> template <typename TInterface, typename TService, typename TFunc>
void ServiceRegistry::registerInterface(const TFunc &fn, bool weak) void ServiceRegistry::registerInterface(TFunc fn, bool weak)
{ {
QTMVVM_SERVICE_ASSERT(TInterface, TService) QTMVVM_SERVICE_ASSERT(TInterface, TService)
QByteArrayList injectables; QByteArrayList injectables;
auto packed_fn = __helpertypes::pack_function(fn, injectables); auto packed_fn = __helpertypes::pack_function(std::move(fn), injectables);
registerService(qobject_interface_iid<TInterface*>(), packed_fn, injectables, weak); registerService(qobject_interface_iid<TInterface*>(), packed_fn, injectables, weak);
} }
@ -189,11 +189,11 @@ void ServiceRegistry::registerObject(bool weak)
} }
template<typename TService, typename TFunc> template<typename TService, typename TFunc>
void ServiceRegistry::registerObject(const TFunc &fn, bool weak) void ServiceRegistry::registerObject(TFunc fn, bool weak)
{ {
QTMVVM_SERVICE_ASSERT(TService) QTMVVM_SERVICE_ASSERT(TService)
QByteArrayList injectables; QByteArrayList injectables;
auto packed_fn = __helpertypes::pack_function(fn, injectables); auto packed_fn = __helpertypes::pack_function(std::move(fn), injectables);
registerService(__helpertypes::qobject_iid<TService*>(), packed_fn, injectables, weak); registerService(__helpertypes::qobject_iid<TService*>(), packed_fn, injectables, weak);
} }

5
src/mvvmcore/serviceregistry_p.h

@ -13,6 +13,7 @@ class ServiceRegistryPrivate
{ {
public: public:
class ServiceInfo { class ServiceInfo {
Q_DISABLE_COPY(ServiceInfo)
public: public:
ServiceInfo(bool weak); ServiceInfo(bool weak);
virtual ~ServiceInfo(); virtual ~ServiceInfo();
@ -25,12 +26,12 @@ public:
private: private:
const bool _weak; const bool _weak;
QObject *_instance; QObject *_instance = nullptr;
}; };
class FnServiceInfo : public ServiceInfo { class FnServiceInfo : public ServiceInfo {
public: public:
FnServiceInfo(const std::function<QObject*(QObjectList)> &creator, const QByteArrayList &injectables, bool weak); FnServiceInfo(std::function<QObject*(QObjectList)> creator, QByteArrayList injectables, bool weak);
protected: protected:
QObject *construct(ServiceRegistryPrivate *d) const final; QObject *construct(ServiceRegistryPrivate *d) const final;

2
src/mvvmcore/settingssetup.h

@ -114,7 +114,9 @@ class SettingsLoaderException : public QException {};
//! An interface for a generic settings setup loader //! An interface for a generic settings setup loader
class ISettingsSetupLoader class ISettingsSetupLoader
{ {
Q_DISABLE_COPY(ISettingsSetupLoader)
public: public:
inline ISettingsSetupLoader() = default;
virtual inline ~ISettingsSetupLoader() = default; virtual inline ~ISettingsSetupLoader() = default;
//! Can be used to overwrite the default icon for categories //! Can be used to overwrite the default icon for categories

23
src/mvvmcore/settingssetuploader.cpp

@ -20,9 +20,7 @@ using namespace QtMvvm::SettingsElements;
#define trctx(x) QCoreApplication::translate("qtmvvm_settings_xml", qUtf8Printable(x)) #define trctx(x) QCoreApplication::translate("qtmvvm_settings_xml", qUtf8Printable(x))
SettingsSetupLoader::SettingsSetupLoader(QObject *parent) : SettingsSetupLoader::SettingsSetupLoader(QObject *parent) :
QObject(parent), QObject{parent}
_defaultIcon(QStringLiteral("qrc:/de/skycoder42/qtmvvm/icons/settings.svg")),
_cache()
{} {}
void SettingsSetupLoader::changeDefaultIcon(const QUrl &defaultIcon) void SettingsSetupLoader::changeDefaultIcon(const QUrl &defaultIcon)
@ -344,29 +342,29 @@ QVariant SettingsSetupLoader::readElement(QXmlStreamReader &reader) const
bool SettingsSetupLoader::readCategoryInclude(QXmlStreamReader &reader, Category &category, const QFileSelector *selector) const bool SettingsSetupLoader::readCategoryInclude(QXmlStreamReader &reader, Category &category, const QFileSelector *selector) const
{ {
return readInclude(reader, [this, &category, selector](QXmlStreamReader &reader){ return readInclude(reader, [this, &category, selector](QXmlStreamReader &mReader){
category = readCategory(reader, selector); category = readCategory(mReader, selector);
}, QStringLiteral("Category"), selector); }, QStringLiteral("Category"), selector);
} }
bool SettingsSetupLoader::readSectionInclude(QXmlStreamReader &reader, Section &section, const QFileSelector *selector) const bool SettingsSetupLoader::readSectionInclude(QXmlStreamReader &reader, Section &section, const QFileSelector *selector) const
{ {
return readInclude(reader, [this, &section, selector](QXmlStreamReader &reader){ return readInclude(reader, [this, &section, selector](QXmlStreamReader &mReader){
section = readSection(reader, selector); section = readSection(mReader, selector);
}, QStringLiteral("Section"), selector); }, QStringLiteral("Section"), selector);
} }
bool SettingsSetupLoader::readGroupInclude(QXmlStreamReader &reader, Group &group, const QFileSelector *selector) const bool SettingsSetupLoader::readGroupInclude(QXmlStreamReader &reader, Group &group, const QFileSelector *selector) const
{ {
return readInclude(reader, [this, &group, selector](QXmlStreamReader &reader){ return readInclude(reader, [this, &group, selector](QXmlStreamReader &mReader){
group = readGroup(reader, selector); group = readGroup(mReader, selector);
}, QStringLiteral("Group"), selector); }, QStringLiteral("Group"), selector);
} }
bool SettingsSetupLoader::readEntryInclude(QXmlStreamReader &reader, Entry &entry, const QFileSelector *selector) const bool SettingsSetupLoader::readEntryInclude(QXmlStreamReader &reader, Entry &entry, const QFileSelector *selector) const
{ {
return readInclude(reader, [this, &entry](QXmlStreamReader &reader){ return readInclude(reader, [this, &entry](QXmlStreamReader &mReader){
entry = readEntry(reader); entry = readEntry(mReader);
}, QStringLiteral("Entry"), selector); }, QStringLiteral("Entry"), selector);
} }
@ -504,8 +502,7 @@ SettingsXmlException::SettingsXmlException(QXmlStreamReader &reader, const QByte
SettingsXmlException::SettingsXmlException(const QFile &fileError) : SettingsXmlException::SettingsXmlException(const QFile &fileError) :
SettingsLoaderException(), SettingsLoaderException(),
_what(QStringLiteral("Failed to open file \"%1\" with error: %2") _what(QStringLiteral("Failed to open file \"%1\" with error: %2")
.arg(fileError.fileName()) .arg(fileError.fileName(), fileError.errorString())
.arg(fileError.errorString())
.toUtf8()) .toUtf8())
{} {}

2
src/mvvmcore/settingssetuploader_p.h

@ -28,7 +28,7 @@ public:
bool event(QEvent *event) override; bool event(QEvent *event) override;
private: private:
QUrl _defaultIcon; QUrl _defaultIcon{QStringLiteral("qrc:/de/skycoder42/qtmvvm/icons/settings.svg")};
mutable QCache<QString, SettingsElements::Setup> _cache; mutable QCache<QString, SettingsElements::Setup> _cache;
//Functions to read the settings XML //Functions to read the settings XML

2
src/mvvmcore/settingsviewmodel.cpp

@ -14,7 +14,7 @@ SettingsViewModel::SettingsViewModel(QObject *parent) :
d(new SettingsViewModelPrivate()) d(new SettingsViewModelPrivate())
{} {}
SettingsViewModel::~SettingsViewModel() {} SettingsViewModel::~SettingsViewModel() = default;
QVariantHash SettingsViewModel::showParams(QSettings *settings, const QString &setupFile) QVariantHash SettingsViewModel::showParams(QSettings *settings, const QString &setupFile)
{ {

2
src/mvvmcore/settingsviewmodel.h

@ -38,7 +38,7 @@ public:
//! Invokable constructor //! Invokable constructor
Q_INVOKABLE explicit SettingsViewModel(QObject *parent = nullptr); Q_INVOKABLE explicit SettingsViewModel(QObject *parent = nullptr);
~SettingsViewModel(); ~SettingsViewModel() override;
//! @readAcFn{SettingsViewModel::canRestoreDefaults} //! @readAcFn{SettingsViewModel::canRestoreDefaults}
virtual bool canRestoreDefaults() const; virtual bool canRestoreDefaults() const;

12
src/mvvmcore/viewmodel.cpp

@ -9,7 +9,7 @@ ViewModel::ViewModel(QObject *parent) :
d(new ViewModelPrivate()) d(new ViewModelPrivate())
{} {}
ViewModel::~ViewModel() {} ViewModel::~ViewModel() = default;
void ViewModel::onInit(const QVariantHash &) {} void ViewModel::onInit(const QVariantHash &) {}
@ -64,15 +64,11 @@ void ViewModel::showForResult(quint32 requestCode, const QMetaObject *viewMetaOb
showImp(viewMetaObject, params, const_cast<ViewModel*>(this), requestCode); showImp(viewMetaObject, params, const_cast<ViewModel*>(this), requestCode);
} }
void ViewModel::showImp(const QMetaObject *metaObject, const QVariantHash &params, QPointer<ViewModel> parent, quint32 requestCode) void ViewModel::showImp(const QMetaObject *metaObject, QVariantHash params, QPointer<ViewModel> parent, quint32 requestCode)
{ {
QMetaObject::invokeMethod(CoreAppPrivate::dInstance().data(), "showViewModel", Qt::QueuedConnection, QMetaObject::invokeMethod(CoreAppPrivate::dInstance().data(), "showViewModel", Qt::QueuedConnection,
Q_ARG(const QMetaObject*, metaObject), Q_ARG(const QMetaObject*, metaObject),
Q_ARG(QVariantHash, params), Q_ARG(QVariantHash, std::move(params)),
Q_ARG(QPointer<ViewModel>, parent), Q_ARG(QPointer<ViewModel>, std::move(parent)),
Q_ARG(quint32, requestCode)); Q_ARG(quint32, requestCode));
} }
// ------------- Private Implementation -------------
ViewModelPrivate::ViewModelPrivate() {}

16
src/mvvmcore/viewmodel.h

@ -24,7 +24,7 @@ class Q_MVVMCORE_EXPORT ViewModel : public QObject
public: public:
//! Default constructor with parent //! Default constructor with parent
explicit ViewModel(QObject *parent = nullptr); explicit ViewModel(QObject *parent = nullptr);
~ViewModel(); ~ViewModel() override;
public Q_SLOTS: public Q_SLOTS:
//! Called by the presenter to initialize the viewmodel //! Called by the presenter to initialize the viewmodel
@ -39,14 +39,14 @@ Q_SIGNALS:
protected: protected:
//! Show another viewmodel as a child of this one //! Show another viewmodel as a child of this one
template <typename TViewModel> template <typename TViewModel>
inline void show(const QVariantHash &params = {}) const; inline void show(QVariantHash params = {}) const;
//! @copybrief ViewModel::show(const QVariantHash &) const //! @copybrief ViewModel::show(const QVariantHash &) const
void show(const char *viewModelName, const QVariantHash &params = {}) const; void show(const char *viewModelName, const QVariantHash &params = {}) const;
//! @copybrief ViewModel::show(const QVariantHash &) const //! @copybrief ViewModel::show(const QVariantHash &) const
void show(const QMetaObject *viewMetaObject, const QVariantHash &params = {}) const; void show(const QMetaObject *viewMetaObject, const QVariantHash &params = {}) const;
//! Show another viewmodel as a child of this one and expect its result //! Show another viewmodel as a child of this one and expect its result
template <typename TViewModel> template <typename TViewModel>
inline void showForResult(quint32 requestCode, const QVariantHash &params = {}) const; inline void showForResult(quint32 requestCode, QVariantHash params = {}) const;
//! @copybrief ViewModel::showForResult(quint32, const QVariantHash &) const //! @copybrief ViewModel::showForResult(quint32, const QVariantHash &) const
void showForResult(quint32 requestCode, const char *viewModelName, const QVariantHash &params = {}) const; void showForResult(quint32 requestCode, const char *viewModelName, const QVariantHash &params = {}) const;
//! @copybrief ViewModel::showForResult(quint32, const QVariantHash &) const //! @copybrief ViewModel::showForResult(quint32, const QVariantHash &) const
@ -57,23 +57,23 @@ private:
QScopedPointer<ViewModelPrivate> d; QScopedPointer<ViewModelPrivate> d;
static void showImp(const QMetaObject *metaObject, const QVariantHash &params, QPointer<ViewModel> parent, quint32 requestCode = 0); static void showImp(const QMetaObject *metaObject, QVariantHash params, QPointer<ViewModel> parent, quint32 requestCode = 0);
}; };
// ------------- Generic Implementation ------------- // ------------- Generic Implementation -------------
template<typename TViewModel> template<typename TViewModel>
inline void ViewModel::show(const QVariantHash &params) const inline void ViewModel::show(QVariantHash params) const
{ {
static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel"); static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel");
showImp(&TViewModel::staticMetaObject, params, const_cast<ViewModel*>(this)); showImp(&TViewModel::staticMetaObject, std::move(params), const_cast<ViewModel*>(this));
} }
template<typename TViewModel> template<typename TViewModel>
void ViewModel::showForResult(quint32 requestCode, const QVariantHash &params) const void ViewModel::showForResult(quint32 requestCode, QVariantHash params) const
{ {
static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel"); static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel");
showImp(&TViewModel::staticMetaObject, params, const_cast<ViewModel*>(this), requestCode); showImp(&TViewModel::staticMetaObject, std::move(params), const_cast<ViewModel*>(this), requestCode);
} }
} }

6
src/mvvmcore/viewmodel_p.h

@ -6,11 +6,7 @@
namespace QtMvvm { namespace QtMvvm {
class ViewModelPrivate class ViewModelPrivate {};
{
public:
ViewModelPrivate();
};
} }

2
src/mvvmdatasynccore/accountmodel.cpp

@ -18,7 +18,7 @@ AccountModel::AccountModel(QObject *parent) :
d(new AccountModelPrivate()) d(new AccountModelPrivate())
{} {}
AccountModel::~AccountModel() {} AccountModel::~AccountModel() = default;
void AccountModel::setup(AccountManager *accountManager, SyncManager *syncManager) void AccountModel::setup(AccountManager *accountManager, SyncManager *syncManager)
{ {

2
src/mvvmdatasynccore/accountmodel.h

@ -27,7 +27,7 @@ public:
//! Default constructor //! Default constructor
explicit AccountModel(QObject *parent = nullptr); explicit AccountModel(QObject *parent = nullptr);
~AccountModel(); ~AccountModel() override;
//! Setups up the model to use the account and a sync manager. Automatically loads devices //! Setups up the model to use the account and a sync manager. Automatically loads devices
Q_INVOKABLE void setup(QtDataSync::AccountManager *accountManager, Q_INVOKABLE void setup(QtDataSync::AccountManager *accountManager,

12
src/mvvmdatasynccore/changeremoteviewmodel.cpp

@ -11,10 +11,6 @@ std::tuple<RemoteConfig, bool> ChangeRemoteViewModel::result(const QVariant &dat
ChangeRemoteViewModel::ChangeRemoteViewModel(QObject *parent) : ChangeRemoteViewModel::ChangeRemoteViewModel(QObject *parent) :
ViewModel(parent), ViewModel(parent),
_url(),
_accessKey(),
_keepAlive(),
_keepData(true),
_headerModel(new QStandardItemModel(0, 2, this)) _headerModel(new QStandardItemModel(0, 2, this))
{ {
_headerModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")}); _headerModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")});
@ -83,21 +79,21 @@ bool ChangeRemoteViewModel::completeSetup()
return true; return true;
} }
void ChangeRemoteViewModel::setUrl(const QUrl &url) void ChangeRemoteViewModel::setUrl(QUrl url)
{ {
if (_url == url) if (_url == url)
return; return;
_url = url; _url = std::move(url);
emit urlChanged(_url); emit urlChanged(_url);
} }
void ChangeRemoteViewModel::setAccessKey(const QString &accessKey) void ChangeRemoteViewModel::setAccessKey(QString accessKey)
{ {
if (_accessKey == accessKey) if (_accessKey == accessKey)
return; return;
_accessKey = accessKey; _accessKey = std::move(accessKey);
emit accessKeyChanged(_accessKey); emit accessKeyChanged(_accessKey);
} }

8
src/mvvmdatasynccore/changeremoteviewmodel_p.h

@ -44,8 +44,8 @@ public:
public Q_SLOTS: public Q_SLOTS:
bool completeSetup(); bool completeSetup();
void setUrl(const QUrl &url); void setUrl(QUrl url);
void setAccessKey(const QString &accessKey); void setAccessKey(QString accessKey);
void setKeepAlive(int keepAlive); void setKeepAlive(int keepAlive);
void setKeepData(bool keepData); void setKeepData(bool keepData);
@ -62,8 +62,8 @@ Q_SIGNALS:
private: private:
QUrl _url; QUrl _url;
QString _accessKey; QString _accessKey;
int _keepAlive; int _keepAlive = 1;
bool _keepData; bool _keepData = true;
QStandardItemModel *_headerModel; QStandardItemModel *_headerModel;
}; };

34
src/mvvmdatasynccore/datasyncviewmodel.cpp

@ -58,7 +58,7 @@ DataSyncViewModel::DataSyncViewModel(QObject *parent) :
resetColorMap(); resetColorMap();
} }
DataSyncViewModel::~DataSyncViewModel() {} DataSyncViewModel::~DataSyncViewModel() = default;
SyncManager *DataSyncViewModel::syncManager() const SyncManager *DataSyncViewModel::syncManager() const
{ {
@ -115,6 +115,7 @@ QSortFilterProxyModel *DataSyncViewModel::sortedModel() const
QString DataSyncViewModel::formatFingerPrint(const QByteArray &fingerPrint) QString DataSyncViewModel::formatFingerPrint(const QByteArray &fingerPrint)
{ {
QByteArrayList res; QByteArrayList res;
res.reserve(fingerPrint.size());
for(char c : fingerPrint) for(char c : fingerPrint)
res.append(QByteArray(1, c).toHex().toUpper()); res.append(QByteArray(1, c).toHex().toUpper());
return QString::fromUtf8(res.join(':')); return QString::fromUtf8(res.join(':'));
@ -148,7 +149,7 @@ void DataSyncViewModel::startExport()
void DataSyncViewModel::startImport() void DataSyncViewModel::startImport()
{ {
auto home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); auto home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
getOpenFile(this, [this](QUrl url) { getOpenFile(this, [this](const QUrl &url) {
if(url.isValid()) { if(url.isValid()) {
logDebug() << "Importing from URL" << url; logDebug() << "Importing from URL" << url;
@ -168,8 +169,7 @@ void DataSyncViewModel::startImport()
if(!device->open(QIODevice::ReadOnly | QIODevice::Text)) { if(!device->open(QIODevice::ReadOnly | QIODevice::Text)) {
critical(tr("Import failed"), critical(tr("Import failed"),
tr("Failed to open URL \"%1\" with error: %2") tr("Failed to open URL \"%1\" with error: %2")
.arg(url.toString()) .arg(url.toString(), device->errorString()));
.arg(device->errorString()));
return; return;
} }
auto data = device->readAll(); auto data = device->readAll();
@ -275,7 +275,7 @@ void DataSyncViewModel::setColorMap(DataSyncViewModel::ColorMap colorMap)
if (d->colorMap == colorMap) if (d->colorMap == colorMap)
return; return;
d->colorMap = colorMap; d->colorMap = std::move(colorMap);
emit colorMapChanged(d->colorMap, {}); emit colorMapChanged(d->colorMap, {});
} }
@ -303,9 +303,8 @@ void DataSyncViewModel::showImportDialog(LoginRequest request)
"<p>Name: %1<br/>" "<p>Name: %1<br/>"
"Fingerprint: %2</p>" "Fingerprint: %2</p>"
"<p>Do you want accept the request?</p>") "<p>Do you want accept the request?</p>")
.arg(request.device().name()) .arg(request.device().name(), formatFingerPrint(request.device().fingerprint())),
.arg(formatFingerPrint(request.device().fingerprint())), this, [request](bool ok) {
this, [this, request](bool ok) {
auto req = request; auto req = request;
if(!req.handled()) { if(!req.handled()) {
if(ok) if(ok)
@ -331,14 +330,13 @@ void DataSyncViewModel::showAccessGranted(const QUuid &id)
void DataSyncViewModel::triggerGranted(const QList<DeviceInfo> &devices) void DataSyncViewModel::triggerGranted(const QList<DeviceInfo> &devices)
{ {
for(auto device : devices) { for(const auto &device : devices) {
if(d->pendingGrants.remove(device.deviceId())) { if(d->pendingGrants.remove(device.deviceId())) {
information(tr("Account access granted"), information(tr("Account access granted"),
tr("<p>Account access has been granted to device:</p>" tr("<p>Account access has been granted to device:</p>"
"<p>Name: %1<br/>" "<p>Name: %1<br/>"
"Fingerprint: %2</p>") "Fingerprint: %2</p>")
.arg(device.name()) .arg(device.name(), formatFingerPrint(device.fingerprint())));
.arg(formatFingerPrint(device.fingerprint())));
} }
} }
} }
@ -410,9 +408,6 @@ void DataSyncViewModel::onResult(quint32 requestCode, const QVariant &result)
QtMvvm::DataSyncViewModelPrivate::DataSyncViewModelPrivate(DataSyncViewModel *q_ptr) : QtMvvm::DataSyncViewModelPrivate::DataSyncViewModelPrivate(DataSyncViewModel *q_ptr) :
q(q_ptr), q(q_ptr),
syncManager(nullptr),
accountManager(nullptr),
colorMap(),
accountModel(new AccountModel(q_ptr)), accountModel(new AccountModel(q_ptr)),
sortedModel(new QSortFilterProxyModel(q_ptr)) sortedModel(new QSortFilterProxyModel(q_ptr))
{} {}
@ -420,7 +415,7 @@ QtMvvm::DataSyncViewModelPrivate::DataSyncViewModelPrivate(DataSyncViewModel *q_
void DataSyncViewModelPrivate::performExport(bool trusted, bool includeServer, const QString &password) void DataSyncViewModelPrivate::performExport(bool trusted, bool includeServer, const QString &password)
{ {
auto home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); auto home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
getSaveFile(q, [this, trusted, includeServer, password](QUrl url) { getSaveFile(q, [this, trusted, includeServer, password](const QUrl &url) {
if(url.isValid()) { if(url.isValid()) {
logDebug() << "Exporting to URL" << url; logDebug() << "Exporting to URL" << url;
@ -441,13 +436,12 @@ void DataSyncViewModelPrivate::performExport(bool trusted, bool includeServer, c
if(!device->open(QIODevice::WriteOnly | QIODevice::Text)) { if(!device->open(QIODevice::WriteOnly | QIODevice::Text)) {
critical(DataSyncViewModel::tr("Export failed"), critical(DataSyncViewModel::tr("Export failed"),
DataSyncViewModel::tr("Failed to open URL \"%1\" with error: %2") DataSyncViewModel::tr("Failed to open URL \"%1\" with error: %2")
.arg(url.toString()) .arg(url.toString(), device->errorString()));
.arg(device->errorString()));
return; return;
} }
QPointer<DataSyncViewModel> qPtr(q); QPointer<DataSyncViewModel> qPtr(q);
auto resFn = [this, qPtr, device](QByteArray data) { auto resFn = [qPtr, device](const QByteArray &data) {
if(!qPtr) if(!qPtr)
return; return;
device->write(data); device->write(data);
@ -455,7 +449,7 @@ void DataSyncViewModelPrivate::performExport(bool trusted, bool includeServer, c
information(DataSyncViewModel::tr("Export completed"), information(DataSyncViewModel::tr("Export completed"),
DataSyncViewModel::tr("Data was successfully exported.")); DataSyncViewModel::tr("Data was successfully exported."));
}; };
auto errFn = [this, qPtr, device](QString error){ auto errFn = [qPtr, device](const QString &error){
if(!qPtr) if(!qPtr)
return; return;
critical(DataSyncViewModel::tr("Export failed"), error); critical(DataSyncViewModel::tr("Export failed"), error);
@ -474,7 +468,7 @@ void DataSyncViewModelPrivate::performExport(bool trusted, bool includeServer, c
void DataSyncViewModelPrivate::performImport(bool trusted, const QString &password, const QByteArray &data, bool keepData) void DataSyncViewModelPrivate::performImport(bool trusted, const QString &password, const QByteArray &data, bool keepData)
{ {
QPointer<DataSyncViewModel> qPtr(q); QPointer<DataSyncViewModel> qPtr(q);
auto resFn = [this, qPtr](bool ok, QString error) { auto resFn = [qPtr](bool ok, const QString &error) {
if(!qPtr) if(!qPtr)
return; return;
if(ok) { if(ok) {

4
src/mvvmdatasynccore/datasyncviewmodel.h

@ -40,7 +40,7 @@ class Q_MVVMDATASYNCCORE_EXPORT DataSyncViewModel : public ViewModel
public: public:
//! A mapping from sync states to a text color //! A mapping from sync states to a text color
typedef QMap<QtDataSync::SyncManager::SyncState, QColor> ColorMap; using ColorMap = QMap<QtDataSync::SyncManager::SyncState, QColor>;
//! The parameter for a setup name for the onInit() method //! The parameter for a setup name for the onInit() method
static const QString paramSetup; static const QString paramSetup;
@ -54,7 +54,7 @@ public:
//! Invokable constructor //! Invokable constructor
Q_INVOKABLE explicit DataSyncViewModel(QObject *parent = nullptr); Q_INVOKABLE explicit DataSyncViewModel(QObject *parent = nullptr);
~DataSyncViewModel(); ~DataSyncViewModel() override;
//! @readAcFn{DataSyncViewModel::syncManager} //! @readAcFn{DataSyncViewModel::syncManager}
QtDataSync::SyncManager* syncManager() const; QtDataSync::SyncManager* syncManager() const;

4
src/mvvmdatasynccore/datasyncviewmodel_p.h

@ -17,8 +17,8 @@ public:
DataSyncViewModelPrivate(DataSyncViewModel *q_ptr); DataSyncViewModelPrivate(DataSyncViewModel *q_ptr);
DataSyncViewModel *q; DataSyncViewModel *q;
QtDataSync::SyncManager *syncManager; QtDataSync::SyncManager *syncManager = nullptr;
QtDataSync::AccountManager *accountManager; QtDataSync::AccountManager *accountManager = nullptr;
DataSyncViewModel::ColorMap colorMap; DataSyncViewModel::ColorMap colorMap;
AccountModel *accountModel; AccountModel *accountModel;
QSortFilterProxyModel *sortedModel; QSortFilterProxyModel *sortedModel;

7
src/mvvmdatasynccore/exchangedevicesmodel.cpp

@ -23,7 +23,7 @@ ExchangeDevicesModel::ExchangeDevicesModel(QObject *parent) :
d(new ExchangeDevicesModelPrivate()) d(new ExchangeDevicesModelPrivate())
{} {}
ExchangeDevicesModel::~ExchangeDevicesModel() {} ExchangeDevicesModel::~ExchangeDevicesModel() = default;
void ExchangeDevicesModel::setup(QtDataSync::UserExchangeManager *exchangeManager) void ExchangeDevicesModel::setup(QtDataSync::UserExchangeManager *exchangeManager)
{ {
@ -34,7 +34,7 @@ void ExchangeDevicesModel::setup(QtDataSync::UserExchangeManager *exchangeManage
d->exchangeManager = exchangeManager; d->exchangeManager = exchangeManager;
d->devices.clear(); d->devices.clear();
d->devices.reserve(d->exchangeManager->devices().size()); d->devices.reserve(d->exchangeManager->devices().size());
for(auto device : d->exchangeManager->devices()) for(const auto &device : d->exchangeManager->devices())
d->devices.append(device); d->devices.append(device);
endResetModel(); endResetModel();
@ -149,7 +149,8 @@ void ExchangeDevicesModel::updateDevices(const QList<UserInfo> &devices)
{ {
//find new devices and update existing //find new devices and update existing
QList<ExchangeDevicesModelPrivate::LimitedUserInfo> addList; QList<ExchangeDevicesModelPrivate::LimitedUserInfo> addList;
for(auto device : devices) { addList.reserve(devices.size());
for(const auto &device : devices) {
auto dIndex = d->devices.indexOf(device); auto dIndex = d->devices.indexOf(device);
if(dIndex != -1) { if(dIndex != -1) {
if(device.name() != d->devices[dIndex].name()) { if(device.name() != d->devices[dIndex].name()) {

2
src/mvvmdatasynccore/exchangedevicesmodel.h

@ -28,7 +28,7 @@ public:
//! Default constructor //! Default constructor
explicit ExchangeDevicesModel(QObject *parent = nullptr); explicit ExchangeDevicesModel(QObject *parent = nullptr);
~ExchangeDevicesModel(); ~ExchangeDevicesModel() override;
//! Setups up the model to use the exchange manager. Automatically displays all devices of the manager //! Setups up the model to use the exchange manager. Automatically displays all devices of the manager
Q_INVOKABLE void setup(QtDataSync::UserExchangeManager *exchangeManager); Q_INVOKABLE void setup(QtDataSync::UserExchangeManager *exchangeManager);

8
src/mvvmdatasynccore/exportsetupviewmodel.cpp

@ -17,11 +17,7 @@ std::tuple<bool, bool, QString> ExportSetupViewModel::result(const QVariant &dat
} }
ExportSetupViewModel::ExportSetupViewModel(QObject *parent) : ExportSetupViewModel::ExportSetupViewModel(QObject *parent) :
ViewModel(parent), ViewModel(parent)
_label(),
_trusted(false),
_password(),
_includeServer(false)
{ {
connect(this, &ExportSetupViewModel::trustedChanged, connect(this, &ExportSetupViewModel::trustedChanged,
this, &ExportSetupViewModel::validChanged); this, &ExportSetupViewModel::validChanged);
@ -90,7 +86,7 @@ void ExportSetupViewModel::setPassword(QString password)
if (_password == password) if (_password == password)
return; return;
_password = password; _password = std::move(password);
emit passwordChanged(_password); emit passwordChanged(_password);
} }

4
src/mvvmdatasynccore/exportsetupviewmodel_p.h

@ -51,9 +51,9 @@ protected:
private: private:
QString _label; QString _label;
bool _trusted; bool _trusted = false;
QString _password; QString _password;
bool _includeServer; bool _includeServer = false;
}; };
} }

7
src/mvvmdatasynccore/identityeditviewmodel.cpp

@ -4,8 +4,7 @@ using namespace QtMvvm;
using namespace QtDataSync; using namespace QtDataSync;
IdentityEditViewModel::IdentityEditViewModel(QObject *parent) : IdentityEditViewModel::IdentityEditViewModel(QObject *parent) :
ViewModel(parent), ViewModel(parent)
_manager(nullptr)
{ {
connect(this, &IdentityEditViewModel::nameChanged, connect(this, &IdentityEditViewModel::nameChanged,
this, &IdentityEditViewModel::validChanged); this, &IdentityEditViewModel::validChanged);
@ -41,12 +40,12 @@ void IdentityEditViewModel::save()
_manager->setDeviceName(_nameBuffer); _manager->setDeviceName(_nameBuffer);
} }
void IdentityEditViewModel::setName(const QString &name) void IdentityEditViewModel::setName(QString name)
{ {
if (_nameBuffer == name) if (_nameBuffer == name)
return; return;
_nameBuffer = name; _nameBuffer = std::move(name);
emit nameChanged(_nameBuffer); emit nameChanged(_nameBuffer);
} }

4
src/mvvmdatasynccore/identityeditviewmodel_p.h

@ -29,7 +29,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
void save(); void save();
void setName(const QString &name); void setName(QString name);
Q_SIGNALS: Q_SIGNALS:
void nameChanged(const QString &name); void nameChanged(const QString &name);
@ -40,7 +40,7 @@ protected:
void onInit(const QVariantHash &showParams) override; void onInit(const QVariantHash &showParams) override;
private: private:
QtDataSync::AccountManager *_manager; QtDataSync::AccountManager *_manager = nullptr;
QString _nameBuffer; QString _nameBuffer;
}; };

22
src/mvvmdatasynccore/networkexchangeviewmodel.cpp

@ -45,7 +45,7 @@ NetworkExchangeViewModel::NetworkExchangeViewModel(QObject *parent) :
d->sortedModel->setSourceModel(d->deviceModel); d->sortedModel->setSourceModel(d->deviceModel);
} }
NetworkExchangeViewModel::~NetworkExchangeViewModel() {} NetworkExchangeViewModel::~NetworkExchangeViewModel() = default;
UserExchangeManager *NetworkExchangeViewModel::userExchangeManager() const UserExchangeManager *NetworkExchangeViewModel::userExchangeManager() const
{ {
@ -91,8 +91,7 @@ void NetworkExchangeViewModel::exportTo(int sortedIndex)
d->activeExports.insert(exCode, info); d->activeExports.insert(exCode, info);
showForResult<ExportSetupViewModel>(exCode, showForResult<ExportSetupViewModel>(exCode,
ExportSetupViewModel::showParams(tr("Export accont data to device \"%1\" with address \"%1\":") ExportSetupViewModel::showParams(tr("Export accont data to device \"%1\" with address \"%1\":")
.arg(info.name()) .arg(info.name(), ExchangeDevicesModel::fullAddress(info))));
.arg(ExchangeDevicesModel::fullAddress(info))));
} }
} }
@ -111,7 +110,7 @@ void NetworkExchangeViewModel::setDeviceName(QString deviceName)
this->deviceName() == deviceName) this->deviceName() == deviceName)
return; return;
d->exchangeManager->accountManager()->setDeviceName(deviceName); d->exchangeManager->accountManager()->setDeviceName(std::move(deviceName));
} }
void NetworkExchangeViewModel::setActive(bool active) void NetworkExchangeViewModel::setActive(bool active)
@ -136,7 +135,7 @@ void NetworkExchangeViewModel::onInit(const QVariantHash &params)
} }
connect(d->exchangeManager->accountManager(), &AccountManager::deviceNameChanged, connect(d->exchangeManager->accountManager(), &AccountManager::deviceNameChanged,
this, PSIGARG(&NetworkExchangeViewModel::deviceNameChanged, QString)); this, PSIGARG(&NetworkExchangeViewModel::deviceNameChanged, const QString &));
connect(d->exchangeManager, &UserExchangeManager::userDataReceived, connect(d->exchangeManager, &UserExchangeManager::userDataReceived,
this, &NetworkExchangeViewModel::newUserData); this, &NetworkExchangeViewModel::newUserData);
connect(d->exchangeManager, &UserExchangeManager::exchangeError, connect(d->exchangeManager, &UserExchangeManager::exchangeError,
@ -179,7 +178,7 @@ void NetworkExchangeViewModel::exchangeError(const QString &errorString)
void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool trusted) void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool trusted)
{ {
QPointer<NetworkExchangeViewModel> qPtr(this); QPointer<NetworkExchangeViewModel> qPtr(this);
auto importDoneHandler = [this, qPtr](bool ok, QString error) { auto importDoneHandler = [qPtr](bool ok, const QString &error) {
if(!qPtr) if(!qPtr)
return; return;
if(ok) { if(ok) {
@ -194,8 +193,7 @@ void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool truste
config.setTitle(tr("Import account data")) config.setTitle(tr("Import account data"))
.setText(tr("Enter the password to decrypt the account data received from \"%1\" with address \"%2\". " .setText(tr("Enter the password to decrypt the account data received from \"%1\" with address \"%2\". "
"Then choose whether you want to keep you local data or not:") "Then choose whether you want to keep you local data or not:")
.arg(userInfo.name()) .arg(userInfo.name(), ExchangeDevicesModel::fullAddress(userInfo)))
.arg(ExchangeDevicesModel::fullAddress(userInfo)))
.setButtons(MessageConfig::YesToAll | MessageConfig::Yes | MessageConfig::Cancel) .setButtons(MessageConfig::YesToAll | MessageConfig::Yes | MessageConfig::Cancel)
.setButtonText(MessageConfig::YesToAll, tr("Reset data")) .setButtonText(MessageConfig::YesToAll, tr("Reset data"))
.setButtonText(MessageConfig::Yes, tr("Keep data")) .setButtonText(MessageConfig::Yes, tr("Keep data"))
@ -222,8 +220,7 @@ void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool truste
config.setTitle(tr("Import account data")) config.setTitle(tr("Import account data"))
.setText(tr("Do you want to import data received from \"%1\" with address \"%2\"? " .setText(tr("Do you want to import data received from \"%1\" with address \"%2\"? "
"Keep the local data after changing the account?") "Keep the local data after changing the account?")
.arg(userInfo.name()) .arg(userInfo.name(), ExchangeDevicesModel::fullAddress(userInfo)))
.arg(ExchangeDevicesModel::fullAddress(userInfo)))
.setButtons(MessageConfig::YesToAll | MessageConfig::Yes | MessageConfig::Cancel) .setButtons(MessageConfig::YesToAll | MessageConfig::Yes | MessageConfig::Cancel)
.setButtonText(MessageConfig::YesToAll, tr("Reset data")) .setButtonText(MessageConfig::YesToAll, tr("Reset data"))
.setButtonText(MessageConfig::Yes, tr("Keep data")); .setButtonText(MessageConfig::Yes, tr("Keep data"));
@ -248,9 +245,6 @@ void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool truste
// ------------- Private Implementation ------------- // ------------- Private Implementation -------------
NetworkExchangeViewModelPrivate::NetworkExchangeViewModelPrivate(NetworkExchangeViewModel *q_ptr) : NetworkExchangeViewModelPrivate::NetworkExchangeViewModelPrivate(NetworkExchangeViewModel *q_ptr) :
exchangeManager(nullptr),
deviceModel(new ExchangeDevicesModel(q_ptr)), deviceModel(new ExchangeDevicesModel(q_ptr)),
sortedModel(new QSortFilterProxyModel(q_ptr)), sortedModel(new QSortFilterProxyModel(q_ptr))
port(UserExchangeManager::DataExchangePort),
activeExports()
{} {}

2
src/mvvmdatasynccore/networkexchangeviewmodel.h

@ -46,7 +46,7 @@ public:
//! Invokable constructor //! Invokable constructor
Q_INVOKABLE explicit NetworkExchangeViewModel(QObject *parent = nullptr); Q_INVOKABLE explicit NetworkExchangeViewModel(QObject *parent = nullptr);
~NetworkExchangeViewModel(); ~NetworkExchangeViewModel() override;
//! @readAcFn{NetworkExchangeViewModel::userExchangeManager} //! @readAcFn{NetworkExchangeViewModel::userExchangeManager}
QtDataSync::UserExchangeManager* userExchangeManager() const; QtDataSync::UserExchangeManager* userExchangeManager() const;

6
src/mvvmdatasynccore/networkexchangeviewmodel_p.h

@ -1,6 +1,8 @@
#ifndef QTMVVM_NETWORKEXCHANGEVIEWMODEL_P_H #ifndef QTMVVM_NETWORKEXCHANGEVIEWMODEL_P_H
#define QTMVVM_NETWORKEXCHANGEVIEWMODEL_P_H #define QTMVVM_NETWORKEXCHANGEVIEWMODEL_P_H
#include <QtDataSync/UserExchangeManager>
#include "qtmvvmdatasynccore_global.h" #include "qtmvvmdatasynccore_global.h"
#include "networkexchangeviewmodel.h" #include "networkexchangeviewmodel.h"
@ -13,10 +15,10 @@ public:
NetworkExchangeViewModelPrivate(NetworkExchangeViewModel *q_ptr); NetworkExchangeViewModelPrivate(NetworkExchangeViewModel *q_ptr);
QtDataSync::UserExchangeManager *exchangeManager; QtDataSync::UserExchangeManager *exchangeManager = nullptr;
ExchangeDevicesModel *deviceModel; ExchangeDevicesModel *deviceModel;
QSortFilterProxyModel *sortedModel; QSortFilterProxyModel *sortedModel;
quint16 port; quint16 port = QtDataSync::UserExchangeManager::DataExchangePort;
QHash<quint32, QtDataSync::UserInfo> activeExports; QHash<quint32, QtDataSync::UserInfo> activeExports;
}; };

2
src/mvvmdatasyncwidgets/changeremotedialog.cpp

@ -50,7 +50,7 @@ ChangeRemoteDialog::ChangeRemoteDialog(ViewModel *viewModel, QWidget *parent) :
ui->treeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); ui->treeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
} }
ChangeRemoteDialog::~ChangeRemoteDialog() {} ChangeRemoteDialog::~ChangeRemoteDialog() = default;
void ChangeRemoteDialog::accept() void ChangeRemoteDialog::accept()
{ {

2
src/mvvmdatasyncwidgets/changeremotedialog_p.h

@ -21,7 +21,7 @@ class Q_MVVMDATASYNCWIDGETS_EXPORT ChangeRemoteDialog : public QDialog
public: public:
Q_INVOKABLE explicit ChangeRemoteDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); Q_INVOKABLE explicit ChangeRemoteDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);
~ChangeRemoteDialog(); ~ChangeRemoteDialog() override;
public Q_SLOTS: public Q_SLOTS:
void accept() override; void accept() override;

2
src/mvvmdatasyncwidgets/datasyncwindow.cpp

@ -42,7 +42,7 @@ DataSyncWindow::DataSyncWindow(QtMvvm::ViewModel *viewModel, QWidget *parent) :
this, &DataSyncWindow::viewModelReady); this, &DataSyncWindow::viewModelReady);
} }
DataSyncWindow::~DataSyncWindow() {} DataSyncWindow::~DataSyncWindow() = default;
double DataSyncWindow::syncProgress() const double DataSyncWindow::syncProgress() const
{ {

2
src/mvvmdatasyncwidgets/datasyncwindow.h

@ -25,7 +25,7 @@ class Q_MVVMDATASYNCWIDGETS_EXPORT DataSyncWindow : public QWidget
public: public:
//! View constructor //! View constructor
Q_INVOKABLE explicit DataSyncWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); Q_INVOKABLE explicit DataSyncWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);
~DataSyncWindow(); ~DataSyncWindow() override;
//! @readAcFn{DataSyncWindow::syncProgress} //! @readAcFn{DataSyncWindow::syncProgress}
double syncProgress() const; double syncProgress() const;

2
src/mvvmdatasyncwidgets/exportsetupdialog.cpp

@ -33,7 +33,7 @@ ExportSetupDialog::ExportSetupDialog(ViewModel *viewModel, QWidget *parent) :
Binding::OneWayToView); Binding::OneWayToView);
} }
ExportSetupDialog::~ExportSetupDialog() {} ExportSetupDialog::~ExportSetupDialog() = default;
void ExportSetupDialog::accept() void ExportSetupDialog::accept()
{ {

2
src/mvvmdatasyncwidgets/exportsetupdialog_p.h

@ -21,7 +21,7 @@ class Q_MVVMDATASYNCWIDGETS_EXPORT ExportSetupDialog : public QDialog
public: public:
Q_INVOKABLE explicit ExportSetupDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); Q_INVOKABLE explicit ExportSetupDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);
~ExportSetupDialog(); ~ExportSetupDialog() override;
public Q_SLOTS: public Q_SLOTS:
void accept() override; void accept() override;

2
src/mvvmdatasyncwidgets/identityeditdialog.cpp

@ -30,7 +30,7 @@ IdentityEditDialog::IdentityEditDialog(ViewModel *viewModel, QWidget *parent) :
Binding::OneWayToView); Binding::OneWayToView);
} }
IdentityEditDialog::~IdentityEditDialog() {} IdentityEditDialog::~IdentityEditDialog() = default;
void IdentityEditDialog::accept() void IdentityEditDialog::accept()
{ {

2
src/mvvmdatasyncwidgets/identityeditdialog_p.h

@ -21,7 +21,7 @@ class Q_MVVMDATASYNCWIDGETS_EXPORT IdentityEditDialog : public QDialog
public: public:
Q_INVOKABLE explicit IdentityEditDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); Q_INVOKABLE explicit IdentityEditDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);
~IdentityEditDialog(); ~IdentityEditDialog() override;
public Q_SLOTS: public Q_SLOTS:
void accept() override; void accept() override;

4
src/mvvmdatasyncwidgets/networkexchangewindow.cpp

@ -21,12 +21,12 @@ NetworkExchangeWindow::NetworkExchangeWindow(ViewModel *viewModel, QWidget *pare
nullptr, "editingFinished()"); nullptr, "editingFinished()");
bind(d->viewModel, "active", bind(d->viewModel, "active",
d->ui->exchangeCheckBox, "checked", d->ui->exchangeCheckBox, "checked",
Binding::OneWayToViewModel);//NOTE workaround because of buggy active property in datasync Binding::OneWayToViewModel);
d->ui->treeView->setModel(d->viewModel->sortedModel()); d->ui->treeView->setModel(d->viewModel->sortedModel());
} }
NetworkExchangeWindow::~NetworkExchangeWindow() {} NetworkExchangeWindow::~NetworkExchangeWindow() = default;
void NetworkExchangeWindow::activated(const QModelIndex &index) void NetworkExchangeWindow::activated(const QModelIndex &index)
{ {

2
src/mvvmdatasyncwidgets/networkexchangewindow.h

@ -20,7 +20,7 @@ class Q_MVVMDATASYNCWIDGETS_EXPORT NetworkExchangeWindow : public QWidget
public: public:
//! View constructor //! View constructor
Q_INVOKABLE explicit NetworkExchangeWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); Q_INVOKABLE explicit NetworkExchangeWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);
~NetworkExchangeWindow(); ~NetworkExchangeWindow() override;
private Q_SLOTS: private Q_SLOTS:
void activated(const QModelIndex &index); void activated(const QModelIndex &index);

2
src/mvvmquick/inputviewfactory.cpp

@ -15,7 +15,7 @@ InputViewFactory::InputViewFactory(QObject *parent) :
d(new InputViewFactoryPrivate()) d(new InputViewFactoryPrivate())
{} {}
InputViewFactory::~InputViewFactory() {} InputViewFactory::~InputViewFactory() = default;
QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &viewProperties) QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &viewProperties)
{ {

2
src/mvvmquick/inputviewfactory.h

@ -19,7 +19,7 @@ class Q_MVVMQUICK_EXPORT InputViewFactory : public QObject
public: public:
//! Default constructor //! Default constructor
Q_INVOKABLE InputViewFactory(QObject *parent = nullptr); Q_INVOKABLE InputViewFactory(QObject *parent = nullptr);
virtual ~InputViewFactory(); ~InputViewFactory() override;
//! Find the input view URL of the given input type //! Find the input view URL of the given input type
Q_INVOKABLE virtual QUrl getInputUrl(const QByteArray &type, const QVariantMap &viewProperties); Q_INVOKABLE virtual QUrl getInputUrl(const QByteArray &type, const QVariantMap &viewProperties);

13
src/mvvmquick/quickpresenter.cpp

@ -42,7 +42,7 @@ QuickPresenter::QuickPresenter(QObject *parent) :
initResources(); initResources();
} }
QuickPresenter::~QuickPresenter() {} QuickPresenter::~QuickPresenter() = default;
void QuickPresenter::addViewSearchDir(const QString &dirPath) void QuickPresenter::addViewSearchDir(const QString &dirPath)
{ {
@ -124,7 +124,7 @@ QUrl QuickPresenter::findViewUrl(const QMetaObject *viewModelType)
QUrl resUrl; QUrl resUrl;
auto shortest = std::numeric_limits<int>::max(); auto shortest = std::numeric_limits<int>::max();
for(auto dir : qAsConst(d->searchDirs)) { for(const auto &dir : qAsConst(d->searchDirs)) {
QDir searchDir(dir, QDir searchDir(dir,
QStringLiteral("%1*.qml").arg(QString::fromLatin1(cName)), QStringLiteral("%1*.qml").arg(QString::fromLatin1(cName)),
QDir::NoSort, QDir::NoSort,
@ -196,13 +196,6 @@ bool QuickPresenter::nameOrClassContains(const QObject *obj, const QString &cont
// ------------- Private Implementation ------------- // ------------- Private Implementation -------------
QuickPresenterPrivate::QuickPresenterPrivate() :
qmlPresenter(nullptr),
inputViewFactory(nullptr),
explicitMappings(),
searchDirs({QStringLiteral(":/qtmvvm/views")})
{}
QuickPresenter *QuickPresenterPrivate::currentPresenter() QuickPresenter *QuickPresenterPrivate::currentPresenter()
{ {
try { try {
@ -213,7 +206,7 @@ QuickPresenter *QuickPresenterPrivate::currentPresenter()
#endif #endif
return static_cast<QuickPresenter*>(ServiceRegistry::instance()->service<IPresenter>()); return static_cast<QuickPresenter*>(ServiceRegistry::instance()->service<IPresenter>());
} catch(QException &e) { } catch(QException &e) {
qFatal(e.what()); qFatal("%s", e.what());
} }
} }

2
src/mvvmquick/quickpresenter.h

@ -28,7 +28,7 @@ class Q_MVVMQUICK_EXPORT QuickPresenter : public QObject, public IPresenter
public: public:
//! Invokable constructor //! Invokable constructor
Q_INVOKABLE explicit QuickPresenter(QObject *parent = nullptr); Q_INVOKABLE explicit QuickPresenter(QObject *parent = nullptr);
~QuickPresenter(); ~QuickPresenter() override;
//! Register a subclass of the QuickPresenter as the active presenter for the CoreApp //! Register a subclass of the QuickPresenter as the active presenter for the CoreApp
template <typename TPresenter> template <typename TPresenter>

6
src/mvvmquick/quickpresenter_p.h

@ -14,17 +14,15 @@ class Q_MVVMQUICK_EXPORT QuickPresenterPrivate
friend class QtMvvm::QuickPresenter; friend class QtMvvm::QuickPresenter;
public: public:
QuickPresenterPrivate();
static QuickPresenter *currentPresenter(); static QuickPresenter *currentPresenter();
static void setQmlPresenter(QObject *presenter); static void setQmlPresenter(QObject *presenter);
private: private:
QPointer<QObject> qmlPresenter; QPointer<QObject> qmlPresenter;
InputViewFactory *inputViewFactory; InputViewFactory *inputViewFactory = nullptr;
QHash<const QMetaObject *, QUrl> explicitMappings; QHash<const QMetaObject *, QUrl> explicitMappings;
QStringList searchDirs; QStringList searchDirs{QStringLiteral(":/qtmvvm/views")};
}; };
} }

2
src/mvvmwidgets/inputwidgetfactory.cpp

@ -23,7 +23,7 @@ InputWidgetFactory::InputWidgetFactory(QObject *parent) :
d(new InputWidgetFactoryPrivate()) d(new InputWidgetFactoryPrivate())
{} {}
InputWidgetFactory::~InputWidgetFactory() {} InputWidgetFactory::~InputWidgetFactory() = default;
QWidget *InputWidgetFactory::createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties) QWidget *InputWidgetFactory::createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties)
{ {

2
src/mvvmwidgets/inputwidgetfactory.h

@ -21,7 +21,7 @@ class InputWidgetFactory : public QObject
public: public:
//! Default constructor //! Default constructor
Q_INVOKABLE explicit InputWidgetFactory(QObject *parent = nullptr); Q_INVOKABLE explicit InputWidgetFactory(QObject *parent = nullptr);
virtual ~InputWidgetFactory(); ~InputWidgetFactory() override;
//! Create a new input widget of the given input type //! Create a new input widget of the given input type
virtual QWidget *createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties); virtual QWidget *createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties);

2
src/mvvmwidgets/ipresentingview.h

@ -10,7 +10,9 @@ namespace QtMvvm {
//! A simple interface to make it possible for any view to present subviews //! A simple interface to make it possible for any view to present subviews
class Q_MVVMWIDGETS_EXPORT IPresentingView class Q_MVVMWIDGETS_EXPORT IPresentingView
{ {
Q_DISABLE_COPY(IPresentingView)
public: public:
inline IPresentingView() = default;
inline virtual ~IPresentingView() = default; inline virtual ~IPresentingView() = default;
//! Is called to try to present a view //! Is called to try to present a view

2
src/mvvmwidgets/selectcombobox.cpp

@ -48,7 +48,7 @@ void SelectComboBox::setCurrentValue(const QVariant &data)
void SelectComboBox::setListElements(const QVariantList &listElements) void SelectComboBox::setListElements(const QVariantList &listElements)
{ {
clear(); clear();
for(auto item : listElements) { for(const auto &item : listElements) {
if(item.type() == QVariant::String) if(item.type() == QVariant::String)
addItem(item.toString(), item); addItem(item.toString(), item);
else { else {

2
src/mvvmwidgets/selectcombobox_p.h

@ -28,7 +28,7 @@ public Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
void currentValueChanged(); void currentValueChanged();
void listElementsChanged(QVariantList listElements); void listElementsChanged(const QVariantList &listElements);
}; };
} }

30
src/mvvmwidgets/settingsdialog.cpp

@ -58,7 +58,7 @@ SettingsDialog::SettingsDialog(ViewModel *viewModel, QWidget *parent) :
d, &SettingsDialogPrivate::createUi); d, &SettingsDialogPrivate::createUi);
} }
SettingsDialog::~SettingsDialog() {} SettingsDialog::~SettingsDialog() = default;
QString SettingsDialog::labelFilterStyleSheet() const QString SettingsDialog::labelFilterStyleSheet() const
{ {
@ -82,14 +82,10 @@ SettingsDialogPrivate::SettingsDialogPrivate(SettingsDialog *q_ptr, ViewModel *v
QObject(q_ptr), QObject(q_ptr),
q(q_ptr), q(q_ptr),
viewModel(static_cast<SettingsViewModel*>(viewModel)), viewModel(static_cast<SettingsViewModel*>(viewModel)),
ui(new Ui::SettingsDialog()), ui(new Ui::SettingsDialog())
delegate(nullptr),
maxWidthBase(0),
entryMap(),
changedEntries()
{} {}
SettingsDialogPrivate::~SettingsDialogPrivate() {} SettingsDialogPrivate::~SettingsDialogPrivate() = default;
void SettingsDialogPrivate::createUi() void SettingsDialogPrivate::createUi()
{ {
@ -101,7 +97,7 @@ void SettingsDialogPrivate::createUi()
ui->filterLineEdit->setVisible(setup.allowSearch); ui->filterLineEdit->setVisible(setup.allowSearch);
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setVisible(setup.allowRestore && viewModel->canRestoreDefaults()); ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setVisible(setup.allowRestore && viewModel->canRestoreDefaults());
for(auto category : setup.categories) for(const auto &category : qAsConst(setup.categories))
createCategory(category); createCategory(category);
resetListSize(); resetListSize();
@ -121,7 +117,7 @@ void SettingsDialogPrivate::createCategory(const SettingsElements::Category &cat
ui->contentStackWidget->addWidget(tab); ui->contentStackWidget->addWidget(tab);
ui->categoryListWidget->addItem(item); ui->categoryListWidget->addItem(item);
for(auto section : category.sections) for(const auto &section : category.sections)
createSection(section, tab); createSection(section, tab);
} }
@ -148,7 +144,7 @@ void SettingsDialogPrivate::createSection(const SettingsElements::Section &secti
tabWidget->tabBar()->setTabToolTip(index, tooltip); tabWidget->tabBar()->setTabToolTip(index, tooltip);
tabWidget->tabBar()->setTabWhatsThis(index, tooltip); tabWidget->tabBar()->setTabWhatsThis(index, tooltip);
for(auto group : section.groups) for(const auto &group : section.groups)
createGroup(group, scrollContent, layout); createGroup(group, scrollContent, layout);
} }
@ -168,7 +164,7 @@ void SettingsDialogPrivate::createGroup(const SettingsElements::Group &group, QW
groupBox->setLayout(sectionLayout); groupBox->setLayout(sectionLayout);
} }
for(auto entry : group.entries) for(const auto &entry : group.entries)
createEntry(entry, sectionWidget, sectionLayout); createEntry(entry, sectionWidget, sectionLayout);
} }
@ -237,7 +233,7 @@ void SettingsDialogPrivate::saveValues()
void SettingsDialogPrivate::restoreValues() void SettingsDialogPrivate::restoreValues()
{ {
for(auto info : entryMap) for(const auto &info : qAsConst(entryMap))
viewModel->resetValue(info.first.key); viewModel->resetValue(info.first.key);
} }
@ -393,7 +389,7 @@ bool SettingsDialogPrivate::searchInEntry(const QRegularExpression &regex, QLabe
auto keys = entryMap.value(content).first.searchKeys; auto keys = entryMap.value(content).first.searchKeys;
keys.append(label->text()); keys.append(label->text());
for(auto key : keys) { for(const auto &key : keys) {
if(regex.match(key).hasMatch()) { if(regex.match(key).hasMatch()) {
label->setStyleSheet(q->labelFilterStyleSheet()); label->setStyleSheet(q->labelFilterStyleSheet());
return true; return true;
@ -427,8 +423,8 @@ void SettingsDialogPrivate::buttonBoxClicked(QAbstractButton *button)
case QDialogButtonBox::RestoreDefaults: case QDialogButtonBox::RestoreDefaults:
if(viewModel->canRestoreDefaults()) { if(viewModel->canRestoreDefaults()) {
auto result = CoreApp::showDialog(viewModel->restoreConfig()); auto result = CoreApp::showDialog(viewModel->restoreConfig());
connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton result) { connect(result, &MessageResult::dialogDone, this, [this](MessageConfig::StandardButton btnResult) {
if(result == MessageConfig::Yes) { if(btnResult == MessageConfig::Yes) {
restoreValues(); restoreValues();
q->accept(); q->accept();
} }
@ -452,10 +448,10 @@ void SettingsDialogPrivate::filterTextChanged(const QString &searchText)
CategoryItemDelegate::CategoryItemDelegate(const std::function<void(int)> &updateFunc, const QSize &iconSize, int layoutSpacing, QObject *parent) : CategoryItemDelegate::CategoryItemDelegate(std::function<void(int)> updateFunc, QSize iconSize, int layoutSpacing, QObject *parent) :
QStyledItemDelegate(parent), QStyledItemDelegate(parent),
_iconSize(iconSize + QSize(0, layoutSpacing)), _iconSize(iconSize + QSize(0, layoutSpacing)),
_updateFunc(updateFunc) _updateFunc(std::move(updateFunc))
{} {}
QSize CategoryItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const QSize CategoryItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const

2
src/mvvmwidgets/settingsdialog.h

@ -20,7 +20,7 @@ class Q_MVVMWIDGETS_EXPORT SettingsDialog : public QDialog
public: public:
//! View constructor //! View constructor
Q_INVOKABLE explicit SettingsDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); Q_INVOKABLE explicit SettingsDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);
~SettingsDialog(); ~SettingsDialog() override;
protected: protected:
//! Returns the stylesheet used highlight labels found when searching //! Returns the stylesheet used highlight labels found when searching

14
src/mvvmwidgets/settingsdialog_p.h

@ -23,9 +23,11 @@ namespace QtMvvm {
class CategoryItemDelegate : public QStyledItemDelegate class CategoryItemDelegate : public QStyledItemDelegate
{ {
Q_OBJECT
public: public:
CategoryItemDelegate(const std::function<void(int)> &updateFunc, CategoryItemDelegate(std::function<void(int)> updateFunc,
const QSize &iconSize, QSize iconSize,
int layoutSpacing, int layoutSpacing,
QObject *parent = nullptr); QObject *parent = nullptr);
@ -42,17 +44,17 @@ class SettingsDialogPrivate : public QObject
public: public:
SettingsDialogPrivate(SettingsDialog *q_ptr, ViewModel *viewModel); SettingsDialogPrivate(SettingsDialog *q_ptr, ViewModel *viewModel);
~SettingsDialogPrivate(); ~SettingsDialogPrivate() override;
static const QString TabContentId; static const QString TabContentId;
SettingsDialog *q; SettingsDialog *q;
SettingsViewModel *viewModel; SettingsViewModel *viewModel;
QScopedPointer<Ui::SettingsDialog> ui; QScopedPointer<Ui::SettingsDialog> ui;
CategoryItemDelegate *delegate; CategoryItemDelegate *delegate = nullptr;
int maxWidthBase; int maxWidthBase = 0;
typedef QPair<SettingsElements::Entry, QMetaProperty> EntryInfo; using EntryInfo = QPair<SettingsElements::Entry, QMetaProperty>;
QHash<QWidget*, EntryInfo> entryMap; QHash<QWidget*, EntryInfo> entryMap;
QSet<QWidget*> changedEntries; QSet<QWidget*> changedEntries;

18
src/mvvmwidgets/widgetspresenter.cpp

@ -53,7 +53,7 @@ WidgetsPresenter::WidgetsPresenter(QObject *parent) :
initResources(); initResources();
} }
WidgetsPresenter::~WidgetsPresenter() {} WidgetsPresenter::~WidgetsPresenter() = default;
void WidgetsPresenter::registerView(const QMetaObject *viewType) void WidgetsPresenter::registerView(const QMetaObject *viewType)
{ {
@ -148,7 +148,7 @@ const QMetaObject *WidgetsPresenter::findWidgetMetaObject(const QMetaObject *vie
auto shortest = std::numeric_limits<int>::max(); auto shortest = std::numeric_limits<int>::max();
const QMetaObject *res = nullptr; const QMetaObject *res = nullptr;
for(auto metaObject : d->implicitMappings) { for(auto metaObject : qAsConst(d->implicitMappings)) {
QByteArray vName = metaObject->className(); QByteArray vName = metaObject->className();
//strip namespaces //strip namespaces
lIndex = vName.lastIndexOf("::"); lIndex = vName.lastIndexOf("::");
@ -349,7 +349,7 @@ void WidgetsPresenter::presentInputDialog(const MessageConfig &config, QPointer<
dialog->done(btnBox->standardButton(btn)); dialog->done(btnBox->standardButton(btn));
}); });
QObject::connect(dialog, &QDialog::finished, QObject::connect(dialog, &QDialog::finished,
dialog, [dialog, input, property, result](int resCode){ dialog, [input, property, result](int resCode){
if(result) { if(result) {
result->complete(static_cast<MessageConfig::StandardButton>(resCode), result->complete(static_cast<MessageConfig::StandardButton>(resCode),
property.read(input)); property.read(input));
@ -408,7 +408,7 @@ void WidgetsPresenter::presentFileDialog(const MessageConfig &config, QPointer<M
if(isMultiFile) if(isMultiFile)
result->setResult(QVariant::fromValue(dialog->selectedUrls())); result->setResult(QVariant::fromValue(dialog->selectedUrls()));
else if(!dialog->selectedUrls().isEmpty()) else if(!dialog->selectedUrls().isEmpty())
result->setResult(dialog->selectedUrls().first()); result->setResult(dialog->selectedUrls().value(0));
result->complete(MessageConfig::Ok); result->complete(MessageConfig::Ok);
} else } else
result->complete(MessageConfig::Cancel); result->complete(MessageConfig::Cancel);
@ -431,9 +431,7 @@ void WidgetsPresenter::presentOtherDialog(const MessageConfig &config, QPointer<
// ------------- Private Implementation ------------- // ------------- Private Implementation -------------
WidgetsPresenterPrivate::WidgetsPresenterPrivate() : WidgetsPresenterPrivate::WidgetsPresenterPrivate() :
inputViewFactory(nullptr), implicitMappings{&SettingsDialog::staticMetaObject}
implicitMappings({&SettingsDialog::staticMetaObject}),
explicitMappings()
{} {}
WidgetsPresenter *WidgetsPresenterPrivate::currentPresenter() WidgetsPresenter *WidgetsPresenterPrivate::currentPresenter()
@ -446,11 +444,11 @@ WidgetsPresenter *WidgetsPresenterPrivate::currentPresenter()
#endif #endif
return static_cast<WidgetsPresenter*>(ServiceRegistry::instance()->service<IPresenter>()); return static_cast<WidgetsPresenter*>(ServiceRegistry::instance()->service<IPresenter>());
} catch(QException &e) { } catch(QException &e) {
qFatal(e.what()); qFatal("%s", e.what());
} }
} }
QValidator *QtMvvm::createUrlValidator(const QStringList &schemes, QObject *parent) QValidator *QtMvvm::createUrlValidator(QStringList schemes, QObject *parent)
{ {
return new QUrlValidator(schemes, parent); return new QUrlValidator(std::move(schemes), parent);
} }

2
src/mvvmwidgets/widgetspresenter.h

@ -28,7 +28,7 @@ class Q_MVVMWIDGETS_EXPORT WidgetsPresenter : public QObject, public IPresenter
public: public:
//! Invokable constructor //! Invokable constructor
Q_INVOKABLE explicit WidgetsPresenter(QObject *parent = nullptr); Q_INVOKABLE explicit WidgetsPresenter(QObject *parent = nullptr);
~WidgetsPresenter(); ~WidgetsPresenter() override;
//! Register a subclass of the WidgetsPresenter as the active presenter for the CoreApp //! Register a subclass of the WidgetsPresenter as the active presenter for the CoreApp
template <typename TPresenter> template <typename TPresenter>

4
src/mvvmwidgets/widgetspresenter_p.h

@ -17,12 +17,12 @@ public:
static WidgetsPresenter *currentPresenter(); static WidgetsPresenter *currentPresenter();
InputWidgetFactory* inputViewFactory; InputWidgetFactory* inputViewFactory = nullptr;
QSet<const QMetaObject*> implicitMappings; QSet<const QMetaObject*> implicitMappings;
QHash<const QMetaObject*, const QMetaObject*> explicitMappings; QHash<const QMetaObject*, const QMetaObject*> explicitMappings;
}; };
Q_MVVMWIDGETS_EXPORT QValidator *createUrlValidator(const QStringList &schemes, QObject* parent = nullptr); Q_MVVMWIDGETS_EXPORT QValidator *createUrlValidator(QStringList schemes, QObject* parent = nullptr);
} }

Loading…
Cancel
Save