This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Custom DataEngine and use in QML

Tags: None
(comma "," separated)
User avatar
gdebure
Registered Member
Posts
117
Karma
1
OS

Custom DataEngine and use in QML

Sun Jan 27, 2013 11:15 pm
In QML, I am trying to use a DataModel, but I can't understand how the dataengine is supposed to provide its data for that mechanism to work...

Here is the QML code :

Code: Select all
import QtQuick 1.1
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.plasma.core 0.1 as PlasmaCore

Item {
    id: mainWidget
    property int minimumWidth: 300
    property int minimumHeight: 200
   
    // Connect to our dataengine
    PlasmaCore.DataSource {
        id: banksSource
        engine: "skgdataengine"
        interval: 0
        connectedSources: ["Accounts"]
    }
   
    // Use a modelProxy for easy filtering / sorting
    PlasmaCore.SortFilterModel {
        id: banksModel
        sourceModel: PlasmaCore.DataModel {
            dataSource: banksSource
        }
    }
   
    // A component for displaying the account with its balance in a row
    // The account name is a ToolButton that opens the account
    // tab on click
   
    // Put all accounts in a Column
    ListView {
        anchors.fill: parent
        model: banksModel

        delegate: Text {
            text: type
        }
    }
}


And here is the C++ code in my dataengine that stores the values:

Code: Select all
// Put the data in the dataengine
int nb = sqlResult.count();
for (int i = 1 ; i < nb ; ++i) {

    QVariantHash values;
    values["bank"] = sqlResult.at(i).at(1);
    values["type"] = sqlResult.at(i).at(2);
    values["amount"] = sqlResult.at(i).at(3);
    values["unit"] = sqlResult.at(i).at(4);
    values["closed"] = sqlResult.at(i).at(5);

    setData(SRC_ACCOUNTS, sqlResult.at(i).at(0), values);
 }


As you can see, each value in the dataengine is a QVariantHash. Is that how the data is supposed to be found in the dataengine ? Or should it be something else ?


Skrooge, a personal finances manager powered by KDE4
http://skrooge.org
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I would suggest asking about this on the Plasma Development mailing list (plasma-devel@kde.org) where people more experienced with QML may be able to answer your question.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient