Originally Posted by
wysota
Are you sure form0 is defined for every object in the model? Can you prepare a minimal compilable example reproducing the problem?
Element:
class IrregularVerb
: public QObject{
Q_OBJECT
Q_PROPERTY(QString form0 READ getForm0 NOTIFY formChanged
) Q_PROPERTY(QString form1 READ getForm1 NOTIFY formChanged
) Q_PROPERTY(QString form2 READ getForm2 NOTIFY formChanged
) public:
QString getForm0
() const { return getForm
(0);
} QString getForm1
() const { return getForm
(1);
} QString getForm2
() const { return getForm
(2);
} protected:
const QString& getForm(const int& ind) const { return forms[ind]; }
signals:
void formChanged();
};
class IrregularVerb : public QObject
{
Q_OBJECT
Q_PROPERTY(QString form0 READ getForm0 NOTIFY formChanged)
Q_PROPERTY(QString form1 READ getForm1 NOTIFY formChanged)
Q_PROPERTY(QString form2 READ getForm2 NOTIFY formChanged)
public:
QString forms[3];
QString getForm0() const { return getForm(0); }
QString getForm1() const { return getForm(1); }
QString getForm2() const { return getForm(2); }
IrregularVerb(QString a, QString b, QString c) { forms[0] = a; forms[1] = b; forms[2] = c; }
protected:
const QString& getForm(const int& ind) const { return forms[ind]; }
signals:
void formChanged();
};
To copy to clipboard, switch view to plain text mode
Container for elements:
class german : public QList<QObject*>
{
public:
german();
};
german::german()
{
append(new IrregularVerb("anfangen", "fing an", "angefangen")); // and so on
}
class german : public QList<QObject*>
{
public:
german();
};
german::german()
{
append(new IrregularVerb("anfangen", "fing an", "angefangen")); // and so on
}
To copy to clipboard, switch view to plain text mode
Class managing the containers:
class IrregularListWrapper
: public QObject{
Q_OBJECT
Q_PROPERTY(QList<QObject*> db READ getdb NOTIFY langChanged)
Q_ENUMS(Language)
public:
enum Language
{
English = 0,
German = 1
};
IrregularListWrapper() : db(0) { setLang(German); }
~IrregularListWrapper() { delete db; }
QList<QObject*> getdb() const { return *db; }
Q_INVOKABLE void changeLang(Language l) { delete db; setLang(l); }
signals:
void langChanged();
protected:
void setLang(Language);
QList<QObject*> * db;
};
void IrregularListWrapper::setLang(Language l)
{
switch (l)
{
case English:
db = new english;
langName = "English";
break;
case German:
db = new german;
langName = "German";
break;
}
emit langChanged();
}
class IrregularListWrapper : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<QObject*> db READ getdb NOTIFY langChanged)
Q_ENUMS(Language)
public:
enum Language
{
English = 0,
German = 1
};
IrregularListWrapper() : db(0) { setLang(German); }
~IrregularListWrapper() { delete db; }
QList<QObject*> getdb() const { return *db; }
Q_INVOKABLE void changeLang(Language l) { delete db; setLang(l); }
signals:
void langChanged();
protected:
void setLang(Language);
QList<QObject*> * db;
};
void IrregularListWrapper::setLang(Language l)
{
switch (l)
{
case English:
db = new english;
langName = "English";
break;
case German:
db = new german;
langName = "German";
break;
}
emit langChanged();
}
To copy to clipboard, switch view to plain text mode
ListView:
ListView
{
id: irrview
width: parent.width
model: irregulars.db
anchors.top: caption.bottom
anchors.bottom: parent.bottom
spacing: 5
clip: true
section.criteria: ViewSection.FirstCharacter
section.property: "form0"
section.delegate: Item {height: 10; width: parent.width; Text { text: section } }
delegate: Rectangle
{
height: 60
width: parent.width
color: "#E0E1E2"
Row
{
height: parent.height
width: parent.width - 10
anchors.horizontalCenter: parent.horizontalCenter
property real columnWidth: (width - 10) / 3
property int rad: 10
spacing: 5
Rectangle
{
height: parent.height
width: parent.columnWidth
radius: parent.rad
Text
{
anchors.centerIn: parent
text: modelData.form0
}
}
Rectangle
{
height: parent.height
width: parent.columnWidth
radius: parent.rad
Text
{
anchors.centerIn: parent
text: modelData.form1
font.pointSize: 24
}
}
Rectangle
{
height: parent.height
width: parent.columnWidth
radius: parent.rad
Text
{
anchors.centerIn: parent
text: modelData.form2
}
}
}
}
}
ListView
{
id: irrview
width: parent.width
model: irregulars.db
anchors.top: caption.bottom
anchors.bottom: parent.bottom
spacing: 5
clip: true
section.criteria: ViewSection.FirstCharacter
section.property: "form0"
section.delegate: Item {height: 10; width: parent.width; Text { text: section } }
delegate: Rectangle
{
height: 60
width: parent.width
color: "#E0E1E2"
Row
{
height: parent.height
width: parent.width - 10
anchors.horizontalCenter: parent.horizontalCenter
property real columnWidth: (width - 10) / 3
property int rad: 10
spacing: 5
Rectangle
{
height: parent.height
width: parent.columnWidth
radius: parent.rad
Text
{
anchors.centerIn: parent
text: modelData.form0
}
}
Rectangle
{
height: parent.height
width: parent.columnWidth
radius: parent.rad
Text
{
anchors.centerIn: parent
text: modelData.form1
font.pointSize: 24
}
}
Rectangle
{
height: parent.height
width: parent.columnWidth
radius: parent.rad
Text
{
anchors.centerIn: parent
text: modelData.form2
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
All the forms (form0, form1, form2) are displayed in teh ListView, and all the model elements are displayed.
If there's too much code, let me know
Bookmarks