-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use custom type for data value in qml delegate
We register a custom type (class) with the QVariant metasystem and pass that back from the QAbstractItemModel into qml. For demonstration purposes we chose to use this custom type to additionally transport the indentation from the input file as an int.
- Loading branch information
Showing
9 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import QtQuick 2.0 | ||
import hvoigt.net 1.0 | ||
|
||
Item { | ||
Text { | ||
anchors.fill: parent | ||
color: styleData.textColor | ||
elide: styleData.elideMode | ||
text: styleData.value.indentation + ": " + styleData.value.text | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "customtype.h" | ||
|
||
CustomType::CustomType(QObject *parent) : QObject(parent), myIndentation(0) | ||
{ | ||
} | ||
|
||
CustomType::CustomType(const CustomType &other) | ||
{ | ||
myText = other.myText; | ||
myIndentation = other.myIndentation; | ||
} | ||
|
||
CustomType::~CustomType() | ||
{ | ||
} | ||
|
||
QString CustomType::text() | ||
{ | ||
return myText; | ||
} | ||
|
||
void CustomType::setText(QString text) | ||
{ | ||
myText = text; | ||
emit textChanged(); | ||
} | ||
|
||
int CustomType::indentation() | ||
{ | ||
return myIndentation; | ||
} | ||
|
||
void CustomType::setIndentation(int indentation) | ||
{ | ||
myIndentation = indentation; | ||
emit indentationChanged(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef CUSTOMTYPE_H | ||
#define CUSTOMTYPE_H | ||
|
||
#include <QObject> | ||
|
||
class CustomType : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) | ||
Q_PROPERTY(int indentation READ indentation WRITE setIndentation NOTIFY indentationChanged) | ||
|
||
public: | ||
explicit CustomType(QObject *parent = 0); | ||
CustomType(const CustomType &other); | ||
~CustomType(); | ||
|
||
QString text(); | ||
void setText(QString text); | ||
|
||
int indentation(); | ||
void setIndentation(int indentation); | ||
|
||
signals: | ||
void textChanged(); | ||
void indentationChanged(); | ||
|
||
private: | ||
QString myText; | ||
int myIndentation; | ||
}; | ||
|
||
Q_DECLARE_METATYPE(CustomType) | ||
|
||
#endif // CUSTOMTYPE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters