Browse Source

improved logging

pull/2/head
Skycoder42 7 years ago
parent
commit
667d97642d
  1. 10
      src/imports/mvvmcore/plugins.qmltypes
  2. 9
      src/imports/mvvmcore/qqmlmvvmbinding.cpp
  3. 10
      src/imports/mvvmcore/qqmlmvvmbinding.h
  4. 6
      src/imports/mvvmquick/InputDialog.qml
  5. 5
      src/imports/mvvmquick/androidfilechooser.cpp
  6. 2
      src/imports/mvvmquick/mvvmquick.pro
  7. 42
      src/imports/mvvmquick/qqmlquickpresenter.cpp
  8. 1
      src/imports/mvvmquick/qtmvvmquick_plugin.cpp
  9. 2
      src/imports/mvvmquick/settingsuibuilder.cpp
  10. 5
      src/mvvmcore/coreapp.cpp
  11. 2
      src/mvvmcore/serviceregistry.cpp
  12. 3
      src/mvvmcore/viewmodel.cpp
  13. 13
      src/mvvmdatasynccore/accountmodel.cpp
  14. 20
      src/mvvmdatasynccore/datasyncviewmodel.cpp
  15. 46
      src/mvvmdatasynccore/exchangedevicesmodel.cpp
  16. 10
      src/mvvmdatasynccore/exchangedevicesmodel_p.h
  17. 5
      src/mvvmdatasynccore/networkexchangeviewmodel.cpp
  18. 50
      src/mvvmquick/inputviewfactory.cpp
  19. 18
      src/mvvmquick/quickpresenter.cpp
  20. 4
      src/mvvmquick/translations/qtmvvmquick_de.ts
  21. 2
      src/mvvmquick/translations/qtmvvmquick_template.ts
  22. 1
      src/mvvmwidgets/inputwidgetfactory.cpp
  23. 12
      src/mvvmwidgets/widgetspresenter.cpp

10
src/imports/mvvmcore/plugins.qmltypes

