09-14-2012 12:40 AM - edited 09-14-2012 12:41 AM
Hi,
I have a tabbed pane with two tabs. I want to populate each tab with a dfifferent JSON (list (not XML). I've managed to populate the first tab with the first json file...by following the stampcollector sample app. All the UI is in QML but the JSON loading and setting groupdatamodel is done in C++.
1. Now I want to populate the 2nd tab's page with a different JSON list. How do I go about this? Create a new class or can I change the source of the JSON when the 2nd tab is triggered?
2. Just like in the stampcollecctor app, I'm using sorting keys. I have some action items in QML, which when pressed, I want the sorting of the lists to change. So let's say the first action sorts them A-Z, the second action Z-A, the third action by population, the 4th action by area. How can access and change the sorting key?
3. Is there anyway to sort alphabetically in reverse order....from Z-A?
Code that I have so far is below...just no idea where to start....
main.qml
import bb.cascades 1.0
TabbedPane {
id: mainTabPage
showTabsOnActionBar: true
// Country Tab
Tab {
title: "Countries"
NavigationPane {
id: countryTabNav
property variant _countryView;
Page {
Container {
ListView {
id: countryList
objectName: "countryList"
listItemComponents: [
ListItemComponent {
type: "listItem"
StandardListItem {
title: ListItemData.country
status: ListItemData.population
description: ListItemData.capital
}
}
]
onTriggered: {
var chosenItem = dataModel.data(indexPath);
_countryView = chosenItem;
countryTabNav.deprecatedPushQmlByString("countryDe tail.qml");
}
}
//-- define tab content here
layout: StackLayout {
}
}
}
}
}
}
app.cpp
#include "app.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Container>
#include <bb/cascades/GroupDataModel>
#include <bb/cascades/ListView>
#include <bb/cascades/NavigationPane>
#include <bb/cascades/QmlDocument>
#include <bb/data/JsonDataAccess>
using namespace bb::cascades;
using namespace bb::data;
App::App() {
QmlDocument *qml = QmlDocument::create("main.qml");
//-- setContextProperty expose C++ object in QML as an variable
//-- uncomment next line to introduce 'this' object to QML name space as an 'app' variable
//qml->setContextProperty("app", this);
AbstractPane *root = qml->createRootNode<AbstractPane>();
// ListView Model
ListView *countryList = root->findChild<ListView*>("countryList");
setupCountryListModel(countryList);
Application::setScene(root);
}
void App::setupCountryListModel(ListView *countryList) {
JsonDataAccess jda;
QVariantList mainList = jda.load("app/native/assets/countries.json").value <QVariantList>();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qDebug() << "JSON loading error: " << error.errorType() << ": "
<< error.errorMessage();
return;
}
GroupDataModel *countryModel = new GroupDataModel(QStringList() << "country");
countryModel->setParent(this);
countryModel->insertList(mainList);
countryModel->setGrouping(ItemGrouping::ByFullValu e);
countryList->setDataModel(countryModel);
}
app.hpp
#ifndef APP_H
#define APP_H
#include <QObject>
#include <bb/cascades/Application>
using namespace bb::cascades;
namespace bb
{
namespace cascades
{
class ListView;
}
}
/*!
* @brief Application GUI object
*/
class App : public QObject
{
Q_OBJECT
public:
App();
private:
void setupCountryListModel(ListView *countryList);
};
#endif // ifndef APP_H
Solved! Go to Solution.
09-18-2012 10:21 PM
1. You'll have to duplicate what you did for the other tab. Check out weatherguesser which has a bunch of tabs and datamodels.
2. Checkout the groupdata model page
https://developer.blackberry.com/cascades/referenc
try:
countryModel->setSortingKeys())
3.
countryModel->setsortedascending(false)
09-20-2012 10:23 AM
Did Dredvard's suggestions work for you?
Graham
10-12-2012 11:16 PM
Sorry for the late reply. Family matters.
Back to programming now.
Dredvard's reply did help. Thanks. I'll mark it as solved.