⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 currencymodel.cpp

📁 Qt4的一些例子
💻 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 + -