Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
ItemMarketModel Class Reference

The Poke-mart / Game Corner "market" model – buy and sell with a cart. More...

#include <itemmarketmodel.h>

Inheritance diagram for ItemMarketModel:
Collaboration diagram for ItemMarketModel:

Public Types

enum  ItemRoles {
  NameRole = Qt::UserRole + 1 , InStockCountRole , CanSellRole , ItemWorthRole ,
  WhichTypeRole , StackCountRole , OnCartLeftRole , CartCountRole ,
  CartWorthRole , TotalStackCountRole , TotalWorthRole , CanCheckoutRole ,
  ValidItemRole , ExcludeItemRole , MoneyLeftRole , BuyModeRole ,
  MoneyCurrencyRole , ViewTagRole , CartSignRole , MoneyDirRole ,
  InfoRole
}
 Columns (mapped in roleNames()); comments describe each. More...
enum  { SelBuyMoney = 0 , SelBuyCoins , SelSellMoney , SelSellCoins }
 The four combined modes (returned by whichMode()). More...
enum  { ViewBuy = 0 , ViewSell = 1 }
 Left-list view tags for the unified buy+sell list (see viewTag). More...

Public Member Functions

 ItemMarketModel (ItemStorageBox *itemBag, ItemStorageBox *itemStorage, PlayerBasics *basics, Router *router, PlayerPokemon *playerPokemon, Storage *storage, SaveFile *file)
virtual int rowCount (const QModelIndex &parent) const override
 Row count.
virtual QVariant data (const QModelIndex &index, int role) const override
 Row+role value.
virtual QHash< int, QByteArray > roleNames () const override
 Role -> QML name.
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 Edit a row (cart count).
int totalCartWorth ()
int totalCartCount ()
int whichMode ()
int moneyStart ()
int moneyLeftover ()
bool anyNotEnoughSpace ()
bool canAnyCheckout ()
int exchangeMoneyStart ()
int exchangeMoneyAfter ()
int exchangeCoinsStart ()
int exchangeCoinsAfter ()
int exchangeBuyRate ()
int exchangeSellRate ()
int exchangeNet ()
 +N buying N coins / -N selling N coins.
void exchangeAdjust (int deltaCoins)
 Nudge the net (+Coins = +1, +Money = -1).
void onReUpdateValues ()
 Recompute the derived totals.
bool vendorListItem (ItemDBEntry *el)
 Should el appear in the store list (has a price here)?
bool buyableInGame (ItemDBEntry *el) const
 Is el sold by a reachable Gen-1 vendor (Normal vs Special)?
bool isVendingItem (ItemDBEntry *el) const
 Is el a Celadon vending-machine drink (its own group)?
void clearList ()
 Empty the row cache.
void buildList ()
 Build the rows for the current mode.
void buildPlayerItemList ()
 Build rows from the player's items.
void buildMartItemList ()
 Build rows from the store stock.
void buildExchangeList ()
 Build the money<->coins exchange rows (both directions).
void pageOpening (QString path)
 Hook when the market page opens.
void checkout ()
 Apply the cart transaction to the save.
void reUpdateAll ()
 Rebuild + recompute everything.

Public Attributes

QVector< ItemMarketEntry * > itemListCache
 The current market rows.
bool isBuyMode = true
bool isMoneyCurrency = true
bool isExchangeMode = false
ItemStorageBoxitemBag = nullptr
 The player's bag.
ItemStorageBoxitemStorage = nullptr
 The PC item box.
Routerrouter = nullptr
 For page hooks.
PlayerBasicsbasics = nullptr
 Player money/coins.
PlayerPokemonplayerPokemon = nullptr
 Party (for received Pokemon).
Storagestorage = nullptr
 PC storage (for received Pokemon).
SaveFilefile = nullptr
 The live save.

Detailed Description

The Poke-mart / Game Corner "market" model – buy and sell with a cart.

The most complex model in the app. It presents a unified buy/sell market with a cart, switching between four modes (buy/sell x money/coins) and between viewing the player's items and the store's stock. Rows are ItemMarketEntry objects (a small class hierarchy – player item, store item, money, message, Game Corner Pokemon). It computes cart totals, leftover money, and space checks, and applies the transaction in checkout(). Exposed as brg.marketModel.

See also
ItemMarketEntry (the row base + its subtypes), Storage, PlayerBasics.

Definition at line 44 of file itemmarketmodel.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The four combined modes (returned by whichMode()).

Enumerator
SelBuyMoney 
SelBuyCoins 
SelSellMoney 
SelSellCoins 

Definition at line 146 of file itemmarketmodel.h.

◆ anonymous enum

anonymous enum

Left-list view tags for the unified buy+sell list (see viewTag).

Enumerator
ViewBuy 
ViewSell 

Definition at line 154 of file itemmarketmodel.h.

◆ ItemRoles

Columns (mapped in roleNames()); comments describe each.

