diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-08-10 12:00:45 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-01-15 12:32:08 +0000 |
commit | 8396dc86f28e89a920d85f59518fac79da8480eb (patch) | |
tree | e38220c0049d50f289625563933b702cc39bc540 /src/qml/jsruntime | |
parent | aca0351c7ce933503b042fd8d745d220c7dd331d (diff) |
StorageModel manual test: use DelegateChoices to show data graphically
This demonstrates that DelegateChooser and DelegateChoice are working
with TableView.
In this use case, DelegateChooser uses a role from the model to
decide which delegate type to instantiate. So we need the model to
provide a type role that it can switch on. Conveniently, by using the
Q_ENUM registration of the Type enum, it automatically becomes
possible to match against the stringified versions of those enum
values in the DelegateChoice.roleValue property.
To demonstrate a set of roles which would work for almost any kind of
numeric data, we choose to have a Value role for the current value,
corresponding to the width of the bar or the numerator of the ratio;
and ValueMax for the maximum possible value, corresponding to the
total width of the bar graph, or the denominator of the ratio.
ValueDisplay and ValueMaxDisplay are roles which provide
string-formatted versions of those for labeling purposes. Maybe in
the future we could consider adding those (plus ValueMin and
ValueMinDisplay) to the ItemDataRole enum; because almost any kind of
data model could need to provide numeric data, but for some reason we
have only made it easy to provide strings (DisplayRole) and booleans
(CheckStateRole). Likewise some sort of type role could be
standardized at the same time.
Free / used space is graphically shown as a bar graph. QStorageInfo
provides bytesFree() but not bytesUsed(), but it's more conventional
to show a bar which grows wider as more space is used, so we reverse
it visually by showing a red background with the bytesFree bar
anchored to the right. Thus the width of the red part showing through
is proportional to bytes used.
The three flags isReady, isReadOnly and isValid are shown with
simulated checkboxes.
This manual test is now on its way to becoming an example of how to
use row, column and role effectively together. It's not enough to say
that TableView is only for spreadsheet-like views, displaying only
text in each cell. To display more than text, we can do the same
thing that we have done in the past with models designed for display
with ListView: use the role, so that data(index, role) gets called
multiple times for each cell, to get the values that each delegate
type needs to use to render itself.
Change-Id: I1060eacc2b7d25f420411828258e7d94ee0bdd0b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
0 files changed, 0 insertions, 0 deletions