Changeset View
Changeset View
Standalone View
Standalone View
src/qt/addresstablemodel.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
/* Determine address type from address purpose */ | /* Determine address type from address purpose */ | ||||
static AddressTableEntry::Type | static AddressTableEntry::Type | ||||
translateTransactionType(const QString &strPurpose, bool isMine) { | translateTransactionType(const QString &strPurpose, bool isMine) { | ||||
AddressTableEntry::Type addressType = AddressTableEntry::Hidden; | AddressTableEntry::Type addressType = AddressTableEntry::Hidden; | ||||
// "refund" addresses aren't shown, and change addresses aren't in | // "refund" addresses aren't shown, and change addresses aren't in | ||||
// mapAddressBook at all. | // mapAddressBook at all. | ||||
if (strPurpose == "send") | if (strPurpose == "send") { | ||||
addressType = AddressTableEntry::Sending; | addressType = AddressTableEntry::Sending; | ||||
else if (strPurpose == "receive") | } else if (strPurpose == "receive") { | ||||
addressType = AddressTableEntry::Receiving; | addressType = AddressTableEntry::Receiving; | ||||
else if (strPurpose == "unknown" || strPurpose == "") { | } else if (strPurpose == "unknown" || strPurpose == "") { | ||||
// if purpose not set, guess | // if purpose not set, guess | ||||
addressType = (isMine ? AddressTableEntry::Receiving | addressType = (isMine ? AddressTableEntry::Receiving | ||||
: AddressTableEntry::Sending); | : AddressTableEntry::Sending); | ||||
} | } | ||||
return addressType; | return addressType; | ||||
} | } | ||||
// Private implementation | // Private implementation | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int AddressTableModel::columnCount(const QModelIndex &parent) const { | int AddressTableModel::columnCount(const QModelIndex &parent) const { | ||||
Q_UNUSED(parent); | Q_UNUSED(parent); | ||||
return columns.length(); | return columns.length(); | ||||
} | } | ||||
QVariant AddressTableModel::data(const QModelIndex &index, int role) const { | QVariant AddressTableModel::data(const QModelIndex &index, int role) const { | ||||
if (!index.isValid()) return QVariant(); | if (!index.isValid()) { | ||||
return QVariant(); | |||||
} | |||||
AddressTableEntry *rec = | AddressTableEntry *rec = | ||||
static_cast<AddressTableEntry *>(index.internalPointer()); | static_cast<AddressTableEntry *>(index.internalPointer()); | ||||
if (role == Qt::DisplayRole || role == Qt::EditRole) { | if (role == Qt::DisplayRole || role == Qt::EditRole) { | ||||
switch (index.column()) { | switch (index.column()) { | ||||
case Label: | case Label: | ||||
if (rec->label.isEmpty() && role == Qt::DisplayRole) { | if (rec->label.isEmpty() && role == Qt::DisplayRole) { | ||||
Show All 20 Lines | if (role == Qt::DisplayRole || role == Qt::EditRole) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return QVariant(); | return QVariant(); | ||||
} | } | ||||
bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, | bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, | ||||
int role) { | int role) { | ||||
if (!index.isValid()) return false; | if (!index.isValid()) { | ||||
return false; | |||||
} | |||||
AddressTableEntry *rec = | AddressTableEntry *rec = | ||||
static_cast<AddressTableEntry *>(index.internalPointer()); | static_cast<AddressTableEntry *>(index.internalPointer()); | ||||
std::string strPurpose = | std::string strPurpose = | ||||
(rec->type == AddressTableEntry::Sending ? "send" : "receive"); | (rec->type == AddressTableEntry::Sending ? "send" : "receive"); | ||||
editStatus = OK; | editStatus = OK; | ||||
if (role == Qt::EditRole) { | if (role == Qt::EditRole) { | ||||
CTxDestination curAddress = DecodeDestination( | CTxDestination curAddress = DecodeDestination( | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (orientation == Qt::Horizontal) { | ||||
if (role == Qt::DisplayRole && section < columns.size()) { | if (role == Qt::DisplayRole && section < columns.size()) { | ||||
return columns[section]; | return columns[section]; | ||||
} | } | ||||
} | } | ||||
return QVariant(); | return QVariant(); | ||||
} | } | ||||
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const { | Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const { | ||||
if (!index.isValid()) return 0; | if (!index.isValid()) { | ||||
return 0; | |||||
} | |||||
AddressTableEntry *rec = | AddressTableEntry *rec = | ||||
static_cast<AddressTableEntry *>(index.internalPointer()); | static_cast<AddressTableEntry *>(index.internalPointer()); | ||||
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled; | Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled; | ||||
// Can edit address and label for sending addresses, and only label for | // Can edit address and label for sending addresses, and only label for | ||||
// receiving addresses. | // receiving addresses. | ||||
if (rec->type == AddressTableEntry::Sending || | if (rec->type == AddressTableEntry::Sending || | ||||
(rec->type == AddressTableEntry::Receiving && | (rec->type == AddressTableEntry::Receiving && | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |