Open tommego opened 5 years ago
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)?
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).
Hello, is this problem continuing solving?
First filtering operation is very slow, and then it was well for nex filtering, what caused this problem? problem above: