Skycoder42
7 years ago
12 changed files with 443 additions and 38 deletions
@ -0,0 +1,159 @@ |
|||||
|
/*! |
||||
|
@class QtMvvm::InputViewFactory |
||||
|
|
||||
|
The factory is used by the QuickPresenter to create input views and delegates for various |
||||
|
types. This is used to for example create the edits of input dialogs or for the list delegates |
||||
|
of a SettingsView. |
||||
|
|
||||
|
@sa QuickPresenter, QuickPresenter::inputViewFactory, MessageConfig::TypeInputDialog, |
||||
|
QtMvvm::getInput, SettingsViewModel |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::getInputUrl |
||||
|
|
||||
|
@param type The input type to create a view for |
||||
|
@param viewProperties A map with extra properties to be set on the edit |
||||
|
@returns A url to a QML component suitable for editing input of the given type |
||||
|
|
||||
|
The factory first checks if the given type is registered as alias. If yes, it continues with |
||||
|
the aliased type. Then it checks for a url registered as simple view exists for the given |
||||
|
type and uses that one if present. If no simple view is set the default mapping for type to |
||||
|
urls is used (See MessageConfig::TypeInputDialog for a full table of supported types). If no |
||||
|
url can be found for a type, an invalid url is returned. |
||||
|
|
||||
|
The viewProperties are used to setup the created view by settings them as properties on the |
||||
|
view. For every key-value-pair in the map, QObject::setProperty is called on the view to |
||||
|
set the property. |
||||
|
|
||||
|
@sa MessageConfig::TypeInputDialog, InputViewFactory::addSimpleInput, |
||||
|
InputViewFactory::addInputAlias, InputViewFactory::getDelegate |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::getDelegate |
||||
|
|
||||
|
@param type The input type to create a delegate for |
||||
|
@param viewProperties A map with extra properties to be set on the delegate |
||||
|
@returns A url to a QML component suitable for editing input of the given type, as a delegate |
||||
|
|
||||
|
Delegates can be used to provide "editabel" list items for ListViews. (For example, the |
||||
|
SettingsView makes use of them). Available roles are: |
||||
|
- group |
||||
|
- key |
||||
|
- type |
||||
|
- title |
||||
|
- tooltip |
||||
|
- delegateUrl |
||||
|
- inputValue |
||||
|
- properties |
||||
|
|
||||
|
The factory first checks if the given type is registered as alias. If yes, it continues with |
||||
|
the aliased type. Then it checks for a url registered as simple delegate exists for the given |
||||
|
type and uses that one if present. If no simple delegate is set the default mapping for type |
||||
|
to urls is used (See MessageConfig::TypeInputDialog for a full table of supported types). If |
||||
|
no url can be found for a type, the MsgDelegate is returned, which will simply show an input |
||||
|
of the given type. Thus, for all not explicitly supported delegate types, the getInputUrl() is |
||||
|
used to find an edit for the dialog. |
||||
|
|
||||
|
The viewProperties are used to setup the created delegate by settings them as properties on |
||||
|
the delegate. For every key-value-pair in the map, QObject::setProperty is called on the |
||||
|
delegate to set the property. |
||||
|
|
||||
|
@sa MessageConfig::TypeInputDialog, InputViewFactory::addSimpleDelegate, |
||||
|
InputViewFactory::addDelegateAlias, InputViewFactory::getInputUrl |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addSimpleInput(const QUrl &) |
||||
|
|
||||
|
@tparam TType The type to add an input view for |
||||
|
@param qmlFileUrl The URL of the QML file that contains the component |
||||
|
|
||||
|
The qmlFileUrl must be a valid URL to a QML file with a displayable quick item. The item must |
||||
|
have a property named `inputValue` that is used to read and write the edit data. |
||||
|
|
||||
|
@sa InputViewFactory::getInputUrl, InputViewFactory::addInputAlias |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addSimpleInput(const QByteArray &, const QUrl &) |
||||
|
|
||||
|
@param type The type to add an input view for |
||||
|
@param qmlFileUrl The URL of the QML file that contains the component |
||||
|
|
||||
|
The qmlFileUrl must be a valid URL to a QML file with a displayable quick item. The item must |
||||
|
have a property named `inputValue` that is used to read and write the edit data. |
||||
|
|
||||
|
@sa InputViewFactory::getInputUrl, InputViewFactory::addInputAlias |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addSimpleDelegate(const QUrl &) |
||||
|
|
||||
|
@tparam TType The type to add a delegate view for |
||||
|
@param qmlFileUrl The URL of the QML file that contains the component |
||||
|
|
||||
|
The qmlFileUrl must be a valid URL to a QML file with a displayable quick item that can be |
||||
|
used as a delegate for a ListView. |
||||
|
|
||||
|
@sa InputViewFactory::getDelegate, InputViewFactory::addDelegateAlias |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addSimpleDelegate(const QByteArray &, const QUrl &) |
||||
|
|
||||
|
@param type The type to add a delegate view for |
||||
|
@param qmlFileUrl The URL of the QML file that contains the component |
||||
|
|
||||
|
The qmlFileUrl must be a valid URL to a QML file with a displayable quick item that can be |
||||
|
used as a delegate for a ListView. |
||||
|
|
||||
|
@sa InputViewFactory::getDelegate, InputViewFactory::addDelegateAlias |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addInputAlias() |
||||
|
|
||||
|
@tparam TAliasType The type to add as a new alias |
||||
|
@tparam TTargetType The type the alias should be translated to |
||||
|
|
||||
|
If an input view for the alias type is requested, one of the target type is created instead. |
||||
|
|
||||
|
@sa InputViewFactory::getInputUrl, InputViewFactory::addSimpleInput |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addInputAlias(const QByteArray &, const QByteArray &) |
||||
|
|
||||
|
@param alias The type to add as a new alias |
||||
|
@param targetType The type the alias should be translated to |
||||
|
|
||||
|
If an input view for the alias type is requested, one of the target type is created instead. |
||||
|
|
||||
|
@sa InputViewFactory::getInputUrl, InputViewFactory::addSimpleInput |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addDelegateAlias() |
||||
|
|
||||
|
@tparam TAliasType The type to add as a new alias |
||||
|
@tparam TTargetType The type the alias should be translated to |
||||
|
|
||||
|
If an delegate view for the alias type is requested, one of the target type is created |
||||
|
instead. |
||||
|
|
||||
|
@sa InputViewFactory::getDelegate, InputViewFactory::addSimpleDelegate |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::InputViewFactory::addDelegateAlias(const QByteArray &, const QByteArray &) |
||||
|
|
||||
|
@param alias The type to add as a new alias |
||||
|
@param targetType The type the alias should be translated to |
||||
|
|
||||
|
If an delegate view for the alias type is requested, one of the target type is created |
||||
|
instead. |
||||
|
|
||||
|
@sa InputViewFactory::getDelegate, InputViewFactory::addSimpleDelegate |
||||
|
*/ |
@ -0,0 +1,132 @@ |
|||||
|
/*! |
||||
|
@class QtMvvm::QuickPresenter |
||||
|
|
||||
|
This presenter is automatically registered as the default presenter for the IPresenter |
||||
|
interface with the ServiceRegistry, but as weak service, in order to make it possible to |
||||
|
overwrite it. |
||||
|
|
||||
|
The class handles all the logic required for presenting Quick Controsl 2 based views. You can |
||||
|
extend this class and reimplement it's virtual methods if you need to adjust how certain views |
||||
|
or dialogs are presented, or if you want to support custom stuff. |
||||
|
|
||||
|
By default, the presenter will use the `":/qtmvvm/views"` directory for finding views. When |
||||
|
presenting a viewmodel, the presenter tries to find a view url with a matching name. If the |
||||
|
viewmodel is for example named `MyViewModel`, then the view must start with `My` too. For |
||||
|
example it can be named `MyView.qml` or `MyDialog.qml` |
||||
|
|
||||
|
@note Implicit detection of views for viewmodels can sometimes lead to ambiguities and thus a |
||||
|
wrong view beeing found. In such cases, use registerViewExplicitly() instead. |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@property QtMvvm::QuickPresenter::inputViewFactory |
||||
|
|
||||
|
@default{<i>Injected</i>} |
||||
|
|
||||
|
Do not set this property yourself. It is automatically injected when showing the viewmodel. |
||||
|
You can use the ServiceRegistry::registerInterface if you need to use a factory different from |
||||
|
the default one. |
||||
|
|
||||
|
@accessors{ |
||||
|
@readAc{inputViewFactory()} |
||||
|
@writeAc{setInputViewFactory()} |
||||
|
@notifyAc{inputViewFactoryChanged()} |
||||
|
} |
||||
|
|
||||
|
@sa #QTMVVM_INJECT |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::addViewSearchDir |
||||
|
|
||||
|
@param dirPath A path to directory to be searched for input views |
||||
|
|
||||
|
Simply adds the directory to the ones beeing searched for views. The new directoy will be |
||||
|
prepended to the search list and thus be searched before any other directory. |
||||
|
|
||||
|
@sa QuickPresenter::registerViewExplicitly |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::registerViewExplicitly(const QUrl &) |
||||
|
|
||||
|
@tparam TViewModel The viewmodel to to register the view for |
||||
|
@param viewUrl The QML url register within the presenter. Must be a valid qml component |
||||
|
|
||||
|
The url is registered with the current presenter. It is registered explicitly, which means |
||||
|
that whenever the given viewmodel is beeing presented, this exact url will be used. Explicit |
||||
|
registration have precedence over implicit ones. |
||||
|
|
||||
|
@sa QuickPresenter::addViewSearchDir |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::registerViewExplicitly(const QMetaObject *, const QUrl &) |
||||
|
|
||||
|
@param viewModelType The viewmodel to to register the view for |
||||
|
@param viewUrl The QML url register within the presenter. Must be a valid qml component |
||||
|
|
||||
|
The url is registered with the current presenter. It is registered explicitly, which means |
||||
|
that whenever the given viewmodel is beeing presented, this exact url will be used. Explicit |
||||
|
registration have precedence over implicit ones. |
||||
|
|
||||
|
@sa QuickPresenter::addViewSearchDir |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::presentToQml |
||||
|
|
||||
|
@param qmlPresenter The presenter to present the view to |
||||
|
@param viewObject The view QML object to be presented |
||||
|
@returns `true` if successfully presented, `false` if not |
||||
|
|
||||
|
Is called from the qml presentation part to actually present a view to another view that takes |
||||
|
the role of a presenter, or the actual main presenter. |
||||
|
|
||||
|
The default implementation uses presentMethodIndex() to find a method to call, then calls it |
||||
|
and returns the result of that method call. If no method was found, false is returned. |
||||
|
|
||||
|
@sa QuickPresenter::presentMethodIndex |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::findViewUrl |
||||
|
|
||||
|
@param viewModelType The metobject of the viewmodel to find a view for |
||||
|
@returns The URL of the found file |
||||
|
@throws PresenterException If no view url could be found |
||||
|
|
||||
|
The default implementation simply check all explicitly registered views and then tries to |
||||
|
match the name with all qml files available in the search dirs. If no match if found, the |
||||
|
same is tried for the parent viewmodel type recursively, until the ViewModel base is reached. |
||||
|
|
||||
|
@sa QuickPresenter::addViewSearchDir |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::presentMethodIndex |
||||
|
|
||||
|
@param presenterMetaObject The metobject of the presenter to search a method on |
||||
|
@param viewObject The QML item to be presented on that presenter |
||||
|
@returns The index of the method from the meta object to be called, or `-1` if no method could |
||||
|
be found. |
||||
|
|
||||
|
This method is called to find the method. The method must take a single argument, the view to |
||||
|
be presented, and return a bool to report whether presenting actually worked or not. The |
||||
|
default implementation first checks if the view extends QQuickPopup, and if yes looks for the |
||||
|
`presentPopup` method. If the view is a normal QQuickItem, the name is analyzed. If the name |
||||
|
contains `Drawer`, the `presentDrawerContent` method is checkd. If the name contains `Tab`, |
||||
|
the `presentTab` method is checkd. If none applies or none was found, the method looks for the |
||||
|
`presentItem` method. If that one is not found as well, `-1 is returned. |
||||
|
|
||||
|
@sa QuickPresenter::presentToQml |
||||
|
*/ |
||||
|
|
||||
|
/*! |
||||
|
@fn QtMvvm::QuickPresenter::nameOrClassContains |
||||
|
|
||||
|
@param obj The object to search for the string |
||||
|
@param contained The string to be searched |
||||
|
@param caseSensitive Specifies if the check should be case sensitive |
||||
|
@returns `true` if the object or class name contain the string, `false` if not |
||||
|
*/ |
Loading…
Reference in new issue