=== removed file 'modules/Ubuntu/Components/ModelSectionCounter.qml'
--- modules/Ubuntu/Components/ModelSectionCounter.qml 2013-06-24 11:56:31 +0000
+++ modules/Ubuntu/Components/ModelSectionCounter.qml 1970-01-01 00:00:00 +0000
@@ -1,179 +0,0 @@
-/*
- * Copyright 2012 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-import QtQuick 2.0
-
-/*!
- \qmltype ModelSectionCounter
- \internal
- \inqmlmodule Ubuntu.Components 0.1
- \ingroup ubuntu
- \brief Section counter for ListView models.
-*/
-
-Object {
- id: counter
-
- /*!
- \preliminary
- The property holds the ListView instance whose model sections are to be counted.
- */
- property var view: null
-
- /*!
- \preliminary
- The property contains the section counts of the given view.
- */
- property int count: 0
-
- /*!
- \preliminary
- \qmlproperty real sectionHeight
- The property contains the section Item height.
- */
- readonly property alias sectionHeight: internals.sectionHeight
-
- /*!
- \preliminary
- When set (true), the sections will be cached for further use. This is used on
- section scrollers (e.g. alphabet scrollbar). The default value is false, meaning
- no caching is done, just counting.
- */
- property bool cacheSections: false
-
- /*!
- \preliminary
- This property holds the cached sections when the cacheSections property is set, and
- is an empty list when no caching is requested.
- */
- property var cache: []
-
- /*!
- \internal
- */
- onCacheSectionsChanged: internals.checkSections()
-
- QtObject {
- id: internals
-
- property real sectionHeight: (count > 0 && view.section.delegate) ?
- QuickUtils.modelDelegateHeight(view.section.delegate, view.model) : 0.0
-
- property var myView: null
- function disconnectPreviousView()
- {
- if (!myView)
- return;
- if (myView.model.countChanged)
- myView.model.countChanged.disconnect(checkSections);
-
- if (myView.model.itemsChanged)
- myView.model.itemsChanged.disconnect(checkSections);
-
- if (myView.model.itemsInserted)
- myView.model.itemsInserted.disconnect(checkSections);
-
- if (myView.model.itemsMoved)
- myView.model.itemsMoved.disconnect(checkSections);
-
- if (myView.model.itemsRemoved)
- myView.model.itemsRemoved.disconnect(checkSections);
-
- if (myView.section.delegateChanged)
- myView.section.delegateChanged.disconnect(checkSections);
- }
-
- function initSectionCounter()
- {
- myView = view;
- if (myView.model.countChanged)
- myView.model.countChanged.connect(checkSections);
-
- if (myView.model.itemsChanged)
- myView.model.itemsChanged.connect(checkSections);
-
- if (myView.model.itemsInserted)
- myView.model.itemsInserted.connect(checkSections);
-
- if (myView.model.itemsMoved)
- myView.model.itemsMoved.connect(checkSections);
-
- if (myView.model.itemsRemoved)
- myView.model.itemsRemoved.connect(checkSections);
-
- if (myView.section.delegateChanged)
- myView.section.delegateChanged.connect(checkSections);
-
- // finally check sections
- checkSections();
- }
-
- function checkSections()
- {
- var sections = 0, sectionStack = [];
- if (view && view.section && undefined !== view.section.property && "" !== view.section.property) {
- function sectionString(str)
- {
- if (str === undefined)
- return "";
- return (view.section.criteria === ViewSection.FirstCharacter) ? str.charAt(1) : str;
- }
-
- var current = "",
- prop = view.section.property,
- item = null, section = "",
- count = (typeof view.model.length === 'undefined' ? view.model.count : view.model.length);
- for (var i = 0; i < count; i++) {
- if (view.model.hasOwnProperty("get")) {
- item = view.model.get(i);
- section = sectionString(JSON.stringify(item[prop])).toLowerCase();
- } else {
- item = view.model[i];
- if (item.hasOwnProperty(prop))
- section = sectionString(JSON.stringify(item[prop])).toLowerCase();
- else
- section = sectionString(JSON.stringify(item)).toLowerCase();
- }
- if (section !== current) {
- current = section;
- sections++;
- if (cacheSections)
- sectionStack.push(current);
- }
- }
- }
- counter.count = sections;
- counter.cache = sectionStack;
- }
- }
-
- Component.onCompleted: cacheSectionsChanged.connect(internals.checkSections);
-
- onViewChanged: {
- internals.disconnectPreviousView()
- if (view && view.hasOwnProperty("model")) {
- if (view && view.model) {
- internals.initSectionCounter();
- } else if (view) {
- view.modelChanged.connect(function()
- {
- if (view && view.model)
- internals.initSectionCounter();
- });
- }
- }
- }
-}
=== modified file 'modules/Ubuntu/Components/plugin/quickutils.cpp'
--- modules/Ubuntu/Components/plugin/quickutils.cpp 2013-11-19 08:57:05 +0000
+++ modules/Ubuntu/Components/plugin/quickutils.cpp 2014-01-09 11:27:39 +0000
@@ -125,84 +125,6 @@
return QString(getenv("QT_IM_MODULE"));
}
-
-/*!
- * \internal
- * Creates an instance out of a delegate using the roles specified in the
- * modelData. Accepts QAbstractListModel, QAbstractProxyModel, QStringList
- * and QVariantList models.
- */
-
-
-qreal QuickUtils::modelDelegateHeight(QQmlComponent *delegate, const QVariant &modelData)
-{
- qreal result = 0.0;
- if (!delegate)
- return result;
-
- QQmlContext *creationContext = delegate->creationContext();
- QQmlContext *context = 0;
- QAbstractListModel *model = qvariant_cast(modelData);
- QAbstractProxyModel *proxy = qvariant_cast(modelData);
-
- if (proxy)
- model = qobject_cast(proxy->sourceModel());
-
- if (model) {
- // QAbstractListModel derived models
-
- if (model->rowCount() > 0) {
- context = new QQmlContext(creationContext);
- const QHash roles = model->roleNames();
- if (roles.count()) {
-
- // put roles inside the context
- QHashIterator i(roles);
- while (i.hasNext()) {
- i.next();
- context->setContextProperty(i.value(), QString());
- }
- }
- }
- } else if (modelData.type() == QVariant::List){
- QVariantList vModel = qvariant_cast(modelData);
- if (vModel.count() > 0) {
- context = new QQmlContext(creationContext);
- if (vModel[0].type() == QVariant::String) {
- // the only role name we have is modelData
- context->setContextProperty("modelData", QString());
-
- } else if (vModel[0].type() == QVariant::Map) {
- // we need only the keys, attached to an object named "modelData"
- context = new QQmlContext(creationContext);
- QQmlPropertyMap *modelData = new QQmlPropertyMap(context);
- QVariantMap map = qvariant_cast(vModel[0]);
- QStringList roles = map.uniqueKeys();
-
- Q_FOREACH(const QString &role, roles)
- modelData->insert(role, QString());
-
- context->setContextProperty("modelData", modelData);
- }
- }
- } else if (modelData.type() == QVariant::Int) {
- context = new QQmlContext(creationContext);
- // the only role name we have is modelData
- context->setContextProperty("modelData", 0);
- }
- if (context) {
- // add index and section too
- context->setContextProperty("index", 0);
- context->setContextProperty("section", QString());
- // create item from component
- QObject * obj = delegate->create(context);
- QQuickItem *item = qobject_cast(obj);
- result = item->height();
- item->deleteLater();
- }
- return result;
-}
-
/*!
* \internal
* Returns the class name (type) of a QtQuick item.
=== modified file 'modules/Ubuntu/Components/plugin/quickutils.h'
--- modules/Ubuntu/Components/plugin/quickutils.h 2013-09-24 09:59:29 +0000
+++ modules/Ubuntu/Components/plugin/quickutils.h 2014-01-09 11:27:39 +0000
@@ -42,7 +42,6 @@
Q_INVOKABLE QQuickItem *rootItem(QObject *object);
QString inputMethodProvider() const;
- Q_INVOKABLE qreal modelDelegateHeight(QQmlComponent *delegate, const QVariant &model);
Q_INVOKABLE QString className(QObject *item);
QObject* createQmlObject(const QUrl &url);
void setImportPathList(const QStringList &paths);
=== modified file 'modules/Ubuntu/Components/qmldir'
--- modules/Ubuntu/Components/qmldir 2013-11-29 12:01:47 +0000
+++ modules/Ubuntu/Components/qmldir 2014-01-09 11:27:39 +0000
@@ -22,7 +22,6 @@
CheckBox 0.1 CheckBox.qml
Slider 0.1 Slider.qml
Scrollbar 0.1 Scrollbar.qml
-internal ModelSectionCounter ModelSectionCounter.qml
Object 0.1 Object.qml
OptionSelector 0.1 OptionSelector.qml
OptionSelectorDelegate 0.1 OptionSelectorDelegate.qml
=== removed file 'tests/unit/tst_components/tst_modelsectioncounter.qml'
--- tests/unit/tst_components/tst_modelsectioncounter.qml 2013-01-22 07:19:06 +0000
+++ tests/unit/tst_components/tst_modelsectioncounter.qml 1970-01-01 00:00:00 +0000
@@ -1,109 +0,0 @@
-/*
- * Copyright 2012 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-import QtQuick 2.0
-import QtTest 1.0
-import Ubuntu.Components 0.1
-
-TestCase {
- name: "ModelSectionCounterAPI"
-
- function initTestCase() {
- var component = Qt.createComponent(Qt.resolvedUrl("../../../modules/Ubuntu/Components/ModelSectionCounter.qml"));
- counter = component.createObject(parent);
- }
-
- function test_0_defaults() {
- compare(counter.view, null, "ModelSectionCounter does not have valid view set");
- compare(counter.count, 0, "ModelSectionCounter default sectionCount is 0");
- compare(counter.cacheSections, false, "ModelSectionCounter does not cache sections");
- compare(counter.cache, [], "ModelSectionCounter has empty section cache list");
- }
-
- function test_1_count_data() {
- return [
- {tag: "Empty model", model: emptyModel, sectionProperty: "label", expect: 0, expectFail: false},
- {tag: "ListModel", model: objectModel, sectionProperty: "label", expect: 8, expectFail: false},
- {tag: "StringList model", model: stringModel, sectionProperty: "modelData", expect: 8, expectFail: false},
- {tag: "VariantList model", model: variantModel, sectionProperty: "label", expect: 8, expectFail: false},
- ];
- }
-
- function test_1_count(data) {
- if (data.expectFail)
- expectFail("", data.tag);
- list.model = data.model;
- list.section.property = data.sectionProperty;
- list.section.criteria = ViewSection.FirstCharacter;
- counter.view = list;
- compare(counter.count, data.expect, "Section count is wrong");
- }
-
- function test_2_cache() {
- list.model = objectModel;
- list.section.property = "label";
- list.section.criteria = ViewSection.FirstCharacter;
- counter.view = list;
- counter.cacheSections = true;
- var cache = ["1", "2", "3", "4", "5", "6", "7", "8"];
- compare(counter.cache, cache, "Section cache is wrong");
-
- counter.cacheSections = false;
- cache = [];
- compare(counter.cache, cache, "Section cache is wrong");
- }
-
- Item {
- ListView {
- id: list
-
- delegate: Item{ height: 40 }
- section.delegate: Item{ height: 10 }
- }
- }
-
- property var counter
-
- property var emptyModel: ListModel {}
-
- property var objectModel: ListModel {
- ListElement {label: "1"}
- ListElement {label: "10"}
- ListElement {label: "100"}
- ListElement {label: "2"}
- ListElement {label: "3"}
- ListElement {label: "4"}
- ListElement {label: "5"}
- ListElement {label: "6"}
- ListElement {label: "7"}
- ListElement {label: "8"}
- }
-
- property var variantModel: [
- {"label": "1"},
- {"label": "10"},
- {"label": "100"},
- {"label": "2"},
- {"label": "3"},
- {"label": "4"},
- {"label": "5"},
- {"label": "6"},
- {"label": "7"},
- {"label": "8"}
- ]
-
- property var stringModel: ["1", "10", "100", "2", "3", "4", "5", "6", "7", "8"]
-}
=== modified file 'tests/unit/tst_components/tst_quickutils.qml'
--- tests/unit/tst_components/tst_quickutils.qml 2013-05-24 10:07:44 +0000
+++ tests/unit/tst_components/tst_quickutils.qml 2014-01-09 11:27:39 +0000
@@ -39,115 +39,5 @@
compare(QuickUtils.className(test), "TestCase", "className for TestCase");
compare(QuickUtils.className(root), "QQuickItem", "className for Item");
}
-
- function test_modelDelegateHeightForEmptyObjectModelElements()
- {
- list.model = emptyModel;
- list.section.property = "";
-
- var itemHeight = QuickUtils.modelDelegateHeight(list.delegate, list.model);
- compare(itemHeight, 0, "itemHeight failure");
-
-
- for (var i = 0; i < 10; i++) {
- emptyModel.append({});
- var itemHeight = QuickUtils.modelDelegateHeight(list.delegate, list.model);
- compare(itemHeight, 50, "itemHeight failure");
- }
- }
-
- function test_modelDelegateHeightForObjectModel()
- {
- list.model = objectList;
- list.section.property = "label";
-
- var sectionHeight = QuickUtils.modelDelegateHeight(list.section.delegate, list.model);
- compare(sectionHeight, 25, "sectionHeight failure");
-
- var itemHeight = QuickUtils.modelDelegateHeight(list.delegate, list.model);
- compare(itemHeight, 50, "itemHeight failure");
- }
-
- function test_modelDelegateHeightForVariantListModel()
- {
- list.model = variantList;
- list.section.property = "label";
-
- var sectionHeight = QuickUtils.modelDelegateHeight(list.section.delegate, list.model);
- compare(sectionHeight, 25, "sectionHeight failure");
-
- var itemHeight = QuickUtils.modelDelegateHeight(list.delegate, list.model);
- compare(itemHeight, 50, "itemHeight failure");
- }
-
- function test_modelDelegateHeightForStringListModel()
- {
- list.model = stringList;
- list.section.property = "modelData";
-
- var sectionHeight = QuickUtils.modelDelegateHeight(list.section.delegate, list.model);
- compare(sectionHeight, 25, "sectionHeight failure");
-
- var itemHeight = QuickUtils.modelDelegateHeight(list.delegate, list.model);
- compare(itemHeight, 50, "itemHeight failure");
- }
-
- function test_modelDelegateHeightForNumericModel()
- {
- list.model = 100;
- list.section.property = "modelData";
-
- var sectionHeight = QuickUtils.modelDelegateHeight(list.section.delegate, list.model);
- compare(sectionHeight, 25, "sectionHeight failure");
-
- var itemHeight = QuickUtils.modelDelegateHeight(list.delegate, list.model);
- compare(itemHeight, 50, "itemHeight failure");
- }
-
- property var emptyModel: ListModel {}
-
- property var objectList: ListModel {
- ListElement {label: "1"}
- ListElement {label: "10"}
- ListElement {label: "100"}
- ListElement {label: "2"}
- ListElement {label: "3"}
- ListElement {label: "4"}
- ListElement {label: "5"}
- ListElement {label: "6"}
- ListElement {label: "7"}
- ListElement {label: "8"}
- }
-
- property var variantList: [
- {"label": "1"},
- {"label": "10"},
- {"label": "100"},
- {"label": "2"},
- {"label": "3"},
- {"label": "4"},
- {"label": "5"},
- {"label": "6"},
- {"label": "7"},
- {"label": "8"}
- ]
-
- property var stringList: ["1", "10", "100", "2", "3", "4", "5", "6", "7", "8", "9"]
-
- ListView {
- id: list
-
- section.criteria: ViewSection.FirstCharacter
- section.delegate: Header{
- text: section
- height: 25
- }
-
- delegate: Standard {
- text: label
- height: 50
- }
- }
-
}
}