Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit ec1b2a3

Browse files
committed
update quick doc
1 parent 6f9cdad commit ec1b2a3

File tree

6 files changed

+113
-7
lines changed

6 files changed

+113
-7
lines changed

doc/inputviewfactory.dox

+94
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ delegate to set the property.
6464
InputViewFactory::addDelegateAlias, InputViewFactory::getInputUrl
6565
*/
6666

67+
/*!
68+
@fn QtMvvm::InputViewFactory::format
69+
70+
@param type The type to choose a formatter for
71+
@param formatString Some kind of format string, depending on what the formatter wants here
72+
@param value The actual value, packet as a variant
73+
@param viewProperties Additional properies set on the delegate
74+
@returns The formatted value text
75+
76+
Internally, this method uses the Formatter registered for the given type and then returns
77+
the result of Formatter::format, invoked with the remaining parameters.
78+
79+
If no formatter was registered for the given type, this method simply returns
80+
`formatString.arg(value.toString());`
81+
82+
Currently, the following special formatters are set by default.
83+
84+
types | formatString semantics
85+
----------------------------|------------------------
86+
int | A translated string with either `%1`, `%L1` or `%n` as number placeholder. If `%n` is used, "plural-translations" are used
87+
list, selection, radiolist | A translated string with `%1` as placeholder. If the list element is named, that one is used, otherwise the value itself
88+
QDateTime, QDate, QTime | Can either be the integer value of one of Qt::DateFormat or a standard date format string (QDateTime::toString). If neither is the case, the date is formatted using Qt::DefaultLocaleShortDate
89+
double | Uses the SimpleFormatter with double as template argument
90+
91+
All other types use the fallback formatting.
92+
93+
@sa Formatter::format, InputViewFactory::addFormatter, InputViewFactory::addFormatterAlias
94+
*/
95+
6796
/*!
6897
@fn QtMvvm::InputViewFactory::addSimpleInput(const QUrl &)
6998

@@ -112,6 +141,30 @@ used as a delegate for a ListView.
112141
@sa InputViewFactory::getDelegate, InputViewFactory::addDelegateAlias
113142
*/
114143

144+
/*!
145+
@fn QtMvvm::InputViewFactory::addFormatter(Formatter*)
146+
147+
@tparam TType The type to add a formatter for
148+
@param formatter The formatter instance to be added
149+
150+
The formatter must be valid and is registered in the factory. The factory takes ownership of
151+
the passed formatter. From now on it is used to convert display texts when format() is called.
152+
153+
@sa InputViewFactory::format, InputViewFactory::addFormatterAlias, Formatter
154+
*/
155+
156+
/*!
157+
@fn QtMvvm::InputViewFactory::addFormatter(const QByteArray &, Formatter*)
158+
159+
@param type The type to add a formatter for
160+
@param formatter The formatter instance to be added
161+
162+
The formatter must be valid and is registered in the factory. The factory takes ownership of
163+
the passed formatter. From now on it is used to convert display texts when format() is called.
164+
165+
@sa InputViewFactory::format, InputViewFactory::addFormatterAlias, Formatter
166+
*/
167+
115168
/*!
116169
@fn QtMvvm::InputViewFactory::addInputAlias()
117170

@@ -157,3 +210,44 @@ instead.
157210

158211
@sa InputViewFactory::getDelegate, InputViewFactory::addSimpleDelegate
159212
*/
213+
214+
/*!
215+
@fn QtMvvm::InputViewFactory::addFormatterAlias()
216+
217+
@tparam TAliasType The type to add as a new alias
218+
@tparam TTargetType The type the alias should be translated to
219+
220+
If a formatter for the alias type is requested for the format() method, the one of the target
221+
type is used instead.
222+
223+
@sa InputViewFactory::format, InputViewFactory::addFormatter
224+
*/
225+
226+
/*!
227+
@fn QtMvvm::InputViewFactory::addFormatterAlias(const QByteArray &, const QByteArray &)
228+
229+
@param alias The type to add as a new alias
230+
@param targetType The type the alias should be translated to
231+
232+
If a formatter for the alias type is requested for the format() method, the one of the target
233+
type is used instead.
234+
235+
@sa InputViewFactory::format, InputViewFactory::addFormatter
236+
*/
237+
238+
239+
240+
/*!
241+
@fn QtMvvm::Formatter::format
242+
243+
@param formatString Some kind of format string, depending on what your formatter wants here
244+
@param value The actual value, packet as a variant
245+
@param viewProperties Additional properies set on the delegate
246+
@return A localized, human readable text, the formatted the value based on formatString
247+
248+
formatString can be whatever you need it to be, but typically it is a localized text with a
249+
placeholder to be replaced with the given value. See InputViewFactory::format for known
250+
formats.
251+
252+
@sa InputViewFactory::format
253+
*/

doc/message.dox