Enumerator
NameRole 
InStockCountRole 
CanSellRole 
ItemWorthRole 
WhichTypeRole 
StackCountRole 
OnCartLeftRole 
CartCountRole 
CartWorthRole 
TotalStackCountRole 
TotalWorthRole 
CanCheckoutRole 
ValidItemRole 
ExcludeItemRole 
MoneyLeftRole 
BuyModeRole 
MoneyCurrencyRole 
ViewTagRole 
CartSignRole 
MoneyDirRole 
InfoRole 

Definition at line 77 of file itemmarketmodel.h.

Constructor & Destructor Documentation

◆ ItemMarketModel()

Member Function Documentation

◆ anyNotEnoughSpace()

bool ItemMarketModel::anyNotEnoughSpace ( )
See also
anyNotEnoughSpace property.

Definition at line 282 of file itemmarketmodel.cpp.

References itemListCache.

◆ buildExchangeList()

void ItemMarketModel::buildExchangeList ( )

Build the money<->coins exchange rows (both directions).

Definition at line 542 of file itemmarketmodel.cpp.

References ItemMarketEntryMoney::DirToCoins, ItemMarketEntryMoney::DirToMoney, and itemListCache.

Referenced by buildList().

◆ buildList()

void ItemMarketModel::buildList ( )

◆ buildMartItemList()

void ItemMarketModel::buildMartItemList ( )

◆ buildPlayerItemList()

void ItemMarketModel::buildPlayerItemList ( )

Build rows from the player's items.

Definition at line 551 of file itemmarketmodel.cpp.

References itemBag, itemListCache, itemStorage, and ViewSell.

Referenced by buildList().

◆ buyableInGame()

bool ItemMarketModel::buyableInGame ( ItemDBEntry * el) const

Is el sold by a reachable Gen-1 vendor (Normal vs Special)?

Definition at line 428 of file itemmarketmodel.cpp.

References ItemDBEntry::getInd().

Referenced by buildMartItemList().

◆ canAnyCheckout()

bool ItemMarketModel::canAnyCheckout ( )
See also
canAnyCheckout property.

Definition at line 300 of file itemmarketmodel.cpp.

References itemListCache.

◆ checkout()

void ItemMarketModel::checkout ( )

Apply the cart transaction to the save.

Definition at line 494 of file itemmarketmodel.cpp.

References itemListCache, and reUpdateAll().

◆ clearList()

void ItemMarketModel::clearList ( )

Empty the row cache.

Definition at line 508 of file itemmarketmodel.cpp.

References itemListCache.

Referenced by buildList().

◆ data()

◆ exchangeAdjust()

void ItemMarketModel::exchangeAdjust ( int deltaCoins)

Nudge the net (+Coins = +1, +Money = -1).

Definition at line 371 of file itemmarketmodel.cpp.

References itemListCache, ItemMarketEntry::onCart, and ItemMarketEntryMoney::onCartLeft().

◆ exchangeBuyRate()

int ItemMarketModel::exchangeBuyRate ( )
See also
exchangeBuyRate property.

Definition at line 347 of file itemmarketmodel.cpp.

References GameCornerDB::getBuyPrice(), and GameCornerDB::inst().

◆ exchangeCoinsAfter()

int ItemMarketModel::exchangeCoinsAfter ( )
See also
exchangeCoinsAfter property.

Definition at line 334 of file itemmarketmodel.cpp.

References basics, and itemListCache.

◆ exchangeCoinsStart()

int ItemMarketModel::exchangeCoinsStart ( )
See also
exchangeCoinsStart property.

Definition at line 313 of file itemmarketmodel.cpp.

References basics.

◆ exchangeMoneyAfter()

int ItemMarketModel::exchangeMoneyAfter ( )
See also
exchangeMoneyAfter property.

Definition at line 321 of file itemmarketmodel.cpp.

References basics, and itemListCache.

◆ exchangeMoneyStart()

int ItemMarketModel::exchangeMoneyStart ( )
See also
exchangeMoneyStart property.

Definition at line 308 of file itemmarketmodel.cpp.

References basics.

◆ exchangeNet()

int ItemMarketModel::exchangeNet ( )

+N buying N coins / -N selling N coins.

Definition at line 359 of file itemmarketmodel.cpp.

References itemListCache.

◆ exchangeSellRate()

int ItemMarketModel::exchangeSellRate ( )
See also
exchangeSellRate property.

Definition at line 352 of file itemmarketmodel.cpp.

References GameCornerDB::getSellPrice(), and GameCornerDB::inst().

◆ isVendingItem()

bool ItemMarketModel::isVendingItem ( ItemDBEntry * el) const

Is el a Celadon vending-machine drink (its own group)?

Definition at line 488 of file itemmarketmodel.cpp.

References ItemDBEntry::getInd().

Referenced by buildMartItemList().

◆ moneyLeftover()

