diff --git a/src/qt/managenamespage.cpp b/src/qt/managenamespage.cpp index 5f47c9982b..5ac44a8ab9 100644 --- a/src/qt/managenamespage.cpp +++ b/src/qt/managenamespage.cpp @@ -162,12 +162,12 @@ void ManageNamesPage::contextualMenu(const QPoint &point) void ManageNamesPage::onCopyNameAction() { - GUIUtil::copyEntryData(ui->tableView, NameTableModel::Name); + GUIUtil::copyEntryData(ui->tableView, NameTableModel::Name, NameTableModel::BinaryRole); } void ManageNamesPage::onCopyValueAction() { - GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value); + GUIUtil::copyEntryData(ui->tableView, NameTableModel::Value, NameTableModel::BinaryRole); } void ManageNamesPage::onConfigureNameAction() @@ -185,9 +185,9 @@ void ManageNamesPage::onConfigureNameAction() return; const QModelIndex &index = indexes.at(0); - const QString name = index.data(Qt::EditRole).toString(); + const QString name = index.data(NameTableModel::BinaryRole).toString(); const std::string strName = name.toStdString(); - const QString initValue = index.sibling(index.row(), NameTableModel::Value).data(Qt::EditRole).toString(); + const QString initValue = index.sibling(index.row(), NameTableModel::Value).data(NameTableModel::BinaryRole).toString(); ConfigureNameDialog dlg(platformStyle, name, initValue, this); dlg.setModel(walletModel); @@ -220,7 +220,7 @@ void ManageNamesPage::onRenewNameAction() { const QString name = indexes.at(0).data(Qt::EditRole).toString(); - msg = tr ("Are you sure you want to renew the name %1?") + msg = tr ("Are you sure you want to renew the %1?") .arg (GUIUtil::HtmlEscape (name)); title = tr ("Confirm name renewal"); } @@ -243,7 +243,7 @@ void ManageNamesPage::onRenewNameAction() for (const QModelIndex& index : indexes) { - const QString name = index.data(Qt::EditRole).toString(); + const QString name = index.data(NameTableModel::BinaryRole).toString(); const QString err_msg = model->renew(name); if (!err_msg.isEmpty() && err_msg != "ABORTED") diff --git a/src/qt/nametablemodel.cpp b/src/qt/nametablemodel.cpp index 9b1a854f78..6a14e95dba 100644 --- a/src/qt/nametablemodel.cpp +++ b/src/qt/nametablemodel.cpp @@ -4,6 +4,9 @@ #include #include #include + +#include +#include #include #include @@ -410,16 +413,42 @@ QVariant NameTableModel::data(const QModelIndex &index, int role) const NameTableEntry *rec = static_cast(index.internalPointer()); - // TODO: implement Qt::ForegroudRole for font color styling for states? + // TODO: implement Qt::ForegroundRole for font color styling for states? // TODO: implement Qt::ToolTipRole show name status on tooltip if(role == Qt::DisplayRole || role == Qt::EditRole) { switch(index.column()) { case Name: - return rec->name; + { + NameNamespace ns = NamespaceFromName(rec->name.toStdString()); + std::string strDesc = DescFromName(rec->name.toStdString(), ns); + QString desc = QString::fromStdString(strDesc); + + switch(ns) + { + case NameNamespace::Domain: + return tr("Domain %1").arg(desc); + case NameNamespace::DomainData: + return tr("Domain data %1").arg(desc); + case NameNamespace::Identity: + return tr("Identity %1").arg(desc); + case NameNamespace::IdentityData: + return tr("Identity data %1").arg(desc); + case NameNamespace::NonStandard: + return tr("Non-standard name %1").arg(desc); + } // no default case, so the compiler can warn about missing cases + assert(false); + } case Value: - return rec->value; + { + // TODO: Refactor this function and EncodeNameForMessage to avoid double conversion + std::string strValue = rec->value.toStdString(); + const valtype vtValue = valtype (strValue.begin (), strValue.end ()); + std::string encodedValue = EncodeNameForMessage(vtValue); + + return QString::fromStdString(encodedValue); + } case ExpiresIn: return rec->expiresIn; case NameStatus: @@ -430,6 +459,17 @@ QVariant NameTableModel::data(const QModelIndex &index, int role) const if(role == Qt::TextAlignmentRole) return column_alignments[index.column()]; + if(role == BinaryRole) + { + switch(index.column()) + { + case Name: + return rec->name; + case Value: + return rec->value; + } + } + return QVariant(); } diff --git a/src/qt/nametablemodel.h b/src/qt/nametablemodel.h index 0c20faf4a3..bf37917ba0 100644 --- a/src/qt/nametablemodel.h +++ b/src/qt/nametablemodel.h @@ -41,6 +41,11 @@ class NameTableModel : public QAbstractTableModel NameStatus = 3 }; + enum RoleIndex { + /** Binary data corresponding to name/value */ + BinaryRole = Qt::UserRole, + }; + /** @name Methods overridden from QAbstractTableModel @{*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;