Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Inventory Class Reference

The inventory: one row per part, with totals. Knows nothing about widgets. More...

Inheritance diagram for Inventory:

Public Types

enum  Column {
  SkuColumn , NameColumn , QuantityColumn , PriceColumn ,
  ValueColumn , ColumnCount
}
 The columns the table shows.
enum  Role {
  SkuRole = Qt::UserRole + 1 , NameRole , QuantityRole , PriceRole ,
  ValueRole
}
 The roles a QML view uses, the same in every column.

Public Member Functions

 Inventory (QList< Part > parts, QObject *parent=nullptr)
 An inventory holding parts.
int count () const
 How many kinds of part there are.
int totalQuantity () const
 How many pieces there are, of every kind.
double totalValue () const
 What the whole stock is worth, in dollars.
int rowCount (const QModelIndex &parent={ }) const override
 See QAbstractItemModel.
int columnCount (const QModelIndex &parent={ }) const override
 See QAbstractItemModel.
QVariant data (const QModelIndex &index, int role) const override
 See QAbstractItemModel.
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 See QAbstractItemModel.
QHash< int, QByteArray > roleNames () const override
 See QAbstractItemModel.
bool addPart (const QString &sku, const QString &name, int quantity, double price)
 Adds a part.
bool adjust (const QString &sku, int delta)
 Adds delta to the quantity of sku (never below zero).
bool removePart (const QString &sku)
 Removes sku.
void countChanged ()
 The number of parts changed.
void totalsChanged ()
 A quantity changed, or a part was added or removed.

Static Public Member Functions

static QString money (double dollars)
 dollars as money, "$1,234.50".

Private Member Functions

int rowOf (const QString &sku) const
 The row of sku, or -1.

Private Attributes

QList< Part > m_parts
 The rows.

Detailed Description

The inventory: one row per part, with totals. Knows nothing about widgets.

Member Function Documentation

◆ addPart()

bool Inventory::addPart ( const QString & sku,
const QString & name,
int quantity,
double price )
inline

Adds a part.

Returns
False if sku is empty or already used, or name is empty.

◆ adjust()

bool Inventory::adjust ( const QString & sku,
int delta )
inline

Adds delta to the quantity of sku (never below zero).

Returns
False if there is no such part.

◆ removePart()

bool Inventory::removePart ( const QString & sku)
inline

Removes sku.

Returns
False if there is no such part.

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