int ItemMarketModel::moneyLeftover ( )
See also
moneyLeftover property.

Definition at line 273 of file itemmarketmodel.cpp.

References itemListCache, and moneyStart().

◆ moneyStart()

int ItemMarketModel::moneyStart ( )
See also
moneyStart property.

Definition at line 265 of file itemmarketmodel.cpp.

References basics, and isMoneyCurrency.

Referenced by moneyLeftover().

◆ onReUpdateValues()

void ItemMarketModel::onReUpdateValues ( )

Recompute the derived totals.

Definition at line 403 of file itemmarketmodel.cpp.

References itemListCache.

Referenced by ItemMarketModel().

◆ pageOpening()

void ItemMarketModel::pageOpening ( QString path)

Hook when the market page opens.

Definition at line 693 of file itemmarketmodel.cpp.

References buildList().

Referenced by ItemMarketModel().

◆ reUpdateAll()

void ItemMarketModel::reUpdateAll ( )

Rebuild + recompute everything.

Definition at line 686 of file itemmarketmodel.cpp.

References buildList().

Referenced by checkout(), and ItemMarketModel().

◆ roleNames()

◆ rowCount()

int ItemMarketModel::rowCount ( const QModelIndex & parent) const
overridevirtual

Row count.

Definition at line 92 of file itemmarketmodel.cpp.

References itemListCache.

◆ setData()

bool ItemMarketModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
override

Edit a row (cart count).

Definition at line 200 of file itemmarketmodel.cpp.

References CartCountRole, and itemListCache.

◆ totalCartCount()

int ItemMarketModel::totalCartCount ( )
See also
totalCartCount property.

Definition at line 232 of file itemmarketmodel.cpp.

References itemListCache.

◆ totalCartWorth()

int ItemMarketModel::totalCartWorth ( )
See also
totalCartWorth property.

Definition at line 224 of file itemmarketmodel.cpp.

References itemListCache.

◆ vendorListItem()

bool ItemMarketModel::vendorListItem ( ItemDBEntry * el)

Should el appear in the store list (has a price here)?

Definition at line 408 of file itemmarketmodel.cpp.

References ItemDBEntry::buyPriceCoins(), ItemDBEntry::buyPriceMoney(), ItemDBEntry::canSell(), ItemDBEntry::isGameCornerExclusive(), and isMoneyCurrency.

Referenced by buildMartItemList().

◆ whichMode()

int ItemMarketModel::whichMode ( )
See also
whichMode property.

Definition at line 251 of file itemmarketmodel.cpp.

References isBuyMode, isMoneyCurrency, SelBuyCoins, SelBuyMoney, SelSellCoins, and SelSellMoney.

Member Data Documentation

◆ basics

PlayerBasics* ItemMarketModel::basics = nullptr

◆ file

SaveFile* ItemMarketModel::file = nullptr

The live save.

Definition at line 237 of file itemmarketmodel.h.

Referenced by ItemMarketModel().

◆ isBuyMode

bool ItemMarketModel::isBuyMode = true
See also
isBuyMode property.

Definition at line 218 of file itemmarketmodel.h.

Referenced by data(), ItemMarketModel(), and whichMode().

◆ isExchangeMode

bool ItemMarketModel::isExchangeMode = false
See also
isExchangeMode property.

Definition at line 228 of file itemmarketmodel.h.

Referenced by buildList().

◆ isMoneyCurrency

bool ItemMarketModel::isMoneyCurrency = true
See also
isMoneyCurrency property.

Definition at line 223 of file itemmarketmodel.h.

Referenced by buildMartItemList(), data(), ItemMarketModel(), moneyStart(), vendorListItem(), and whichMode().

◆ itemBag

ItemStorageBox* ItemMarketModel::itemBag = nullptr

The player's bag.

Definition at line 231 of file itemmarketmodel.h.

Referenced by buildMartItemList(), buildPlayerItemList(), and ItemMarketModel().

◆ itemListCache

◆ itemStorage

ItemStorageBox* ItemMarketModel::itemStorage = nullptr

The PC item box.

Definition at line 232 of file itemmarketmodel.h.

Referenced by buildMartItemList(), buildPlayerItemList(), and ItemMarketModel().

◆ playerPokemon

PlayerPokemon* ItemMarketModel::playerPokemon = nullptr

Party (for received Pokemon).

Definition at line 235 of file itemmarketmodel.h.

Referenced by buildMartItemList(), and ItemMarketModel().

◆ router

Router* ItemMarketModel::router = nullptr

For page hooks.

Definition at line 233 of file itemmarketmodel.h.

Referenced by ItemMarketModel().

◆ storage

Storage* ItemMarketModel::storage = nullptr

PC storage (for received Pokemon).

Definition at line 236 of file itemmarketmodel.h.

Referenced by buildMartItemList(), and ItemMarketModel().


The documentation for this class was generated from the following files: