Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
itemmarketcartmodel.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
21
23#include "./itemmarketmodel.h"
24
26 : QSortFilterProxyModel(parent)
27{
28 setSourceModel(source);
29
30 // Re-evaluate filterAcceptsRow on every source dataChanged. The market model
31 // emits a per-row dataChanged when a cart count is set, and a model-wide
32 // dataChanged on each recompute, so a row enters/leaves the receipt the moment
33 // its cart count crosses zero -- no manual invalidate needed.
34 setDynamicSortFilter(true);
35}
36
38 const QModelIndex& sourceParent) const
39{
40 const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
41 if(!idx.isValid())
42 return false;
43
44 // Section headers ("msg" rows) never belong on a receipt.
45 if(sourceModel()->data(idx, ItemMarketModel::WhichTypeRole).toString() == "msg")
46 return false;
47
48 // Keep only rows the user actually put on the cart.
49 return sourceModel()->data(idx, ItemMarketModel::CartCountRole).toInt() > 0;
50}
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Accept a source row only when it's on the cart and isn't a section header.
ItemMarketCartModel(ItemMarketModel *source, QObject *parent=nullptr)
The Poke-mart / Game Corner "market" model – buy and sell with a cart.