Skip to content

Commit

Permalink
Refs #2. Updated GenericItemDelegate to use listview properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Mar 8, 2024
1 parent 33a32b4 commit 44dc1d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import QtQuick.Controls 2.15
import QtQuick.Layouts

Item {
property string fieldIdName: "id_"
property string fieldDisplayName: "disp_"
property string iconPath: "qrc:/genericIcon"

id: myDelegate

signal itemClicked(int id);
Expand All @@ -28,7 +24,7 @@ Item {
// Customize delegate appearance as needed
Text {
height: 20
text: "Name: " + model[fieldDisplayName]
text: "Name: " + model[myDelegate.ListView.view.fieldDisplayName]
color: "red"
}
/*
Expand All @@ -46,15 +42,15 @@ Item {
*/
}
Component.onCompleted: function() {
console.log("GenericItemDelegate");
//console.log("GenericItemDelegate - " + myDelegate.ListView.view.fieldDisplayName);
}


MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
itemClicked(model[fieldIdName]);
itemClicked(model[myDelegate.ListView.view.fieldIdName]);
}
}
}
Expand Down
47 changes: 7 additions & 40 deletions Frontend/DashboardsViewer/content/widgets/ListViewWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,21 @@ import QtQuick.Controls 2.15
BaseWidget {

//Set model and delegate properties externally
property alias model: myListView.model
property alias delegate: myListView.delegate
property var dataSource: Object()

property var dataSource: null

// Define a ListView to display the items
ListView {
id: myListView
anchors.fill: parent
model: myModel
delegate: myDelegate

onModelChanged: function()
{
//At this stage the model is empty
}

onCountChanged: function()
{
//Something added to the model
//Update all delegate to model items
for (var i = 0; i < myListView.count; ++i) {
var element = model.get(i); // Access the ListElement at index i
var item = myListView.itemAtIndex(i);

// Data Source will determine field names
var fieldIdName = dataSource.fieldIdName;
var fieldDisplayName = dataSource.fieldDisplayName;
var iconPath = dataSource.iconPath;


//TODO not working yet.
/*
item[fieldIdName] = element[fieldIdName];
item[fieldDisplayName] = element[fieldDisplayName];
item[iconPath] = element[iconPath];
*/
model: dataSource ? dataSource.model : null

console.log("Item at index", i, ":", item, element);
}

}
property string fieldDisplayName: dataSource.fieldDisplayName
property string fieldIdName: dataSource.fieldIdName
property string iconPath: dataSource.iconPath

}




/*
ListModel {
id: myModel
ListElement { name: "Apple" }
Expand All @@ -66,7 +33,7 @@ BaseWidget {
Text {
text: name
}
}
}*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"target": {"object": "participantListData", "slot": "update", "args": []}
},
{
"source": {"object": "participantList.delegate", "signal": "onParticipantClicked"},
"source": {"object": "participantList.delegate", "signal": "onItemClicked"},
"target": {"object": "participantSessionListData", "slot": "setParticipant", "args": ["id_participant"]}
}
]
Expand Down

0 comments on commit 44dc1d4

Please sign in to comment.