9 changed files with 297 additions and 6 deletions
@ -0,0 +1,55 @@ |
|||
#include "identityeditviewmodel_p.h" |
|||
#include "datasyncviewmodel.h" |
|||
using namespace QtMvvm; |
|||
using namespace QtDataSync; |
|||
|
|||
IdentityEditViewModel::IdentityEditViewModel(QObject *parent) : |
|||
ViewModel(parent), |
|||
_manager(nullptr) |
|||
{} |
|||
|
|||
QVariantHash IdentityEditViewModel::params(AccountManager *manager) |
|||
{ |
|||
return { |
|||
{QStringLiteral("manager"), QVariant::fromValue(manager)} |
|||
}; |
|||
} |
|||
|
|||
QString IdentityEditViewModel::name() const |
|||
{ |
|||
return _nameBuffer; |
|||
} |
|||
|
|||
QString IdentityEditViewModel::fingerPrint() const |
|||
{ |
|||
return _manager ? |
|||
DataSyncViewModel::formatFingerPrint(_manager->deviceFingerprint()) : |
|||
QString(); |
|||
} |
|||
|
|||
void IdentityEditViewModel::save() |
|||
{ |
|||
if(_manager) |
|||
_manager->setDeviceName(_nameBuffer); |
|||
} |
|||
|
|||
void IdentityEditViewModel::setName(const QString &name) |
|||
{ |
|||
if (_nameBuffer == name) |
|||
return; |
|||
|
|||
_nameBuffer = name; |
|||
emit nameChanged(_nameBuffer); |
|||
} |
|||
|
|||
void IdentityEditViewModel::onInit(const QVariantHash ¶ms) |
|||
{ |
|||
_manager = params.value(QStringLiteral("manager")).value<AccountManager*>(); |
|||
|
|||
connect(_manager, &AccountManager::deviceFingerprintChanged, |
|||
this, &IdentityEditViewModel::fingerPrintChanged); |
|||
connect(_manager, &AccountManager::deviceNameChanged, |
|||
this, &IdentityEditViewModel::setName); |
|||
setName(_manager->deviceName()); |
|||
emit fingerPrintChanged(); |
|||
} |
@ -0,0 +1,46 @@ |
|||
#ifndef QTMVVM_IDENTITYEDITVIEWMODEL_P_H |
|||
#define QTMVVM_IDENTITYEDITVIEWMODEL_P_H |
|||
|
|||
#include <QtMvvmCore/ViewModel> |
|||
|
|||
#include <QtDataSync/AccountManager> |
|||
|
|||
#include "qtmvvmdatasynccore_global.h" |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class Q_MVVMDATASYNCCORE_EXPORT IdentityEditViewModel : public ViewModel |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|||
Q_PROPERTY(QString fingerPrint READ fingerPrint NOTIFY fingerPrintChanged) |
|||
|
|||
public: |
|||
Q_INVOKABLE explicit IdentityEditViewModel(QObject *parent = nullptr); |
|||
|
|||
static QVariantHash params(QtDataSync::AccountManager *manager); |
|||
|
|||
QString name() const; |
|||
QString fingerPrint() const; |
|||
|
|||
public Q_SLOTS: |
|||
void save(); |
|||
|
|||
void setName(const QString &name); |
|||
|
|||
Q_SIGNALS: |
|||
void nameChanged(const QString &name); |
|||
void fingerPrintChanged(); |
|||
|
|||
protected: |
|||
void onInit(const QVariantHash ¶ms) override; |
|||
|
|||
private: |
|||
QtDataSync::AccountManager *_manager; |
|||
QString _nameBuffer; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_IDENTITYEDITVIEWMODEL_P_H
|
@ -0,0 +1,35 @@ |
|||
#include "identityeditdialog_p.h" |
|||
#include "ui_identityeditdialog.h" |
|||
#include <QtMvvmCore/Binding> |
|||
using namespace QtMvvm; |
|||
|
|||
IdentityEditDialog::IdentityEditDialog(ViewModel *viewModel, QWidget *parent) : |
|||
QDialog(parent), |
|||
_viewModel(static_cast<IdentityEditViewModel*>(viewModel)), |
|||
ui(new Ui::IdentityEditDialog) |
|||
{ |
|||
ui->setupUi(this); |
|||
if(parentWidget()) { |
|||
setWindowModality(Qt::WindowModal); |
|||
setWindowFlags(Qt::Sheet | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint); |
|||
} else { |
|||
setWindowModality(Qt::ApplicationModal); |
|||
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint); |
|||
} |
|||
|
|||
bind(_viewModel, "name", |
|||
ui->deviceNameLineEdit, "text", |
|||
Binding::TwoWay, |
|||
nullptr, "editingFinished()"); |
|||
bind(_viewModel, "fingerPrint", |
|||
ui->fingerPrintDisplayLabel, "text", |
|||
Binding::OneWayToView); |
|||
} |
|||
|
|||
IdentityEditDialog::~IdentityEditDialog() {} |
|||
|
|||
void IdentityEditDialog::accept() |
|||
{ |
|||
_viewModel->save(); |
|||
QDialog::accept(); |
|||
} |
@ -0,0 +1,109 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>IdentityEditDialog</class> |
|||
<widget class="QDialog" name="IdentityEditDialog"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>397</width> |
|||
<height>172</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Dialog</string> |
|||
</property> |
|||
<property name="sizeGripEnabled"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="modal"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,1,0"> |
|||
<item row="0" column="0"> |
|||
<widget class="QLabel" name="deviceNameLabel"> |
|||
<property name="text"> |
|||
<string>Device &Name:</string> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>deviceNameLineEdit</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="0" column="1"> |
|||
<widget class="QLineEdit" name="deviceNameLineEdit"/> |
|||
</item> |
|||
<item row="3" column="0" colspan="2"> |
|||
<widget class="QDialogButtonBox" name="buttonBox"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
<property name="standardButtons"> |
|||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="2" column="0" colspan="2"> |
|||
<widget class="QLabel" name="fingerPrintDisplayLabel"> |
|||
<property name="text"> |
|||
<string notr="true"><fingerprint></string> |
|||
</property> |
|||
<property name="textFormat"> |
|||
<enum>Qt::PlainText</enum> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignCenter</set> |
|||
</property> |
|||
<property name="wordWrap"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="textInteractionFlags"> |
|||
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="0" colspan="2"> |
|||
<widget class="QLabel" name="fingerprintLabel"> |
|||
<property name="text"> |
|||
<string>Device Fingerprint:</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<resources/> |
|||
<connections> |
|||
<connection> |
|||
<sender>buttonBox</sender> |
|||
<signal>accepted()</signal> |
|||
<receiver>IdentityEditDialog</receiver> |
|||
<slot>accept()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>227</x> |
|||
<y>279</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>157</x> |
|||
<y>274</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
<connection> |
|||
<sender>buttonBox</sender> |
|||
<signal>rejected()</signal> |
|||
<receiver>IdentityEditDialog</receiver> |
|||
<slot>reject()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>295</x> |
|||
<y>285</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>286</x> |
|||
<y>274</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
</connections> |
|||
</ui> |
@ -0,0 +1,36 @@ |
|||
#ifndef QTMVVM_IDENTITYEDITDIALOG_P_H |
|||
#define QTMVVM_IDENTITYEDITDIALOG_P_H |
|||
|
|||
#include <QtCore/QScopedPointer> |
|||
|
|||
#include <QtWidgets/QDialog> |
|||
|
|||
#include <QtMvvmDataSyncCore/private/identityeditviewmodel_p.h> |
|||
|
|||
#include "qtmvvmdatasyncwidgets_global.h" |
|||
|
|||
namespace Ui { |
|||
class IdentityEditDialog; |
|||
} |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class Q_MVVMDATASYNCWIDGETS_EXPORT IdentityEditDialog : public QDialog |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
Q_INVOKABLE explicit IdentityEditDialog(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); |
|||
~IdentityEditDialog(); |
|||
|
|||
public Q_SLOTS: |
|||
void accept() override; |
|||
|
|||
private: |
|||
IdentityEditViewModel *_viewModel; |
|||
QScopedPointer<Ui::IdentityEditDialog> ui; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_IDENTITYEDITDIALOG_P_H
|
Loading…
Reference in new issue