Browse Source

added identity edit dialog

pull/2/head
Skycoder42 7 years ago
parent
commit
8041ae9c38
  1. 2
      src/imports/mvvmdatasynccore/mvvmdatasynccore.pro
  2. 128
      src/imports/mvvmdatasynccore/plugins.qmltypes
  3. 9
      src/imports/mvvmdatasynccore/qtmvvmdatasynccore_plugin.cpp
  4. 2
      src/imports/mvvmdatasyncquick/DataSyncView.qml
  5. 79
      src/imports/mvvmdatasyncquick/IdentityEditView.qml
  6. 3
      src/imports/mvvmdatasyncquick/mvvmdatasyncquick.pro
  7. 1
      src/imports/mvvmdatasyncquick/qmldir
  8. 10
      src/mvvmdatasynccore/identityeditviewmodel.cpp
  9. 3
      src/mvvmdatasynccore/identityeditviewmodel_p.h
  10. 3
      src/mvvmdatasyncquick/IdentityEditView.qml
  11. 1
      src/mvvmdatasyncquick/qtmvvmdatasyncquick_module.qrc
  12. 3
      src/mvvmdatasyncwidgets/identityeditdialog.cpp

2
src/imports/mvvmdatasynccore/mvvmdatasynccore.pro

@ -1,4 +1,4 @@
QT += core qml quick mvvmdatasynccore
QT += core qml quick mvvmdatasynccore mvvmdatasynccore-private
CXX_MODULE = mvvmdatasynccore
TARGETPATH = de/skycoder42/QtMvvm/DataSync/Core
TARGET = declarative_mvvmdatasynccore

128
src/imports/mvvmdatasynccore/plugins.qmltypes

