forked from ciphrex/mSIGNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptmodel.cpp
118 lines (92 loc) · 2.78 KB
/
scriptmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
///////////////////////////////////////////////////////////////////////////////
//
// mSIGNA
//
// scriptmodel.cpp
//
// Copyright (c) 2013 Eric Lombrozo
//
// All Rights Reserved.
#include "scriptmodel.h"
#include "settings.h"
#include <CoinQ/CoinQ_script.h>
#include <QStandardItemModel>
using namespace CoinDB;
using namespace CoinQ::Script;
using namespace std;
ScriptModel::ScriptModel(QObject* parent)
: QStandardItemModel(parent)
{
initColumns();
}
ScriptModel::ScriptModel(CoinDB::Vault* vault, const QString& accountName, QObject* parent)
: QStandardItemModel(parent)
{
initColumns();
setVault(vault);
setAccount(accountName);
}
void ScriptModel::initColumns()
{
QStringList columns;
columns << tr("Address") << tr("Type") << tr("Description");
setHorizontalHeaderLabels(columns);
}
void ScriptModel::setVault(CoinDB::Vault* vault)
{
this->vault = vault;
accountName.clear();
}
void ScriptModel::setAccount(const QString& accountName)
{
if (!vault) {
throw std::runtime_error("Vault is not open.");
}
if (!vault->accountExists(accountName.toStdString())) {
throw std::runtime_error("Account not found.");
}
this->accountName = accountName;
}
void ScriptModel::update()
{
removeRows(0, rowCount());
if (!vault || accountName.isEmpty()) return;
std::vector<SigningScriptView> scripts = vault->getSigningScriptViews(accountName.toStdString(), "", SigningScript::CHANGE | SigningScript::ISSUED | SigningScript::USED);
for (auto& script: scripts) {
QList<QStandardItem*> row;
QString address = QString::fromStdString(getAddressForTxOutScript(script.txoutscript, getDefaultSettings().getBase58Versions()));
QString type;
switch (script.status) {
case SigningScript::CHANGE:
type = tr("Change");
break;
case SigningScript::ISSUED:
type = tr("Issued");
break;
case SigningScript::USED:
type = tr("Used");
break;
default:
type = tr("Unknown");
}
QString description = QString::fromStdString(script.label);
row.append(new QStandardItem(address));
row.append(new QStandardItem(type));
row.append(new QStandardItem(description));
appendRow(row);
}
}
bool ScriptModel::setData(const QModelIndex& /*index*/, const QVariant& /*value*/, int /*role*/)
{
return false;
}
Qt::ItemFlags ScriptModel::flags(const QModelIndex& index) const
{
// Make the address editable as a workaround so it can be copied to clipboard.
// TODO: Script context menu
if (index.column() == 0)
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
}
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}