@ -109,6 +109,8 @@ Module {
Property { name: "viewModelProperty"; type: "string" }
Property { name: "view"; type: "QObject"; isPointer: true }
Property { name: "viewProperty"; type: "string" }
Property { name: "viewModelChangeSignal"; type: "string" }
Property { name: "viewChangeSignal"; type: "string" }
Property { name: "type"; type: "BindingDirection" }
Signal {
name: "viewModelChanged"
@ -130,6 +132,14 @@ Module {
name: "typeChanged"
Parameter { name: "type"; type: "BindingDirection" }
}
Signal {
name: "viewModelChangeSignalChanged"
Parameter { name: "viewModelChangeSignal"; type: "string" }
}
Signal {
name: "viewChangeSignalChanged"
Parameter { name: "viewChangeSignal"; type: "string" }
}
Method {
name: "setType"
Parameter { name: "type"; type: "BindingDirection" }

9
src/imports/mvvmcore/qqmlmvvmbinding.cpp

@ -10,7 +10,9 @@ QQmlMvvmBinding::QQmlMvvmBinding(QObject *parent) :
_viewModelProperty(),
_view(nullptr),
_viewProperty(),
_type(TwoWay)
_type(TwoWay),
_viewModelChangeSignal(),
_viewChangeSignal()
{
connect(this, &QQmlMvvmBinding::viewModelChanged,
this, &QQmlMvvmBinding::resetBinding);
@ -60,8 +62,11 @@ void QQmlMvvmBinding::resetBinding()
{
if(!_completed || !_viewModel || !_view)
return;
_binding.unbind();
_binding = QtMvvm::bind(_viewModel, qUtf8Printable(_viewModelProperty),
_view, qUtf8Printable(_viewProperty),
static_cast<Binding::BindingDirection>(static_cast<int>(_type)));
static_cast<Binding::BindingDirection>(static_cast<int>(_type)),
_viewModelChangeSignal.isEmpty() ? nullptr : qUtf8Printable(_viewModelChangeSignal),
_viewChangeSignal.isEmpty() ? nullptr : qUtf8Printable(_viewChangeSignal));
}

10
src/imports/mvvmcore/qqmlmvvmbinding.h

@ -17,6 +17,8 @@ class QQmlMvvmBinding : public QObject, public QQmlParserStatus
Q_PROPERTY(QString viewModelProperty MEMBER _viewModelProperty NOTIFY viewModelPropertyChanged)
Q_PROPERTY(QObject* view MEMBER _view NOTIFY viewChanged)
Q_PROPERTY(QString viewProperty MEMBER _viewProperty NOTIFY viewPropertyChanged)
Q_PROPERTY(QString viewModelChangeSignal MEMBER _viewModelChangeSignal NOTIFY viewModelChangeSignalChanged)
Q_PROPERTY(QString viewChangeSignal MEMBER _viewChangeSignal NOTIFY viewChangeSignalChanged)
Q_PROPERTY(BindingDirection type READ type WRITE setType NOTIFY typeChanged) //MEMBER is broken for flags
public:
@ -43,10 +45,12 @@ public Q_SLOTS:
Q_SIGNALS:
void viewModelChanged(QObject* viewModel);
void viewModelPropertyChanged(QString viewModelProperty);
void viewModelPropertyChanged(const QString &viewModelProperty);
void viewChanged(QObject* view);
void viewPropertyChanged(QString viewProperty);
void viewPropertyChanged(const QString &viewProperty);
void typeChanged(BindingDirection type);
void viewModelChangeSignalChanged(const QString &viewModelChangeSignal);
void viewChangeSignalChanged(const QString &viewChangeSignal);
private Q_SLOTS:
void resetBinding();
@ -60,6 +64,8 @@ private:
QObject* _view;
QString _viewProperty;
BindingDirection _type;
QString _viewModelChangeSignal;
QString _viewChangeSignal;
};
}

6
src/imports/mvvmquick/InputDialog.qml

@ -29,9 +29,11 @@ MsgBoxBase {
Label {
id: _errorLabel
visible: _inputViewLoad.status == Loader.Error
visible: _inputViewLoad.status == Loader.Error || inputUrl == ""
Layout.fillWidth: true
text: qsTr("<i>Failed to load input view for type: <b>%1</b></i>").arg(msgConfig.subType)
text: qsTr("<i>Failed to load input view</i>")
color: "#800000"
wrapMode: Text.Wrap
}
Loader {

5
src/imports/mvvmquick/androidfilechooser.cpp

@ -14,10 +14,7 @@ AndroidFileChooser::AndroidFileChooser(QObject *parent) :
_result()
{}
AndroidFileChooser::~AndroidFileChooser()
{
qt_noop();
}
AndroidFileChooser::~AndroidFileChooser() {}
QString AndroidFileChooser::title() const
{

2
src/imports/mvvmquick/mvvmquick.pro

@ -1,4 +1,4 @@
QT += core qml quick svg quickcontrols2 mvvmquick mvvmquick-private
QT += core qml quick svg quickcontrols2 mvvmquick mvvmcore-private mvvmquick-private
CXX_MODULE = mvvmquick
TARGETPATH = de/skycoder42/QtMvvm/Quick
TARGET = declarative_mvvmquick

42
src/imports/mvvmquick/qqmlquickpresenter.cpp

@ -6,6 +6,7 @@
#include <QtQuickControls2/QQuickStyle>
#include <QtMvvmCore/private/qtmvvm_logging_p.h>
#include <QtMvvmQuick/private/quickpresenter_p.h>
#ifdef Q_OS_ANDROID
@ -61,21 +62,23 @@ QStringList QQmlQuickPresenter::mimeTypeFilters(const QStringList &mimeTypes) co
void QQmlQuickPresenter::toggleDrawer()
{
if(!_qmlPresenter) {
qmlWarning(this).space() << "No QML-Presenter registered! Unable to toggle drawer";
logWarning() << "No QML-Presenter registered! Unable to toggle drawer";
return;
}
QMetaObject::invokeMethod(_qmlPresenter, "toggleDrawer");
if(!QMetaObject::invokeMethod(_qmlPresenter, "toggleDrawer"))
logWarning() << "QML-Presenter does not have a \"toggleDrawer\" method";
}
void QQmlQuickPresenter::popView()
{
if(!_qmlPresenter) {
qmlWarning(this).space() << "No QML-Presenter registered! Unable to toggle drawer";
logWarning() << "No QML-Presenter registered! Unable to pop view";
return;
}
QMetaObject::invokeMethod(_qmlPresenter, "closeAction");
if(!QMetaObject::invokeMethod(_qmlPresenter, "closeAction"))
logWarning() << "QML-Presenter does not have a \"closeAction\" method";
}
void QQmlQuickPresenter::hapticLongPress()
@ -93,6 +96,8 @@ void QQmlQuickPresenter::hapticLongPress()
"(I)Z",
LONG_PRESS);
});
#else
logDebug() << Q_FUNC_INFO;
#endif
}
@ -124,8 +129,8 @@ void QQmlQuickPresenter::present(ViewModel *viewModel, const QVariantHash &param
void QQmlQuickPresenter::showDialog(const MessageConfig &config, MessageResult *result)
{
if(!_qmlPresenter) {
qmlWarning(this).space() << "No QML-Presenter registered! Unable to present dialog of type"
<< config.type();
logWarning() << "No QML-Presenter registered! Unable to present dialog of type"
<< config.type();
return;
}
@ -135,8 +140,9 @@ void QQmlQuickPresenter::showDialog(const MessageConfig &config, MessageResult *
Q_ARG(QVariant, QVariant::fromValue(config)),
Q_ARG(QVariant, QVariant::fromValue(result)));
if(!res.toBool()) {
qmlWarning(this).space() << "Failed to present dialog of type"
<< config.type();
logWarning() << "Failed to present dialog of type"
<< config.type();
result->complete(MessageConfig::NoButton);
}
}
@ -149,6 +155,7 @@ void QQmlQuickPresenter::statusChanged(QQmlComponent::Status status)
switch(status) {
case QQmlComponent::Ready:
{
logDebug() << "Loaded and cached component" << component->url();
_componentCache.insert(component->url(), component);
auto loadInfo = _loadCache.value(component);
disconnect(component, &QQmlComponent::progressChanged,
@ -158,10 +165,11 @@ void QQmlQuickPresenter::statusChanged(QQmlComponent::Status status)
}
case QQmlComponent::Error:
{
qmlWarning(this, component->errors()) << "Failed to load component";
component->deleteLater();
auto loadInfo = _loadCache.value(component);
logWarning().noquote() << "Failed to load component for" << std::get<0>(loadInfo)->metaObject()->className()
<< "with error:" << component->errorString().trimmed();
std::get<0>(loadInfo)->deleteLater();
component->deleteLater();
break;
}
default:
@ -178,16 +186,16 @@ void QQmlQuickPresenter::statusChanged(QQmlComponent::Status status)
void QQmlQuickPresenter::addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent)
{
if(!_qmlPresenter) {
qmlWarning(this).space() << "No QML-Presenter registered! Unable to present viewModel of type"
<< viewModel->metaObject()->className();
logWarning() << "No QML-Presenter registered! Unable to present viewModel of type"
<< viewModel->metaObject()->className();
return;
}
//create the view item, set initial stuff and them complete creation
auto item = component->beginCreate(_engine->rootContext());
if(!item) {
qmlWarning(this).space() << "Unable to create quick view from the loaded component"
<< component->url();
logWarning() << "Unable to create quick view from the loaded component"
<< component->url();
return;
}
item->setProperty("viewModel", QVariant::fromValue(viewModel));
@ -205,9 +213,11 @@ void QQmlQuickPresenter::addObject(QQmlComponent *component, ViewModel *viewMode
if(presented) {
if(!item->parent())
QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership);
logDebug() << "Presented" << viewModel->metaObject()->className()
<< "with view" << item->metaObject()->className();
} else {
qmlWarning(this).space() << "Failed to present item for viewModel of type"
<< viewModel->metaObject()->className();
logWarning() << "Failed to present item for viewModel of type"
<< viewModel->metaObject()->className();
item->deleteLater();
}
}

1
src/imports/mvvmquick/qtmvvmquick_plugin.cpp

@ -21,7 +21,6 @@ static void initResources()
static QObject *createQuickPresenterQmlSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{
Q_UNUSED(jsEngine)
//image provider is created together with the singleton
qmlEngine->addImageProvider(QStringLiteral("svg"), new QtMvvm::SvgImageProvider());
return new QtMvvm::QQmlQuickPresenter(qmlEngine);
}

2
src/imports/mvvmquick/settingsuibuilder.cpp

@ -59,6 +59,7 @@ void SettingsUiBuilder::loadSection(const SettingsElements::Section &section)
{
auto inputFactory = QuickPresenterPrivate::currentPresenter()->inputViewFactory();
_entryModel->setup(section, _viewModel, inputFactory);
qmlDebug(this) << "Loaded section" << section.title;
emit presentSection(_entryFilterModel);
}
@ -67,6 +68,7 @@ void SettingsUiBuilder::showDialog(const QString &key, const QString &title, con
if(type == QStringLiteral("action"))
_viewModel->callAction(key, properties.value(QStringLiteral("args")).toMap());
else {
qmlDebug(this) << "Creating input dialog for settings entry" << key;
getInput(title + tr(":"), QString(), qUtf8Printable(type), this, [this, key](QVariant value) {
if(value.isValid())
_viewModel->saveValue(key, value);

5
src/mvvmcore/coreapp.cpp

@ -176,6 +176,7 @@ void CoreAppPrivate::showViewModel(const QMetaObject *metaObject, const QVariant
parent->onResult(requestCode, QVariant());
});
}
logDebug() << "Successfully presented" << metaObject->className();
} catch(QException &e) {
logCritical() << "Failed to present viewmodel of type"
<< metaObject->className()
@ -196,6 +197,7 @@ void CoreAppPrivate::showDialog(const MessageConfig &config, MessageResult *resu
if(presenter) {
try {
presenter->showDialog(config, result);
logDebug() << "Successfully presented dialog of type" << config.type();
} catch(QException &e) {
logCritical() << "Failed to show dialog ff type"
<< config.type() << ":" << config.subType()
@ -203,8 +205,7 @@ void CoreAppPrivate::showDialog(const MessageConfig &config, MessageResult *resu
<< e.what();
result->complete(MessageConfig::NoButton);
}
}
else {
} else {
logCritical() << "Failed to show dialog ff type"
<< config.type() << ":" << config.subType()
<< "- no presenter was set";

2
src/mvvmcore/serviceregistry.cpp

@ -148,7 +148,6 @@ bool ServiceRegistryPrivate::ServiceInfo::replaceable() const
QObject *ServiceRegistryPrivate::ServiceInfo::instance(ServiceRegistryPrivate *d, const QByteArray &iid)
{
if(!_instance) {
logDebug() << "Constructing service of type" << iid;
_instance = construct(d);
if(!_instance)
throw ServiceConstructionException("Failed to construct service of type " +
@ -156,6 +155,7 @@ QObject *ServiceRegistryPrivate::ServiceInfo::instance(ServiceRegistryPrivate *d
" with unknown error");
if(_instance->thread() != qApp->thread())
_instance->moveToThread(qApp->thread());
logDebug() << "Constructed service of type" << iid;
}
return _instance;
}

3
src/mvvmcore/viewmodel.cpp

@ -75,5 +75,4 @@ void ViewModel::showImp(const QMetaObject *metaObject, const QVariantHash &param
// ------------- Private Implementation -------------
ViewModelPrivate::ViewModelPrivate()
{}
ViewModelPrivate::ViewModelPrivate() {}

13
src/mvvmdatasynccore/accountmodel.cpp

@ -2,7 +2,13 @@
#include "accountmodel_p.h"
#include "datasyncviewmodel.h"
#include <QRemoteObjectReplica>
#include <QtRemoteObjects/QRemoteObjectReplica>
#undef logDebug
#undef logInfo
#undef logWarning
#undef logCritical
#include <QtMvvmCore/private/qtmvvm_logging_p.h>
using namespace QtMvvm;
using namespace QtDataSync;
@ -139,8 +145,10 @@ void AccountModel::reload()
d->devices.clear();
endResetModel();
if(d->accountManager)
if(d->accountManager) {
logDebug() << "Reloading device list";
d->accountManager->listDevices();
}
}
void AccountModel::accountDevices(const QList<DeviceInfo> &devices)
@ -148,6 +156,7 @@ void AccountModel::accountDevices(const QList<DeviceInfo> &devices)
beginResetModel();
d->devices = devices;
endResetModel();
logDebug() << "Device list updated with" << devices.size() << "devices";
}
void AccountModel::update(SyncManager::SyncState state)

20
src/mvvmdatasynccore/datasyncviewmodel.cpp

@ -112,10 +112,13 @@ QString DataSyncViewModel::formatFingerPrint(const QByteArray &fingerPrint)
void DataSyncViewModel::syncOrConnect()
{
if(d->syncManager->syncState() == SyncManager::Disconnected ||
d->syncManager->syncState() == SyncManager::Error)
d->syncManager->syncState() == SyncManager::Error) {
logDebug() << "Reconnecting to remote";
d->syncManager->reconnect();
else
} else {
logDebug() << "Synchronizing with remote";
d->syncManager->synchronize();
}
}
void DataSyncViewModel::showDeviceInfo()
@ -136,6 +139,8 @@ void DataSyncViewModel::startImport()
auto home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
getOpenFile(this, [this](QUrl url) {
if(url.isValid()) {
logDebug() << "Importing from URL" << url;
QSharedPointer<QIODevice> device;
#ifdef Q_OS_ANDROID
if(url.scheme() == QStringLiteral("content"))
@ -269,8 +274,11 @@ void DataSyncViewModel::resetColorMap()
void DataSyncViewModel::showImportDialog(LoginRequest request)
{
if(request.handled())
if(request.handled()) {
logDebug() << "Skipping already handeled import request";
return;
}
question(tr("Login requested!"),
tr("<p>A device wants to log into your account:</p>"
"<p>Name: %1<br/>"
@ -285,7 +293,8 @@ void DataSyncViewModel::showImportDialog(LoginRequest request)
req.accept();
else
req.reject();
}
} else
logDebug() << "Skipping already handeled import request";
});
}
@ -366,6 +375,7 @@ void DataSyncViewModel::onResult(quint32 requestCode, const QVariant &result)
case DataSyncViewModelPrivate::ChangeRemoteRequestCode:
if(result.isValid()) {
auto res = ChangeRemoteViewModel::result(result);
logDebug() << "Changing remote to server" << std::get<0>(res).url();
d->accountManager->changeRemote(std::get<0>(res), std::get<1>(res));
}
break;
@ -389,6 +399,8 @@ void DataSyncViewModelPrivate::performExport(bool trusted, bool includeServer, c
auto home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
getSaveFile(q, [this, trusted, includeServer, password](QUrl url) {
if(url.isValid()) {
logDebug() << "Exporting to URL" << url;
QSharedPointer<QIODevice> device;
#ifdef Q_OS_ANDROID
if(url.scheme() == QStringLiteral("content"))

46
src/mvvmdatasynccore/exchangedevicesmodel.cpp

@ -1,7 +1,16 @@
#include "exchangedevicesmodel.h"
#include "exchangedevicesmodel_p.h"
#include <chrono>
#undef logDebug
#undef logInfo
#undef logWarning
#undef logCritical
#include <QtMvvmCore/private/qtmvvm_logging_p.h>
using namespace QtMvvm;
using namespace QtDataSync;
using namespace std::chrono;
ExchangeDevicesModel::ExchangeDevicesModel(QObject *parent) :
QAbstractListModel(parent),
@ -17,7 +26,10 @@ void ExchangeDevicesModel::setup(QtDataSync::UserExchangeManager *exchangeManage
beginResetModel();
d->exchangeManager = exchangeManager;
d->devices = d->exchangeManager->devices();
d->devices.clear();
d->devices.reserve(d->exchangeManager->devices().size());
for(auto device : d->exchangeManager->devices())
d->devices.append(device);
endResetModel();
connect(d->exchangeManager, &UserExchangeManager::devicesChanged,
@ -126,23 +138,47 @@ QString ExchangeDevicesModel::fullAddress(const UserInfo &userInfo)
void ExchangeDevicesModel::updateDevices(const QList<UserInfo> &devices)
{
QList<UserInfo> addList;
//find new devices and update existing
QList<ExchangeDevicesModelPrivate::LimitedUserInfo> addList;
for(auto device : devices) {
auto dIndex = d->devices.indexOf(device);
if(dIndex != -1) {
if(device.name() != d->devices[dIndex].name()) {
logDebug() << "Updating name of device" << device;
d->devices[dIndex] = device;
emit dataChanged(index(dIndex), index(dIndex, 1));
}
} else
} else
d->devices[dIndex].deadline.setRemainingTime(seconds(5), Qt::VeryCoarseTimer);
} else {
logDebug() << "Adding new device" << device;
addList.append(device);
}
}
//remove old devices
for(auto i = 0; i < d->devices.size();) {
if(d->devices[i].deadline.hasExpired()) {
logDebug() << "Removing stale device" << d->devices[i];
beginRemoveRows({}, i, i);
d->devices.removeAt(i);
endRemoveRows();
} else
i++;
}
//add new devices
if(addList.isEmpty())
return;
beginInsertRows(QModelIndex(),
beginInsertRows({},
d->devices.size(),
d->devices.size() + addList.size() - 1);
d->devices.append(addList);
endInsertRows();
}
ExchangeDevicesModelPrivate::LimitedUserInfo::LimitedUserInfo(const UserInfo &info) :
UserInfo(info),
deadline(seconds(5), Qt::VeryCoarseTimer)
{}

10
src/mvvmdatasynccore/exchangedevicesmodel_p.h

@ -2,6 +2,7 @@
#define QTMVVM_EXCHANGEDEVICESMODEL_P_H
#include <QtCore/QHash>
#include <QtCore/QDeadlineTimer>
#include "qtmvvmdatasynccore_global.h"
#include "exchangedevicesmodel.h"
@ -11,8 +12,15 @@ namespace QtMvvm {
class ExchangeDevicesModelPrivate
{
public:
struct LimitedUserInfo : public QtDataSync::UserInfo
{
LimitedUserInfo(const QtDataSync::UserInfo &info = {});
QDeadlineTimer deadline;
};
QtDataSync::UserExchangeManager *exchangeManager = nullptr;
QList<QtDataSync::UserInfo> devices;
QList<LimitedUserInfo> devices;
};
}

5
src/mvvmdatasynccore/networkexchangeviewmodel.cpp

@ -139,6 +139,7 @@ void NetworkExchangeViewModel::onResult(quint32 requestCode, const QVariant &res
if(d->activeExports.contains(requestCode)) {
auto info = d->activeExports.take(requestCode);
if(result.isValid()) {
logDebug() << "Exporting account to device" << info;
auto res = ExportSetupViewModel::result(result);
if(std::get<0>(res))
d->exchangeManager->exportTrustedTo(info, std::get<1>(res), std::get<2>(res));
@ -183,9 +184,11 @@ void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool truste
connect(res, &MessageResult::dialogDone, this, [this, res, userInfo, importDoneHandler](MessageConfig::StandardButton btn) {
switch (btn) {
case MessageConfig::YesToAll:
logDebug() << "Importing account from device" << userInfo;
d->exchangeManager->importTrustedFrom(userInfo, res->result().toString(), importDoneHandler, false);
break;
case MessageConfig::Yes:
logDebug() << "Importing account from device" << userInfo;
d->exchangeManager->importTrustedFrom(userInfo, res->result().toString(), importDoneHandler, true);
break;
default:
@ -206,9 +209,11 @@ void NetworkExchangeViewModel::newUserData(const UserInfo &userInfo, bool truste
connect(res, &MessageResult::dialogDone, this, [this, userInfo, importDoneHandler](MessageConfig::StandardButton btn) {
switch (btn) {
case MessageConfig::YesToAll:
logDebug() << "Importing account from device" << userInfo;
d->exchangeManager->importFrom(userInfo, importDoneHandler, false);
break;
case MessageConfig::Yes:
logDebug() << "Importing account from device" << userInfo;
d->exchangeManager->importFrom(userInfo, importDoneHandler, true);
break;
default:

50
src/mvvmquick/inputviewfactory.cpp

@ -19,57 +19,67 @@ InputViewFactory::~InputViewFactory() {}
QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &viewProperties)
{
QUrl url;
Q_UNUSED(viewProperties)
if(d->inputAliases.contains(type))
return getInputUrl(d->inputAliases.value(type), viewProperties);
url = getInputUrl(d->inputAliases.value(type), viewProperties);
if(d->simpleInputs.contains(type))
return d->simpleInputs.value(type);
url = d->simpleInputs.value(type);
else if(type == QMetaType::typeName(QMetaType::Bool))
return QStringLiteral("qrc:/qtmvvm/inputs/CheckBox.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/CheckBox.qml");
else if(type == "switch")
return QStringLiteral("qrc:/qtmvvm/inputs/Switch.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/Switch.qml");
else if(type == QMetaType::typeName(QMetaType::QString) || type == "string")
return QStringLiteral("qrc:/qtmvvm/inputs/TextField.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/TextField.qml");
else if(type == QMetaType::typeName(QMetaType::Int))
return QStringLiteral("qrc:/qtmvvm/inputs/SpinBox.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/SpinBox.qml");
else if(type == QMetaType::typeName(QMetaType::Double))
return QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml");
// else if(type == QMetaType::typeName(QMetaType::QDate))
// return QUrl();
// url = QUrl();
// else if(type == QMetaType::typeName(QMetaType::QTime))
// return QUrl();
// url = QUrl();
// else if(type == QMetaType::typeName(QMetaType::QDateTime) || type == "date")
// return QUrl();
// url = QUrl();
else if(type == QMetaType::typeName(QMetaType::QFont))
return QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml");
else if(type == QMetaType::typeName(QMetaType::QUrl) || type == "url")
return QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml");
else if(type == "selection" || type == "list")
return QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml");
else if(type == "radiolist")
return QStringLiteral("qrc:/qtmvvm/inputs/RadioListEdit.qml");
url = QStringLiteral("qrc:/qtmvvm/inputs/RadioListEdit.qml");
else {
logCritical() << "Failed to find any input view for input type:" << type;
return QUrl();
}
logDebug() << "Found view URL for input of type" << type << "as" << url;
return url;
}
QUrl InputViewFactory::getDelegate(const QByteArray &type, const QVariantMap &viewProperties)
{
QUrl url;
Q_UNUSED(viewProperties)
if(d->delegateAliases.contains(type))
return getDelegate(d->delegateAliases.value(type), viewProperties);
url = getDelegate(d->delegateAliases.value(type), viewProperties);
if(d->simpleDelegates.contains(type))
return d->simpleDelegates.value(type);
url = d->simpleDelegates.value(type);
else if(type == QMetaType::typeName(QMetaType::Bool))
return QStringLiteral("qrc:/qtmvvm/delegates/BoolDelegate.qml");
url = QStringLiteral("qrc:/qtmvvm/delegates/BoolDelegate.qml");
else if(type == "switch")
return QStringLiteral("qrc:/qtmvvm/delegates/SwitchDelegate.qml");
url = QStringLiteral("qrc:/qtmvvm/delegates/SwitchDelegate.qml");
else if((type == "selection" || type == "list") &&
!viewProperties.value(QStringLiteral("editable"), false).toBool())
return QStringLiteral("qrc:/qtmvvm/delegates/ListDelegate.qml");
url = QStringLiteral("qrc:/qtmvvm/delegates/ListDelegate.qml");
else
return QStringLiteral("qrc:/qtmvvm/delegates/MsgDelegate.qml");
url = QStringLiteral("qrc:/qtmvvm/delegates/MsgDelegate.qml");
logDebug() << "Found view URL for delegate of type" << type << "as" << url;
return url;
}
void InputViewFactory::addSimpleInput(const QByteArray &type, const QUrl &qmlFileUrl)

18
src/mvvmquick/quickpresenter.cpp

@ -57,6 +57,7 @@ void QuickPresenter::present(QtMvvm::ViewModel *viewModel, const QVariantHash &p
{
if(d->qmlPresenter) {
auto url = findViewUrl(viewModel->metaObject());
logDebug() << "Handing over viewModel" << viewModel->metaObject()->className() << "to QML presenter";
QMetaObject::invokeMethod(d->qmlPresenter, "present",
Q_ARG(QtMvvm::ViewModel*, viewModel),
Q_ARG(QVariantHash, params),
@ -69,6 +70,7 @@ void QuickPresenter::present(QtMvvm::ViewModel *viewModel, const QVariantHash &p
void QuickPresenter::showDialog(const QtMvvm::MessageConfig &config, QtMvvm::MessageResult *result)
{
if(d->qmlPresenter) {
logDebug() << "Handing over dialog of type" << config.type() << "to QML presenter";
QMetaObject::invokeMethod(d->qmlPresenter, "showDialog",
Q_ARG(QtMvvm::MessageConfig, config),
Q_ARG(QtMvvm::MessageResult*, result));
@ -157,16 +159,22 @@ QUrl QuickPresenter::findViewUrl(const QMetaObject *viewModelType)
int QuickPresenter::presentMethodIndex(const QMetaObject *presenterMetaObject, QObject *viewObject)
{
auto index = -1;
if(viewObject->inherits("QQuickPopup"))
if(viewObject->inherits("QQuickPopup")) {
logDebug() << "Presenting" << viewObject->metaObject()->className() << "as popup";
index = presenterMetaObject->indexOfMethod("presentPopup(QVariant)");
if(viewObject->inherits("QQuickItem")) {
if(nameOrClassContains(viewObject, QStringLiteral("Drawer")))
} if(viewObject->inherits("QQuickItem")) {
if(nameOrClassContains(viewObject, QStringLiteral("Drawer"))) {
logDebug() << "Presenting" << viewObject->metaObject()->className() << "as drawer";
index = presenterMetaObject->indexOfMethod("presentDrawerContent(QVariant)");
if(index == -1 && nameOrClassContains(viewObject, QStringLiteral("Tab")))
} if(index == -1 && nameOrClassContains(viewObject, QStringLiteral("Tab"))) {
logDebug() << "Presenting" << viewObject->metaObject()->className() << "as tab";
index = presenterMetaObject->indexOfMethod("presentTab(QVariant)");
}
if(index == -1)
if(index == -1) {
logDebug() << "Presenting" << viewObject->metaObject()->className() << "as item";
index = presenterMetaObject->indexOfMethod("presentItem(QVariant)");
}
}
return index;
}

4
src/mvvmquick/translations/qtmvvmquick_de.ts

@ -5,8 +5,8 @@
<name>InputDialog</name>
<message>
<location filename="../../imports/mvvmquick/InputDialog.qml" line="+34"/>
<source>&lt;i&gt;Failed to load input view for type: &lt;b&gt;%1&lt;/b&gt;&lt;/i&gt;</source>
<translation>&lt;i&gt;Eingabeansicht konnte nicht geladen werden. Typ: &lt;b&gt;%1&lt;/b&gt;&lt;/i&gt;</translation>
<source>&lt;i&gt;Failed to load input view&lt;/i&gt;</source>
<translation>&lt;i&gt;Eingabeansicht konnte nicht geladen werden&lt;/i&gt;</translation>
</message>
</context>
<context>

2
src/mvvmquick/translations/qtmvvmquick_template.ts

@ -5,7 +5,7 @@
<name>InputDialog</name>
<message>
<location filename="../../imports/mvvmquick/InputDialog.qml" line="+34"/>
<source>&lt;i&gt;Failed to load input view for type: &lt;b&gt;%1&lt;/b&gt;&lt;/i&gt;</source>
<source>&lt;i&gt;Failed to load input view&lt;/i&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>

1
src/mvvmwidgets/inputwidgetfactory.cpp

@ -72,6 +72,7 @@ QWidget *InputWidgetFactory::createInput(const QByteArray &type, QWidget *parent
for(auto it = viewProperties.constBegin(); it != viewProperties.constEnd(); it++)
widget->setProperty(qUtf8Printable(it.key()), it.value());
logDebug() << "Found view for input of type" << type << "as" << widget->metaObject()->className();
return widget;
}

12
src/mvvmwidgets/widgetspresenter.cpp

@ -104,6 +104,9 @@ void WidgetsPresenter::present(ViewModel *viewModel, const QVariantHash &params,
view->deleteLater();
throw PresenterException(QByteArrayLiteral("Unable to find a method that is able to present a view of type") +
viewMetaObject->className());
} else {
logDebug() << "Presented" << viewModel->metaObject()->className()
<< "with view" << viewMetaObject->className();
}
}
@ -117,6 +120,7 @@ void WidgetsPresenter::showDialog(const MessageConfig &config, MessageResult *re
presentFileDialog(config, result);
else
presentOtherDialog(config, result);
logDebug() << "Presented dialog of type" << config.type();
}
InputWidgetFactory *WidgetsPresenter::inputWidgetFactory() const
@ -179,6 +183,7 @@ bool WidgetsPresenter::tryPresent(QWidget *view, QWidget *parentView)
// Check if QDialog
if(metaObject->inherits(&QDialog::staticMetaObject)) {
logDebug() << "Presenting" << metaObject->className() << "as dialog";
qobject_cast<QDialog*>(view)->open();
return true;
}
@ -190,6 +195,7 @@ bool WidgetsPresenter::tryPresent(QWidget *view, QWidget *parentView)
// Check if child is QDockWidget
if(metaObject->inherits(&QDockWidget::staticMetaObject)) {
logDebug() << "Presenting" << metaObject->className() << "as dock widget";
auto dockWidget = qobject_cast<QDockWidget*>(view);
if(!mainWindow->restoreDockWidget(dockWidget))
mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
@ -205,9 +211,10 @@ bool WidgetsPresenter::tryPresent(QWidget *view, QWidget *parentView)
if(!pView)
continue;
// Check if QMdiArea and child is QMdiSubWindow
// Check if QMdiArea and child ends with MdiWindow
if(pView->metaObject()->inherits(&QMdiArea::staticMetaObject) &&
metaObject->inherits(&QMdiSubWindow::staticMetaObject)) {
QByteArray(metaObject->className()).endsWith("MdiWindow")) {
logDebug() << "Presenting" << metaObject->className() << "as MDI window";
auto mdiArea = qobject_cast<QMdiArea*>(pView);
mdiArea->addSubWindow(view);
return true;
@ -215,6 +222,7 @@ bool WidgetsPresenter::tryPresent(QWidget *view, QWidget *parentView)
}
//none of the special cases -> simply "show" it
logDebug() << "Presenting" << metaObject->className() << "as normal window";
showForeground(view);
return true;
}

Loading…
Cancel
Save