Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
itemmarketviewmodel.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 m_market(source)
28{
29 setSourceModel(source);
30 setDynamicSortFilter(true);
31
32 // Toggling Buy/Sell does NOT rebuild the model (that would clear the cart); it
33 // only re-slices the left view, so re-filter when the flag flips.
34 connect(source, &ItemMarketModel::isBuyModeChanged,
35 this, [this]() { invalidateFilter(); });
36}
37
39 const QModelIndex& sourceParent) const
40{
41 // Exchange mode is a separate, single list -- show it wholesale.
42 if(m_market->isExchangeMode)
43 return true;
44
45 const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
46 if(!idx.isValid())
47 return false;
48
49 const int tag = sourceModel()->data(idx, ItemMarketModel::ViewTagRole).toInt();
50 const int want = m_market->isBuyMode ? ItemMarketModel::ViewBuy
52 return tag == want;
53}
The Poke-mart / Game Corner "market" model – buy and sell with a cart.
ItemMarketViewModel(ItemMarketModel *source, QObject *parent=nullptr)
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override