+7-5
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,16 @@ create edit views yourself
247247
Type | Widgets edit | Quick edit | Quick delegate
248248
------------------------|-------------------------------|---------------|----------------
249249
bool | QCheckBox | CheckBox | BoolDelegate
250-
switch | -/- | Switch | SwitchDelegate
250+
switch | QCheckBox | Switch | SwitchDelegate
251251
QString, string | QLineEdit | TextField | MsgDelegate (*)
252252
int | QSpinBox | SpinBox | MsgDelegate
253253
double, number | QDoubleSpinBox | DoubleSpinBox | MsgDelegate
254-
QDate | QDateEdit | -/- | -/-
255-
QTime | QTimeEdit | -/- | -/-
256-
QDateTime, date | QDateTimeEdit | -/- | -/-
257-
QFont | QFontComboBox | FontEdit | MsgDelegate
254+
range (int) | QSlider | Slider | RangeDelegate
255+
QDate | QDateEdit | DateEdit | MsgDelegate
256+
QTime | QTimeEdit | TimeEdit | MsgDelegate
257+
QDateTime, date | QDateTimeEdit | DateTimeEdit | MsgDelegate
258+
QColor, color | ColorButton | ColorEdit | ColorDelegate
259+
QFont, font | QFontComboBox | FontEdit | MsgDelegate
258260
QKeySequence | QKeySequenceEdit | -/- | -/-
259261
QUrl, url | QLineEdit with QUrlValidator | UrlField | MsgDelegate
260262
selection, list | QComboBox | ListEdit | ListDelegate

src/imports/mvvmdatasynccore/plugins.qmltypes

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ Module {
114114
exportMetaObjectRevisions: [0]
115115
Property { name: "key"; type: "string" }
116116
Property { name: "dataVersion"; type: "int" }
117-
Property { name: "value"; type: "QByteArray" }
118-
Property { name: "variantValue"; type: "QVariant" }
117+
Property { name: "value"; type: "QVariant" }
118+
Property { name: "valueData"; type: "QByteArray" }
119119
}
120120
Component {
121121
name: "QtMvvm::DataSyncSettingsViewModel"

src/mvvmquick/inputviewfactory.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void InputViewFactory::addSimpleDelegate(const QByteArray &type, const QUrl &qml
7979

8080
void InputViewFactory::addFormatter(const QByteArray &type, Formatter *formatter)
8181
{
82+
Q_ASSERT_X(formatter, Q_FUNC_INFO, "formatter must not be null");
8283
d->formatters.insert(type, QSharedPointer<Formatter>{formatter});
8384
}
8485

src/mvvmquick/inputviewfactory.h

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace QtMvvm {
1414

15+
//! A class to format the preview text in the delegates
1516
class Q_MVVMQUICK_EXPORT Formatter
1617
{
1718
Q_DISABLE_COPY(Formatter)
@@ -20,11 +21,13 @@ class Q_MVVMQUICK_EXPORT Formatter
2021
Formatter();
2122
virtual ~Formatter();
2223

24+
//! Is called to format a value to a localized, human readable text
2325
virtual QString format(const QString &formatString,
2426
const QVariant &value,
2527
const QVariantMap &viewProperties) const = 0;
2628
};
2729

30+
//! A very basic formatter that uses QString::arg with the value on the format string
2831
template <typename T>
2932
class SimpleFormatter : public Formatter
3033
{
@@ -50,6 +53,7 @@ class Q_MVVMQUICK_EXPORT InputViewFactory : public QObject
5053
//! Find the input list delegate URL of the given input type
5154
Q_INVOKABLE virtual QUrl getDelegate(const QByteArray &type, const QVariantMap &viewProperties);
5255

56+
//! Formats the value using the internally registered Formatter for the given type
5357
QTMVVM_REVISION_1 Q_INVOKABLE QString format(const QByteArray &type,
5458
const QString &formatString,
5559
const QVariant &value,
@@ -67,8 +71,10 @@ class Q_MVVMQUICK_EXPORT InputViewFactory : public QObject
6771
//! @copybrief addSimpleDelegate(const QUrl &)
6872
Q_INVOKABLE virtual void addSimpleDelegate(const QByteArray &type, const QUrl &qmlFileUrl);
6973

74+
//! Adds a new Formatter to format delegate preview texts for the given type
7075
template <typename TType>
7176
inline void addFormatter(Formatter *formatter);
77+
//! @copybrief addFormatter(Formatter*)
7278
void addFormatter(const QByteArray &type, Formatter *formatter); //MAJOR make virtual
7379

7480
//! Adds a type name alias for views
@@ -83,8 +89,10 @@ class Q_MVVMQUICK_EXPORT InputViewFactory : public QObject
8389
//! @copybrief addDelegateAlias()
8490
Q_INVOKABLE virtual void addDelegateAlias(const QByteArray &alias, const QByteArray &targetType);
8591

92+
//! Adds a type name alias for formatters
8693
template <typename TAliasType, typename TTargetType>
8794
inline void addFormatterAlias();
95+
//! @copybrief addFormatterAlias()
8896
QTMVVM_REVISION_1 Q_INVOKABLE void addFormatterAlias(const QByteArray &alias, const QByteArray &targetType);
8997

9098
private:

src/mvvmquick/quickpresenter.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Q_MVVMQUICK_EXPORT QuickPresenter : public QObject, public IPresenter
4242
//! @copybrief registerViewExplicitly()
4343
static void registerViewExplicitly(const QMetaObject *viewModelType, const QUrl &viewUrl);
4444

45+
//! Returns the internally used input view factory
4546
static InputViewFactory* getInputViewFactory();
4647

4748
void present(ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent) override;

0 commit comments

Comments
 (0)