?? currencymodel.cpp
字號:
#include <QtCore>#include "currencymodel.h"CurrencyModel::CurrencyModel(QObject *parent) : QAbstractTableModel(parent){}void CurrencyModel::setCurrencyMap(const QMap<QString, double> &map){ currencyMap = map; reset();}int CurrencyModel::rowCount(const QModelIndex & /* parent */) const{ return currencyMap.count();}int CurrencyModel::columnCount(const QModelIndex & /* parent */) const{ return currencyMap.count();}QVariant CurrencyModel::data(const QModelIndex &index, int role) const{ if (!index.isValid()) return QVariant(); if (role == Qt::TextAlignmentRole) { return int(Qt::AlignRight | Qt::AlignVCenter); } else if (role == Qt::DisplayRole) { QString rowCurrency = currencyAt(index.row()); QString columnCurrency = currencyAt(index.column()); if (currencyMap.value(rowCurrency) == 0.0) return "####"; double amount = currencyMap.value(columnCurrency) / currencyMap.value(rowCurrency); return QString("%1").arg(amount, 0, 'f', 4); } return QVariant();}QVariant CurrencyModel::headerData(int section, Qt::Orientation /* orientation */, int role) const{ if (role != Qt::DisplayRole) return QVariant(); return currencyAt(section);}QString CurrencyModel::currencyAt(int offset) const{ return (currencyMap.begin() + offset).key();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -