You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
#ifndef QTMVVM_VIEWMODEL_H
|
|
#define QTMVVM_VIEWMODEL_H
|
|
|
|
#include <type_traits>
|
|
|
|
#include <QtCore/qobject.h>
|
|
#include <QtCore/qscopedpointer.h>
|
|
#include <QtCore/qvariant.h>
|
|
#include <QtCore/qpointer.h>
|
|
|
|
#include "QtMvvmCore/qtmvvmcore_global.h"
|
|
|
|
namespace QtMvvm {
|
|
|
|
class ViewModelPrivate;
|
|
class Q_MVVMCORE_EXPORT ViewModel : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool deleteOnClose READ deleteOnClose WRITE setDeleteOnClose NOTIFY deleteOnCloseChanged)
|
|
|
|
public:
|
|
explicit ViewModel(QObject *parent = nullptr);
|
|
~ViewModel();
|
|
|
|
virtual ViewModel *parentViewModel() const;
|
|
|
|
bool deleteOnClose() const;
|
|
|
|
template <typename TViewModel>
|
|
inline static void show(const QVariantHash ¶ms = {});
|
|
|
|
public Q_SLOTS:
|
|
void setDeleteOnClose(bool deleteOnClose);
|
|
|
|
virtual void onInit(const QVariantHash ¶ms);
|
|
|
|
Q_SIGNALS:
|
|
void deleteOnCloseChanged(bool deleteOnClose, QPrivateSignal);
|
|
|
|
protected:
|
|
template <typename TViewModel>
|
|
inline void showChild(const QVariantHash ¶ms = {}) const;
|
|
|
|
private:
|
|
QScopedPointer<ViewModelPrivate> d;
|
|
|
|
static void showImp(const QMetaObject *mo, const QVariantHash ¶ms, QPointer<ViewModel> parent);
|
|
};
|
|
|
|
template<typename TViewModel>
|
|
inline void ViewModel::show(const QVariantHash ¶ms)
|
|
{
|
|
static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel");
|
|
showImp(&TViewModel::staticMetaObject, params, nullptr);
|
|
}
|
|
|
|
template<typename TViewModel>
|
|
inline void ViewModel::showChild(const QVariantHash ¶ms) const
|
|
{
|
|
static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel");
|
|
showImp(&TViewModel::staticMetaObject, params, const_cast<ViewModel*>(this));
|
|
}
|
|
|
|
}
|
|
|
|
#endif // QTMVVM_VIEWMODEL_H
|
|
|