Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
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
22
#include "
./itemmarketviewmodel.h
"
23
#include "
./itemmarketmodel.h
"
24
25
ItemMarketViewModel::ItemMarketViewModel
(
ItemMarketModel
* source, QObject* parent)
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
38
bool
ItemMarketViewModel::filterAcceptsRow
(
int
sourceRow,
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
51
:
ItemMarketModel::ViewSell
;
52
return
tag == want;
53
}
ItemMarketModel
The Poke-mart / Game Corner "market" model – buy and sell with a cart.
Definition
itemmarketmodel.h:45
ItemMarketModel::ViewTagRole
@ ViewTagRole
Definition
itemmarketmodel.h:132
ItemMarketModel::ViewBuy
@ ViewBuy
Definition
itemmarketmodel.h:155
ItemMarketModel::ViewSell
@ ViewSell
Definition
itemmarketmodel.h:156
ItemMarketViewModel::ItemMarketViewModel
ItemMarketViewModel(ItemMarketModel *source, QObject *parent=nullptr)
Definition
itemmarketviewmodel.cpp:25
ItemMarketViewModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition
itemmarketviewmodel.cpp:38
itemmarketmodel.h
itemmarketviewmodel.h
projects
app
src
mvc
itemmarketviewmodel.cpp
Generated by
1.17.0