20 label(_label), address(_address), abi(_abi) {}
48 wallet(_wallet), parent(_parent) {}
52 cachedContractTable.clear();
55 for(
const std::pair<std::string, CContractBookData>& item : wallet->
mapContractBook)
57 const std::string&
address = item.first;
58 const std::string& strName = item.second.name;
59 const std::string& strAbi = item.second.abi;
61 QString::fromStdString(strName),
62 QString::fromStdString(address),
63 QString::fromStdString(strAbi)));
73 QList<ContractTableEntry>::iterator lower = qLowerBound(
75 QList<ContractTableEntry>::iterator upper = qUpperBound(
77 int lowerIndex = (lower - cachedContractTable.begin());
78 int upperIndex = (upper - cachedContractTable.begin());
79 bool inModel = (lower != upper);
86 qWarning() <<
"ContractTablePriv::updateEntry: Warning: Got CT_NEW, but entry is already in model";
89 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
91 parent->endInsertRows();
96 qWarning() <<
"ContractTablePriv::updateEntry: Warning: Got CT_UPDATED, but entry is not in model";
106 qWarning() <<
"ContractTablePriv::updateEntry: Warning: Got CT_DELETED, but entry is not in model";
109 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
110 cachedContractTable.erase(lower, upper);
111 parent->endRemoveRows();
118 return cachedContractTable.size();
123 if(idx >= 0 && idx < cachedContractTable.size())
125 return &cachedContractTable[idx];
135 QAbstractTableModel(parent),walletModel(parent),wallet(_wallet),priv(0)
137 columns << tr(
"Label") << tr(
"Contract Address") << tr(
"Interface (ABI)");
166 if(role == Qt::DisplayRole || role == Qt::EditRole)
168 switch(index.column())
171 if(rec->
label.isEmpty() && role == Qt::DisplayRole)
173 return tr(
"(no label)");
185 else if (role == Qt::FontRole)
204 if(role == Qt::EditRole)
207 std::string curAddress = rec->
address.toStdString();
208 std::string curLabel = rec->
label.toStdString();
209 std::string curAbi = rec->
abi.toStdString();
210 if(index.column() ==
Label)
213 if(rec->
label == value.toString())
219 }
else if(index.column() ==
Address) {
220 std::string newAddress = value.toString().toStdString();
223 if(newAddress == curAddress)
243 else if(index.column() ==
ABI) {
245 if(rec->
abi == value.toString())
259 if(orientation == Qt::Horizontal)
261 if(role == Qt::DisplayRole && section <
columns.size())
275 return createIndex(row, column,
priv->
index(row));
279 return QModelIndex();
284 const QString &label,
const QString &abi,
int status)
300 std::string strLabel = label.toStdString();
301 std::string strAddress = address.toStdString();
302 std::string strAbi = abi.toStdString();
315 if(count != 1 || !rec )
333 std::string address_parsed(address.toStdString());
334 std::map<std::string, CContractBookData>::iterator mi =
wallet->
mapContractBook.find(address_parsed);
337 return QString::fromStdString(mi->second.name);
349 std::string address_parsed(address.toStdString());
350 std::map<std::string, CContractBookData>::iterator mi =
wallet->
mapContractBook.find(address_parsed);
353 return QString::fromStdString(mi->second.abi);
361 QModelIndexList lst = match(
index(0,
Address, QModelIndex()),
362 Qt::EditRole, address, 1, Qt::MatchExactly);
369 return lst.at(0).row();
380 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
ContractTablePriv(CWallet *_wallet, ContractTableModel *_parent)
QVariant data(const QModelIndex &index, int role) const
bool setData(const QModelIndex &index, const QVariant &value, int role)
int lookupAddress(const QString &address) const
Address already in contract book.
bool DelContractBook(const std::string &strAddress)
int columnCount(const QModelIndex &parent) const
QString addRow(const QString &label, const QString &address, const QString &abi)
CCriticalSection cs_wallet
bool SetContractBook(const std::string &strAddress, const std::string &strName, const std::string &strAbi)
void emitDataChanged(int index)
Notify listeners that data changed.
void updateEntry(const QString &address, const QString &label, const QString &abi, int status)
bool operator()(const ContractTableEntry &a, const QString &b) const
bool operator()(const ContractTableEntry &a, const ContractTableEntry &b) const
int rowCount(const QModelIndex &parent) const
No changes were made during edit operation.
QList< ContractTableEntry > cachedContractTable
QString abiForAddress(const QString &address) const
ContractTableModel(CWallet *wallet, WalletModel *parent=0)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QString labelForAddress(const QString &address) const
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
void updateEntry(const QString &address, const QString &label, const QString &abi, int status)
bool operator()(const QString &a, const ContractTableEntry &b) const
ContractTableEntry * index(int idx)
QModelIndex index(int row, int column, const QModelIndex &parent) const
Qt model of the contract book in the core.
ContractTableEntry(const QString &_label, const QString &_address, const QString &_abi)
friend class ContractTablePriv
std::map< std::string, CContractBookData > mapContractBook
Interface to Fabcoin wallet from Qt view code.
void updateEditStatus(EditStatus status)
void refreshContractTable()
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
struct evm_uint160be address(struct evm_env *env)
ContractTableModel * parent
EditStatus
Return status of edit/insert operation.