Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filering on slow responsing time problem #64

Open
tommego opened this issue May 28, 2019 · 3 comments
Open

filering on slow responsing time problem #64

tommego opened this issue May 28, 2019 · 3 comments

Comments

@tommego
Copy link

tommego commented May 28, 2019

First filtering operation is very slow, and then it was well for nex filtering, what caused this problem?
image
problem above:

  1. I select A (matched 12 items) and then select E (matched thousands of items) on the language filtering options.it takes 2 seconds on 100k items model.
  2. I select E (matched thousands of items) first, it takes hours of filtering, on a 100k items model. and after finished this filtering job, other options of filtering come faster with 2 seconds.
    Amazing but why?
@oKcerG
Copy link
Owner

oKcerG commented May 28, 2019

Hello,
Can you list the roles of your source model and share the QML source code of your SortFilterProxyModel (so I can see how your filters/sorters/proxy roles are set up)?

@tommego
Copy link
Author

tommego commented May 31, 2019

UIPage.qml

import QtQuick 2.0
import SongDataParser 1.0
import SortFilterProxyModel 0.2
import QtQuick.Controls 2.5
import "./Delegates"

Item {
    property var laguages:["All", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N"]
    property var abc: ["All", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
    property int currentLanguageIndex: 0
    property int currentAbcIndex: 0
    property int pageSize: 20
    property int pageCount: sortFilterModel.count % pageSize === 0 ? sortFilterModel.count / pageSize : Math.round(sortFilterModel.count / pageSize) + 1

    SongDataParser{
        id: songDataParser
        onDataLoaded: {
            for(var i in songDatas())
            {
                var elementData = songDatas()[i];
                songModel.append(elementData)
            }
        }
    }

    ListModel{
        id: songModel
    }

    SortFilterProxyModel{
        id: sortFilterModel
        sourceModel: songModel
        filters:[
            ValueFilter{
                roleName: "Language"
                value: laguages[currentLanguageIndex]
                enabled: currentLanguageIndex !== 0
            },
            RegExpFilter {
                roleName: "PYStr1"
                pattern: "^" + abc[currentAbcIndex] // 正则表达式匹配字符串
                caseSensitivity: Qt.CaseInsensitive
                enabled: currentAbcIndex !== 0
            }

        ]

        sorters: [
            StringSorter{
                id: aa
            }

        ]
        Component.onCompleted: {
//            sortFilterModel.
        }
    }

    Column{
        anchors.fill: parent
        spacing: 20

        Item{
            width: parent.width
            height: 40
            Row{
                anchors.verticalCenter: parent.verticalCenter
                spacing: 10
                x: 20
                Text{
                    anchors.verticalCenter: parent.verticalCenter
                    text: "Language: "
                }

                Repeater{
                    model: laguages
                    Rectangle{
                        width: 40
                        height: 30
                        radius: 3
                        color: currentLanguageIndex == index ? "#3af" : "#aaa"
                        Text{
                            anchors.centerIn: parent
                            text: modelData
                            color: "white"
                        }
                        MouseArea{
                            anchors.fill: parent
                            onClicked: {
                                currentLanguageIndex = index
                            }
                        }
                    }
                }
            }
        }

        Item{
            width: parent.width
            height: 40
            Row{
                anchors.verticalCenter: parent.verticalCenter
                spacing: 10
                x: 20
                Text{
                    anchors.verticalCenter: parent.verticalCenter
                    text: "abc: "
                }

                Repeater{
                    model: abc
                    Rectangle{
                        width: 40
                        height: 30
                        radius: 3
                        color: currentAbcIndex == index ? "#3af" : "#aaa"
                        Text{
                            anchors.centerIn: parent
                            text: modelData
                            color: "white"
                        }
                        MouseArea{
                            anchors.fill: parent
                            onClicked: {
                                currentAbcIndex = index
                            }
                        }
                    }
                }
            }
        }

        Item{
            width: parent.width
            height: 500
            Column{
                anchors.fill: parent
                ListView{
                    id:listView
                    orientation: ListView.Horizontal
                    width: parent.width
                    height: parent.height - 60
                    model: pageCount
                    highlightRangeMode : ListView.StrictlyEnforceRange
                    highlightMoveDuration: 200
                    highlightMoveVelocity: -1
                    snapMode: ListView.SnapOneItem
                    delegate: PageDelegate{
                        pageNo: index
                        source: sortFilterModel
                        sizeInPage: pageSize
                        width: listView.width
                        height: listView.height
                    }
                }

                Item{
                    width: parent.width
                    height: 60
                    Row{
                        anchors.centerIn: parent
                        spacing: 20

                        Button{
                            text: "Previous"
                            width: 70
                            height: 40
                            onClicked: {
                                if(listView.currentIndex > 0)
                                    listView.currentIndex -= 1
                            }
                        }

                        Text{
                            text: String(listView.currentIndex + 1) + "/" + String(pageCount)
                            anchors.verticalCenter: parent.verticalCenter
                        }

                        Button{
                            text: "Next"
                            width: 70
                            height: 40
                            onClicked: {
                                if(listView.currentIndex < pageCount - 1)
                                    listView.currentIndex += 1
                            }
                        }
                    }
                }
            }
        }
    }

    Component.onCompleted: {
        songDataParser.loadData("E:/MiniK/Bin/KVData/swsong.db", 1000);
    }
}

PageDelegate.qml

import QtQuick 2.0
import PageModel 1.0

Rectangle{
    property int pageNo;
    property QtObject source;
    property int sizeInPage;
    id: page
    Grid{
        anchors.centerIn: parent
        spacing: 10
        columns: 5
        Repeater{
            model: PageModel{
                sourceModel: source
                pageIndex: pageNo
                pageSize: sizeInPage
            }
            delegate: SongDelegate{}
        }
    }
}

SongDelegate.qml

import QtQuick 2.0

Rectangle{
    width: 200
    height: 100
    border.width: 1
    border.color: "#7799aa"
    color: "#aaeeff"
    radius: 4
    Column{
        anchors.centerIn: parent
        spacing: 10
        Text{
            text: Name
        }
        Text{
            text: PYStr1
        }
        Text{
            text: Language
        }
    }
}

And the PageModel c++ implementation can read my articl open link(containing whole source code).

@tommego
Copy link
Author

tommego commented Jun 3, 2019

Hello, is this problem continuing solving?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants