QML ListModel for interaction with C++
Hey Guys,
I am already struggling with this problem for about 3 days... seems I am kinda stuck now =/.
What I want: I want a QList<T> to interact with my QML view - dynamically - so if I remove an item via a C++ interface call to the model the item should disappear in the QML view
What I know so far: I recognized (logical anyways) that the QList i had before:
Code:
//Q_PROPERTY(QDeclarativeListProperty<TaskData> taskData READ taskData CONSTANT)
//QDeclarativeListProperty<TaskData> taskData();
wasn't working because it provides no notification for the view -> after some research I decided to implement my own ListModel then...
The Model seems to work but the View does not display anything...
QMLPtrNotificationModel.h looks like shown below:
Code:
class QMLPtrAbstractItem : public QDeclarativeItem
{
public:
QMLPtrAbstractItem(QDeclarativeItem *parent = 0);
virtual ~QMLPtrAbstractItem() { }
virtual QString getName
() const = 0;
virtual QString setName
() const = 0;
};
{
Q_OBJECT
public:
explicit QMLPtrNotificationModel
(QObject *parent
= 0);
QMLPtrNotificationModel
(const QList<QMLPtrAbstractItem
*>
&list,
QObject *parent
= 0);
~QMLPtrNotificationModel();
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
QList<QMLPtrAbstractItem*> operator()();
const QList<QMLPtrAbstractItem*> operator()();
QList<QMLPtrAbstractItem*> getList() const;
void setList(const QList<QMLPtrAbstractItem*> &list);
QMLPtrAbstractItem* at(int index);
bool addElement(QMLPtrAbstractItem *element);
bool removeElement(QMLPtrAbstractItem *element);
bool clear();
Qt::DropActions supportedDropActions() const;
private Q_SLOTS:
void refresh();
private:
Q_DISABLE_COPY(QMLPtrNotificationModel)
QList<QMLPtrAbstractItem*> lst;
};
QML_DECLARE_TYPE(QMLPtrNotificationModel)
The QMLPtrNotificationModel.cpp looks like shown below (not all functions provided - I think that not all are necessary to document the problem)
Code:
QMLPtrAbstractItem::QMLPtrAbstractItem(QDeclarativeItem *parent)
: QDeclarativeItem(parent)
{
}
QMLPtrNotificationModel
::QMLPtrNotificationModel(QObject *parent
){
}
QMLPtrNotificationModel
::QMLPtrNotificationModel(const QList<QMLPtrAbstractItem
*>
&list,
QObject *parent
){
}
QMLPtrNotificationModel::~QMLPtrNotificationModel()
{
clear();
}
int QMLPtrNotificationModel
::rowCount(const QModelIndex &parent
) const {
if (parent.isValid())
return 0;
return lst.count();
}
{
if (index.row() < 0 || index.row() >= lst.size())
if (role == Qt::DisplayRole || role == Qt::EditRole)
return lst.at(index.row())->getName();
}
Qt
::ItemFlags QMLPtrNotificationModel
::flags(const QModelIndex &index
) const{
if (!index.isValid())
return QAbstractItemModel::flags(index
) | Qt
::ItemIsEditable | Qt
::ItemIsDragEnabled | Qt
::ItemIsDropEnabled;
}
bool QMLPtrNotificationModel
::setData(const QModelIndex &index,
const QVariant &value,
int role
) {
if (index.row() >= 0 && index.row() < lst.size()
&& (role == Qt::EditRole || role == Qt::DisplayRole)) {
lst.at(index.row())->setName(value.toString());
emit dataChanged(index, index);
return true;
}
return false;
}
bool QMLPtrNotificationModel
::insertRows(int row,
int count,
const QModelIndex &parent
) {
if (count < 1 || row < 0 || row > rowCount(parent))
return false;
for (int r = 0; r < count; ++r){
lst.insert(row, NULL);
}
endInsertRows();
return true;
}
bool QMLPtrNotificationModel
::removeRows(int row,
int count,
const QModelIndex &parent
) {
if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
return false;
for (int r = 0; r < count; ++r){
delete lst.at(row);
lst.removeAt(row);
}
endRemoveRows();
return true;
}
bool QMLPtrNotificationModel::clear()
{
}
bool QMLPtrNotificationModel::addElement(QMLPtrAbstractItem *element)
{
int position = rowCount();
lst << element;
return true;
}
return false;
}
bool QMLPtrNotificationModel::removeElement(QMLPtrAbstractItem *element)
{
int position = lst.indexOf(element);
return true;
}
return false;
}
QMLPtrAbstractItem* QMLPtrNotificationModel::at(int index)
{
return lst.at(index);
}
It seems QML doesn't recognize anthing - the structure looks as follows:
Code:
import QtQuick 1.1
import QMLPtrNotificationModel 1.0
Item {
property variant orientation: Qt.Vertical
ListView {
id: completeTable
QMLPtrNotificationModel {
id: myListmodel
}
model: myListmodel
delegate: TaskData { }
}
And i registered QMLPtrNotificationModel as QML Type via C++ like that:
Code:
qmlRegisterType<QMLPtrNotificationModel>("QMLPtrNotificationModel", 1, 0, "QMLPtrNotificationModel");
I know it's a big part of code for a single post - but I think the error is in both parts, QML and the Model itself.. looks like missing notifications again?
Would be really lovely if anybody of you has an idea to fix this issue -> my QML view is empty at the moment (I added elements via addElement())
The Elements to add are correctly derived from QMLPtrAbstractItem and implement the abstract methods.
Any ideas?
Re: QML ListModel for interaction with C++
Re: QML ListModel for interaction with C++
is your listview really empty or field with empty items ?
can you give us the delegate ?
did you try to add emit datachanged(QModelIndex(), QModelIndex()); to refresh your model (it s not supposed to be needed but...)
Re: QML ListModel for interaction with C++
I think your addElement and removeElement implementations are incorrect. Try an equivalent of:
Code:
bool QMLPtrNotificationModel::addElement(QMLPtrAbstractItem *element)
{
int position = rowCount();
lst << element;
endInsertRows();
return true;
}
2 Attachment(s)
Re: QML ListModel for interaction with C++
Before i used an implementation with:
Code:
Q_PROPERTY(QDeclarativeListProperty<TaskData> taskData READ taskData CONSTANT)
QDeclarativeListProperty<TaskData> taskData();
That worked so far ... but if i delete an item via C++ QML gets not notified because it's just a QList...
It looked like that (and now should look the same way with the model.. but i think my implementation with the model went wrong in the very beginning .. possibly ListModel is not what i need !?):
Attachment 7494
The implementation in QML before looked like that (i am afraid - i used a Repeater { } before -- don't know if there is really a difference)
Code:
Item {
//width: 900; height: 800
property variant scrollArea
property variant orientation: Qt.Vertical
ListView {
id: completeTable
Rectangle {
id: cornerWidget
width: dataHandler.getEmpWidth()
height: dataHandler.getColumnHeight()
anchors.top: parent.top
anchors.left: parent.left
gradient: Gradient {....}
border.color: "black"
border.width: 2
radius: 1
Text {...}
}
Grid {
anchors.top: cornerWidget.bottom
anchors.left: parent.left
columns: 1
Repeater {
id: empGrid
model: employees
delegate: Employee {}
}
}
Grid {
anchors.left: cornerWidget.right
columns: dataHandler.getColumnCount()
Repeater {
id: dayHeaderGrid
model: dateHeaderData
delegate: DateHeaderData {}
}
}
Grid {
anchors.left: cornerWidget.right
anchors.top: cornerWidget.bottom
columns: dataHandler.getColumnCount()
Repeater {
id: calendarGrid
model: calendarData
delegate: CalendarData { border.width: 2; opacity: 1; visible: true}
}
}
}
Repeater {
id: tasks
model: taskData
delegate: TaskData {}
}
}
In this case taskData was the list .. this worked for the view .. but not for the add/delete
(I can provide the delegate too if it's needed but it seems i have an error somewhere with the model and it's instance in the Item/ListView)
No it looks like that:
Attachment 7495
seems empty for me (if i compare them ... the list in the model is filled .. i checked that)
The QML Code now looks like that:
Code:
Item {
//width: 900; height: 800
property variant scrollArea
property variant orientation: Qt.Vertical
ListView {
id: completeTable
QMLPtrNotificationModel {
id: myListmodel
}
Rectangle {
id: cornerWidget
width: dataHandler.getEmpWidth()
height: dataHandler.getColumnHeight()
anchors.top: parent.top
anchors.left: parent.left
gradient: Gradient {....}
border.color: "black"
border.width: 2
radius: 1
Text {
.....
}
}
Grid {
anchors.top: cornerWidget.bottom
anchors.left: parent.left
columns: 1
Repeater {
id: empGrid
model: employees
delegate: Employee {}
}
}
Grid {
anchors.left: cornerWidget.right
columns: dataHandler.getColumnCount()
Repeater {
id: dayHeaderGrid
model: dateHeaderData
delegate: DateHeaderData {}
}
}
Grid {
anchors.left: cornerWidget.right
anchors.top: cornerWidget.bottom
columns: dataHandler.getColumnCount()
Repeater {
id: calendarGrid
model: calendarData
delegate: CalendarData { border.width: 2; opacity: 1; visible: true}
}
}
model: myListmodel
delegate: TaskData { }
}
//Repeater {
// id: tasks
// model: myListmodel
// delegate: TaskData { }
//}
}
As you can see, i also tried the repeater again - gave the same meaninless empty result =/
I don't really know where to start debugging and where to look for the error in the QML <-> C++ communication -> complicated as it seems ;)
@wysota: Thanks for your tip! I changed the implementation of my derived ListModel to the following:
Code:
QMLPtrAbstractItem::QMLPtrAbstractItem(QDeclarativeItem *parent)
: QDeclarativeItem(parent)
{
}
QMLPtrNotificationModel
::QMLPtrNotificationModel(QObject *parent
){
}
QMLPtrNotificationModel
::QMLPtrNotificationModel(const QList<QMLPtrAbstractItem
*>
&list,
QObject *parent
){
}
QMLPtrNotificationModel::~QMLPtrNotificationModel()
{
clear();
}
int QMLPtrNotificationModel
::rowCount(const QModelIndex &parent
) const {
if (parent.isValid())
return 0;
return lst.count();
}
{
if (index.row() < 0 || index.row() >= lst.size())
if (role == Qt::DisplayRole || role == Qt::EditRole)
return lst.at(index.row())->getName();
}
Qt
::ItemFlags QMLPtrNotificationModel
::flags(const QModelIndex &index
) const{
if (!index.isValid())
return QAbstractItemModel::flags(index
) | Qt
::ItemIsEditable | Qt
::ItemIsDragEnabled | Qt
::ItemIsDropEnabled;
}
bool QMLPtrNotificationModel
::setData(const QModelIndex &index,
const QVariant &value,
int role
) {
if (index.row() >= 0 && index.row() < lst.size()
&& (role == Qt::EditRole || role == Qt::DisplayRole)) {
if(role == Qt::EditRole)
qDebug() << "QMLPtrNotificationModel::setData(role == Qt::EditRole)";
else
qDebug() << "QMLPtrNotificationModel::setData(role == Qt::DisplayRole)";
lst.at(index.row())->setName(value.toString());
emit dataChanged(index, index);
return true;
}
return false;
}
QList<QMLPtrAbstractItem*> QMLPtrNotificationModel::getList() const
{
return lst;
}
void QMLPtrNotificationModel::setList(const QList<QMLPtrAbstractItem*> &myitems)
{
emit beginResetModel();
lst = myitems;
emit endResetModel();
emit countChanged();
}
Qt::DropActions QMLPtrNotificationModel::supportedDropActions() const
{
}
bool QMLPtrNotificationModel::clear()
{
qDebug() << "QMLPtrNotificationModel::clear() == false";
return false;
}
QList<QMLPtrAbstractItem*>* QMLPtrNotificationModel::operator()()
{
return &lst;
}
bool QMLPtrNotificationModel::addElement(QMLPtrAbstractItem *element)
{
int position = rowCount();
lst << element;
qDebug() << "Added Element - new count(): " << lst.count();
endInsertRows();
return true;
}
bool QMLPtrNotificationModel::removeElement(QMLPtrAbstractItem *element)
{
int position = lst.indexOf(element);
delete lst.at(position);
lst.removeAt(position);
endInsertRows();
return true;
}
QMLPtrAbstractItem* QMLPtrNotificationModel::at(int index)
{
return lst.at(index);
}
void QMLPtrNotificationModel::refresh()
{
QList<QMLPtrAbstractItem*> myList = getList();
setList(myList);
}
Please - forget the meaningless clear(); function for the moment - i don't think that this might be the problem -> let's talk about clear and delete if i am able to fill the fucking view again ^^
Here is the class description of the QMLPtrAbstractItem again and the definition of the QMLPtrNotificationModel (QMLPtrNotificationModel.h):
Code:
class QMLPtrAbstractItem : public QDeclarativeItem
{
public:
QMLPtrAbstractItem(QDeclarativeItem *parent = 0);
virtual ~QMLPtrAbstractItem() { }
virtual QString getName
() const = 0;
virtual void setName
(QString name
) = 0;
};
{
Q_OBJECT
.......
};
QML_DECLARE_TYPE(QMLPtrNotificationModel)
I hope you any further ideas for me - i am stuck ... =(
Thanks, greets
1 Attachment(s)
Re: QML ListModel for interaction with C++
To test your QML implementation I suggest you attach a QStandardItemModel to it and try to add and remove items in it from within C++ to see if changes are properly reflected in QtQuick view.
Re: QML ListModel for interaction with C++
Thanks for that example wysota - seems very helpful! The problem is that the classes are derived from QDeclarativeItem and i can't really change stuff to QStandardItem because it's column/row based and the things are working with normal X/Y coordinates .. seems a bit more complicated (inheritance from QStandardItem and QDeclarativeItem seems not really pretty - and not working anyways .. i did it to test stuff -> i get an empty table again like the one i already posted)
I think what i need is something like QStandardDeclarativeItem or QDeclarativeItemModel ? Which is a DeclarativeItem derived from QStandardItem or from QAbstractItem which means i have to reimplement the whole stuff!? =/
Possibly i am wrong!? .. hopefully...
Re: QML ListModel for interaction with C++
QDeclarativeItem is something you show in QtQuick. The model has nothing to do with this. It won't make any sense to keep a list of QDeclarativeItem instances in C++ and expect that to be somehow automatically trasfered to QtQuick. Your deleage needs to be a component and for that you can use your declarative item but the model is intended to hold data.
Re: QML ListModel for interaction with C++
Ahm ... yes .. sure - you are right, it seems i missed that point while writing absurd code ...
After all - with the right code - it does not seem so difficult at all ;) So however here is my solution:
Derive a model from QAbstractListModel and use specific roles for each function related to the Object/Delegate that should be displayed via QML (which is accessing these roles)
ListView QML:
Code:
import QtQuick 1.1
Item {
ListView {
...
...
}
Repeater {
id: tasks
model: myMod //the model must be "registered" via the Context:ui->declarativeView->rootContext()->setContextProperty("myMod", model);
delegate: TaskData { }
}
}
Delegate QML:
Code:
Rectangle {
Text {
id: taskName
anchors.centerIn: parent
text: name; color: "white";
}
}
C++ Class (Element)
Code:
class Element: public QDeclarativeItem
{
Q_OBJECT
public:
Element() { }
virtual ~Element() { }
virtual QString getName
() const { return _name;
} virtual void setName
(QString name
) { _name
= name;
}
private:
};
C++ Derived Model (header):
Code:
{
Q_OBJECT
public:
enum roles {
Name = Qt::UserRole + 1
};
explicit QMLPtrNotificationModel
(QObject *parent
= 0);
QMLPtrNotificationModel
(const QList<Element
*>
&list,
QObject *parent
= 0);
~QMLPtrNotificationModel();
Element* at(int index);
bool addElement(Element *element);
bool removeElement(Element *element);
bool updateElement(Element *element);
bool clear();
public Q_SLOTS:
QList<Element*> getList() const;
void setList(const QList<Element*> &list);
private Q_SLOTS:
void refresh();
private:
Q_DISABLE_COPY(QMLPtrNotificationModel)
void init();
QList<Element*> lst;
};
C++ Derived Model:
Code:
void QMLPtrNotificationModel::init(){
QHash<int, QByteArray> roles;
roles[Name] = "name";
setRoleNames(roles);
}
int QMLPtrNotificationModel
::rowCount(const QModelIndex &parent
) const {
if (parent.isValid())
return 0;
return lst.count();
}
{
if (index.row() < 0 || index.row() > lst.size())
const Element* const elem = lst[index.row()];
if (role == Name)
return elem->getName();
}
bool QMLPtrNotificationModel
::setData(const QModelIndex &index,
const QVariant &value,
int role
) {
if (index.row() >= 0 && index.row() < lst.size()) {
bool changed = false;
Element* const elem = lst.at(index.row());
if(task){
if (role == Name){
changed = true;
elem->setName(value.toString());
}
if(changed)
emit dataChanged(index, index);
return changed;
}
return false;
}
return false;
}
QList<Element*> QMLPtrNotificationModel::getList() const
{
return lst;
}
void QMLPtrNotificationModel::setList(const QList<Element*> &myitems)
{
emit beginResetModel();
lst = myitems;
emit endResetModel();
}
bool QMLPtrNotificationModel::clear()
{
lst.clear();
endRemoveRows();
return true;
}
bool QMLPtrNotificationModel::addElement(Element *element)
{
int position = rowCount();
lst << element;
endInsertRows();
return true;
}
bool QMLPtrNotificationModel::removeElement(Element *element)
{
int position = lst.indexOf(element);
lst.removeAt(position);
endRemoveRows();
return true;
}
bool QMLPtrNotificationModel::updateElement(Element *element)
{
int position = lst.indexOf(element);
if(position>-1){
lst[position] = element;
emit dataChanged(index(position), index(position));
return true;
}
return false;
}
Element* QMLPtrNotificationModel::at(int index)
{
return lst.at(index);
}
void QMLPtrNotificationModel::refresh()
{
QList<Element*> myList = getList();
setList(myList);
}
After changing the value pointed to by the model i do model.updateElement(elem);
After deletion/on deletion of the object i do model.removeElement(elem);
I hope this could be helpful for others who are struggling by implementing an own model for QML ;)
cheers
Re: QML ListModel for interaction with C++
But why is your Element class derived from QDeclarativeItem?
Re: QML ListModel for interaction with C++
Because i am using setPos() to place these items in the DeclarativeView
Re: QML ListModel for interaction with C++
They are part of your data and not items. The model makes no use of their declarative item nature. If you delete such an object behind the model's back, your application will crash the next time the model tries to use that item.
The proper approach would be to have some internal representation of your data that is shared between the model and the item you display somewhere in the scene.
Re: QML ListModel for interaction with C++
I don't know if i got your point, but that is (as i think) exactly what i do?
I changed the interface design later to:
Code:
class QMLPtrAbstractItem : public QDeclarativeItem
{
public:
virtual ~QMLPtrAbstractItem() { }
virtual bool setData
(int role,
const QVariant &value
) = 0;
virtual QVariant getData
(int role
) const = 0;
virtual int getUID() const = 0;
virtual void setUID(int uid) = 0;
};
So that i have an abstract "interface" to the model then i derive other classes of QMLPtrAbstractItem
Code:
class EmpData : public QMLPtrAbstractItem
I could have also done:
Code:
class QMLPtrAbstractItem {}
class EmpData : public QMLPtrAbstractItem, public QDeclarativeItem {}
But the Abstractlayer is my communication layer between the DeclarativeItem and the Model - or have i missed something?
I am using only Data in the model - the data i get from the Item itself (i wanted to avoid to implement 3 different model for the same type of use case...
In the Model i call "getData()" in data() to return the data associated with the provided role (different acting for different item)
The model holds a list of pointers to the Items (as usual!?) and with data() I request the data for a given role from the selected item
Isn't that the same behaviour as usual? The same is done here: http://harmattan-dev.nokia.com/docs/...model-cpp.html
This is what i do: (looks the same for me)
Code:
{
if (index.row() < 0 || index.row() > lst.size())
const QMLPtrAbstractItem * const ptrItem = lst[index.row()];
return ptrItem->getData(role);
}
bool QMLPtrNotificationModel
::setData(const QModelIndex &index,
const QVariant &value,
int role
) {
if (index.row() >= 0 && index.row() < lst.size()) {
QMLPtrAbstractItem * const ptrItem = lst.at(index.row());
if(ptrItem){
bool changed = ptrItem->setData(role, value);
if(changed)
emit dataChanged(index, index);
return changed;
}
return false;
}else
qDebug() << "QMLPtrNotificationModel::setData( " << role << ")";
return false;
}
What's wrong with that architecture? If you say -you must be right because you have more knowhow than me, but if that's "bad design" i could have missed the point - i am always interested in your opinion ;)
Re: QML ListModel for interaction with C++
You are still using QDeclarativeItem as the base class for items in your model.
No, it's not. In the quoted example Animal is not a subclass of QDeclarativeItem.
Re: QML ListModel for interaction with C++
Ok.. so you mean this would be better?:
Code:
class QMLPtrAbstractItem
{
}
{
....
private:
QList<QMLPtrAbstractItem*> lst;
};
class EmpData : public QDeclarativeItem, public QMLPtrAbstractItem
{
....
}
Re: QML ListModel for interaction with C++
What is this EmpData class? Are you adding instances of this class directly to the declarative scene? Your initial QML code suggests the only custom item you are using is "TaskData". How is "EmpData" related to "TaskData"?
Re: QML ListModel for interaction with C++
EmpData and TaskData are items that i really add to the DeclarativeView - EmpData is not really related to TaskData (That are employees - TaskData are the Tasks that are associated to the Employees which are represented via to the DeclatativeView via EmpData)
They are however threated similar to Tasks TaskData is created the same way:
Code:
class TaskData : public QDeclarativeItem, public QMLPtrAbstractItem
From TaskData there are however again two specifications: Events (sickness, Vacation) and Orders (real working tasks) Task is the "interface for both"
So OrderData and EventData are then derived from TaskData...
Code:
EventData *td = new EventData();
td->setUID(ID.toInt());
td->setName(type);
td->setBgColor1("#ffffff");
td->setBgColor2(color.name());
td->setXPos(x);
td->setYPos(y);
td->setLength(w);
td->setCreationUser(creationUser);
taskModel.addElement(td);
Code:
OrderData *td = new OrderData();
td->setUID(uID);
td->setName(text);
td->setBgColor1("#ffffff");
td->setBgColor2(ZEGlobal->getStatusColor(oid2sta[orderID]).name());
td->setXPos(ex_x);
td->setYPos(ex_y);
td->setLength(len);
td->setOrderID(orderID);
td->setLttID(lttID);
td->setGrpID(grpID);
td->setCreationUser(creationUser);
taskModel.addElement(td);
These items are later checked for collisions - but i think i got your point ... i don't need the DeclarativeItem ... cauze the items are placed via
the data from the model in QML..
Was that your point?
Re: QML ListModel for interaction with C++
Ok, I think the problem is that you are not using QtQuick correctly. It's a declarative framework, not an imperative one. Your TaskData and EmpData classes are delegates -- components that should be used to display (and otherwise interact with) data from a model. They are not supposed to be part of the model itself so you don't need to add them manually to the scene. You just need to state "ok, here is a model containing my data and here is how each item should look like".
So based on that your EmpData class can have the same base class as your model item class but that's not required in any way, you just need to teach the EmpData class to handle pieces of data from your model. Instead of inheritance you can as well use composition.
Code:
class EmpDataItem : public QDeclarativeItem {
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName
) public:
m_data.name = n;
update();
}
QString name
() const { return m_data.
name;
} private:
EmpData m_data;
};
This way you won't require any virtual methods in your data class and you can easily have the model class hold QList<Data> instead of QList<Data*> which makes things a lot easier.
Re: QML ListModel for interaction with C++
Hmm what you say sounds good so far..
"Your TaskData and EmpData classes are delegates -- components that should be used to display (and otherwise interact with) data from a model" I agree to that and got that (i think)..
Means I have Delegates that don't have any data by heart and the delegates are provided X-times according to the Listmodel which holds the data for each Delegate - this might be set via setItemData() correct? And in the delegate I can access the data via the role.
What for do i need the QDeclarativeItem anyways? If the Delegate interacts with the model that thing is not needed? By now it is working without it..
If i store the data in the model directly i have to use different model instances - correct? At the moment i am using one instance for Tasks and Events thats why i
used virtual functions and the Abstractlayer
What would you do with
Code:
private:
EmpData m_data;
};
in the case above ? how does the model interact with that Data?
Re: QML ListModel for interaction with C++
Quote:
Originally Posted by
shock
and the delegates are provided X-times according to the Listmodel which holds the data for each Delegate
The delegate is provided once per view using the "delegate" property of the view. The model itself doesn't use a delegate.
Quote:
this might be set via setItemData() correct? And in the delegate I can access the data via the role.
No, that's wrong, that's my point that you are doing it the wrong way. Your model shouldn't be composed of delegates or anything like that. The model holds data, regardless of how the data is stored. You don't need any "items" in the model, the data could be generated on the fly. The "items" are not "delegates", they have no visual representation in the model.
Quote:
What for do i need the QDeclarativeItem anyways?
The way I see it you are providing a custom delegate (TaskData or EmpData). If you implement it in C++, it will be derived from QDeclarativeItem.
Quote:
By now it is working without it..
You have QDeclarativeItem instances all over your code, just take a look.
Quote:
If i store the data in the model directly i have to use different model instances
Different model instances of what?
Quote:
how does the model interact with that Data?
The model doesn't interact with data. The model represents the data, it provides access to it.