@ -41,6 +41,70 @@ Module {
Parameter { name: "row"; type: "int" }
}
}
Component {
name: "QtMvvm::ChangeRemoteViewModel"
prototype: "QtMvvm::ViewModel"
exports: [
"de.skycoder42.QtMvvm.DataSync.Core/PChangeRemoteViewModel 1.0"
]
isCreatable: false
exportMetaObjectRevisions: [0]
Enum {
name: "Roles"
values: {
"KeyRole": 0,
"ValueRole": 257
}
}
Property { name: "url"; type: "QUrl" }
Property { name: "accessKey"; type: "string" }
Property { name: "keepAlive"; type: "int" }
Property { name: "keepData"; type: "bool" }
Property { name: "headerModel"; type: "QStandardItemModel"; isReadonly: true; isPointer: true }
Property { name: "valid"; type: "bool"; isReadonly: true }
Signal {
name: "urlChanged"
Parameter { name: "url"; type: "QUrl" }
}
Signal {
name: "accessKeyChanged"
Parameter { name: "accessKey"; type: "string" }
}
Signal {
name: "keepAliveChanged"
Parameter { name: "keepAlive"; type: "int" }
}
Signal {
name: "keepDataChanged"
Parameter { name: "keepData"; type: "bool" }
}
Method { name: "completeSetup"; type: "bool" }
Method {
name: "setUrl"
Parameter { name: "url"; type: "QUrl" }
}
Method {
name: "setAccessKey"
Parameter { name: "accessKey"; type: "string" }
}
Method {
name: "setKeepAlive"
Parameter { name: "keepAlive"; type: "int" }
}
Method {
name: "setKeepData"
Parameter { name: "keepData"; type: "bool" }
}
Method {
name: "addHeaderConfig"
Parameter { name: "key"; type: "string" }
Parameter { name: "value"; type: "string" }
}
Method {
name: "removeHeaderConfig"
Parameter { name: "index"; type: "int" }
}
}
Component {
name: "QtMvvm::DataSyncViewModel"
prototype: "QtMvvm::ViewModel"
@ -119,6 +183,70 @@ Module {
Parameter { name: "index"; type: "int" }
}
}
Component {
name: "QtMvvm::ExportSetupViewModel"
prototype: "QtMvvm::ViewModel"
exports: [
"de.skycoder42.QtMvvm.DataSync.Core/PExportSetupViewModel 1.0"
]
isCreatable: false
exportMetaObjectRevisions: [0]
Property { name: "label"; type: "string"; isReadonly: true }
Property { name: "trusted"; type: "bool" }
Property { name: "includeServer"; type: "bool" }
Property { name: "password"; type: "string" }
Property { name: "valid"; type: "bool"; isReadonly: true }
Signal {
name: "labelChanged"
Parameter { name: "label"; type: "string" }
}
Signal {
name: "trustedChanged"
Parameter { name: "trusted"; type: "bool" }
}
Signal {
name: "includeServerChanged"
Parameter { name: "includeServer"; type: "bool" }
}
Signal {
name: "passwordChanged"
Parameter { name: "password"; type: "string" }
}
Method { name: "completeSetup"; type: "bool" }
Method {
name: "setTrusted"
Parameter { name: "trusted"; type: "bool" }
}
Method {
name: "setIncludeServer"
Parameter { name: "includeServer"; type: "bool" }
}
Method {
name: "setPassword"
Parameter { name: "password"; type: "string" }
}
}
Component {
name: "QtMvvm::IdentityEditViewModel"
prototype: "QtMvvm::ViewModel"
exports: [
"de.skycoder42.QtMvvm.DataSync.Core/PIdentityEditViewModel 1.0"
]
isCreatable: false
exportMetaObjectRevisions: [0]
Property { name: "name"; type: "string" }
Property { name: "fingerPrint"; type: "string"; isReadonly: true }
Property { name: "valid"; type: "bool"; isReadonly: true }
Signal {
name: "nameChanged"
Parameter { name: "name"; type: "string" }
}
Method { name: "save" }
Method {
name: "setName"
Parameter { name: "name"; type: "string" }
}
}
Component {
name: "QtMvvm::NetworkExchangeViewModel"
prototype: "QtMvvm::ViewModel"

9
src/imports/mvvmdatasynccore/qtmvvmdatasynccore_plugin.cpp

@ -7,6 +7,10 @@
#include <QtMvvmDataSyncCore/DataSyncViewModel>
#include <QtMvvmDataSyncCore/NetworkExchangeViewModel>
#include <QtMvvmDataSyncCore/private/identityeditviewmodel_p.h>
#include <QtMvvmDataSyncCore/private/changeremoteviewmodel_p.h>
#include <QtMvvmDataSyncCore/private/exportsetupviewmodel_p.h>
QtMvvmDataSyncCoreDeclarativeModule::QtMvvmDataSyncCoreDeclarativeModule(QObject *parent) :
QQmlExtensionPlugin(parent)
{}
@ -22,6 +26,11 @@ void QtMvvmDataSyncCoreDeclarativeModule::registerTypes(const char *uri)
qmlRegisterUncreatableType<QtMvvm::DataSyncViewModel>(uri, 1, 0, "DataSyncViewModel", QStringLiteral("ViewModels cannot be created from QML"));
qmlRegisterUncreatableType<QtMvvm::NetworkExchangeViewModel>(uri, 1, 0, "NetworkExchangeViewModel", QStringLiteral("ViewModels cannot be created from QML"));
//private models
qmlRegisterUncreatableType<QtMvvm::IdentityEditViewModel>(uri, 1, 0, "PIdentityEditViewModel", QStringLiteral("ViewModels cannot be created from QML"));
qmlRegisterUncreatableType<QtMvvm::ChangeRemoteViewModel>(uri, 1, 0, "PChangeRemoteViewModel", QStringLiteral("ViewModels cannot be created from QML"));
qmlRegisterUncreatableType<QtMvvm::ExportSetupViewModel>(uri, 1, 0, "PExportSetupViewModel", QStringLiteral("ViewModels cannot be created from QML"));
// Check to make shure no module update is forgotten
static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 0, "QML module version needs to be updated");
}

2
src/imports/mvvmdatasyncquick/DataSyncView.qml

@ -199,7 +199,7 @@ Page {
Layout.leftMargin: 7
text: fingerPrint
elide: Text.ElideMiddle
color: Qt.lighter(_nameLabel.color, 2.0)
opacity: 0.75
}
}

79
src/imports/mvvmdatasyncquick/IdentityEditView.qml

@ -0,0 +1,79 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import de.skycoder42.QtMvvm.Core 1.0
import de.skycoder42.QtMvvm.Quick 1.0
import de.skycoder42.QtMvvm.DataSync.Core 1.0
Dialog {
id: _identityEditView
property PIdentityEditViewModel viewModel: null
property real extraHeight: 0
property real baseWidth: 300
x: parent ? (parent.width - width) / 2 : 0
y: parent ? deltaY() : 0
width: parent ? Math.min(Math.max(implicitWidth, baseWidth), parent.width - 24) : implicitWidth
height: parent ? Math.min(implicitHeight, parent.height - 24) : implicitWidth
modal: true
focus: true
function deltaY() {
var unscaled = Qt.inputMethod.keyboardRectangle.height / Screen.devicePixelRatio;
var availHeight = (parent.height + extraHeight) - unscaled - 24; //margins
var rawDelta = (Math.max(0, availHeight - height) / 2);
return rawDelta + 12 - extraHeight; //spacing
}
title: qsTr("Edit Identity")
ColumnLayout {
id: _layout
anchors.fill: parent
Label {
text: qsTr("Device Name:")
Layout.fillWidth: true
color: _nameEdit.focus ? _nameEdit.selectionColor : palette.text
opacity: _nameEdit.focus ? 1 : 0.5
}
TextField {
id: _nameEdit
Layout.fillWidth: true
MvvmBinding {
viewModel: _identityEditView.viewModel
viewModelProperty: "name"
view: _nameEdit
viewProperty: "text"
}
}
Label {
id: _fpLabel
text: qsTr("Device Fingerprint:")
Layout.fillWidth: true
opacity: 0.5
Layout.topMargin: 16
}
Label {
text: viewModel.fingerPrint
Layout.fillWidth: true
wrapMode: Text.Wrap
verticalAlignment: Qt.AlignVCenter
font.pointSize: _fpLabel.font.pointSize * 0.8
Layout.topMargin: 8
}
}
standardButtons: Dialog.Save | Dialog.Cancel
onAccepted: viewModel.save()
Component.onCompleted: standardButton(Dialog.Save).enabled = Qt.binding(function(){ return viewModel.valid; })
}

3
src/imports/mvvmdatasyncquick/mvvmdatasyncquick.pro

@ -16,7 +16,8 @@ SOURCES += \
QML_FILES += \
SubButton.qml \
DataSyncView.qml
DataSyncView.qml \
IdentityEditView.qml
OTHER_FILES += qmldir

1
src/imports/mvvmdatasyncquick/qmldir

@ -8,3 +8,4 @@ depends de.skycoder42.QtMvvm.Quick 1.0
internal SubButton SubButton.qml
DataSyncView 1.0 DataSyncView.qml
IdentityEditView 1.0 IdentityEditView.qml

10
src/mvvmdatasynccore/identityeditviewmodel.cpp

@ -6,7 +6,10 @@ using namespace QtDataSync;
IdentityEditViewModel::IdentityEditViewModel(QObject *parent) :
ViewModel(parent),
_manager(nullptr)
{}
{
connect(this, &IdentityEditViewModel::nameChanged,
this, &IdentityEditViewModel::validChanged);
}
QVariantHash IdentityEditViewModel::showParams(AccountManager *manager)
{
@ -27,6 +30,11 @@ QString IdentityEditViewModel::fingerPrint() const
QString();
}
bool IdentityEditViewModel::isValid() const
{
return !_nameBuffer.isEmpty();
}
void IdentityEditViewModel::save()
{
if(_manager)

3
src/mvvmdatasynccore/identityeditviewmodel_p.h

@ -15,6 +15,7 @@ class Q_MVVMDATASYNCCORE_EXPORT IdentityEditViewModel : public ViewModel
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString fingerPrint READ fingerPrint NOTIFY fingerPrintChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
public:
Q_INVOKABLE explicit IdentityEditViewModel(QObject *parent = nullptr);
@ -23,6 +24,7 @@ public:
QString name() const;
QString fingerPrint() const;
bool isValid() const;
public Q_SLOTS:
void save();
@ -32,6 +34,7 @@ public Q_SLOTS:
Q_SIGNALS:
void nameChanged(const QString &name);
void fingerPrintChanged();
void validChanged();
protected:
void onInit(const QVariantHash &showParams) override;

3
src/mvvmdatasyncquick/IdentityEditView.qml

@ -0,0 +1,3 @@
import de.skycoder42.QtMvvm.DataSync.Quick 1.0 as QtMvvm
QtMvvm.IdentityEditView {}

1
src/mvvmdatasyncquick/qtmvvmdatasyncquick_module.qrc

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/qtmvvm/views">
<file>DataSyncView.qml</file>
<file>IdentityEditView.qml</file>
</qresource>
</RCC>

3
src/mvvmdatasyncwidgets/identityeditdialog.cpp

@ -25,6 +25,9 @@ IdentityEditDialog::IdentityEditDialog(ViewModel *viewModel, QWidget *parent) :
bind(_viewModel, "fingerPrint",
ui->fingerPrintDisplayLabel, "text",
Binding::OneWayToView);
bind(_viewModel, "valid",
ui->buttonBox->button(QDialogButtonBox::Save), "enabled",
Binding::OneWayToView);
}
IdentityEditDialog::~IdentityEditDialog() {}

Loading…
Cancel
Save