Just Wonder
5 years ago
11 changed files with 519 additions and 0 deletions
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>KevaMyNamespacesDialog</class> |
||||
<widget class="QDialog" name="KevaMyNamespacesDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>800</width> |
||||
<height>400</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string notr="true">My Namespaces</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QTableView" name="namespaceView"> |
||||
<property name="contextMenuPolicy"> |
||||
<enum>Qt::CustomContextMenu</enum> |
||||
</property> |
||||
<property name="tabKeyNavigation"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="sortingEnabled"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>KevaMyNamespacesDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>20</x> |
||||
<y>20</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>20</x> |
||||
<y>20</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>KevaMyNamespacesDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>20</x> |
||||
<y>20</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>20</x> |
||||
<y>20</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <qt/kevamynamespacesdialog.h> |
||||
#include <qt/forms/ui_kevamynamespacesdialog.h> |
||||
|
||||
#include <qt/kevanamespacemodel.h> |
||||
|
||||
#include <QModelIndex> |
||||
|
||||
KevaMyNamespacesDialog::KevaMyNamespacesDialog(QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::KevaMyNamespacesDialog) |
||||
{ |
||||
ui->setupUi(this); |
||||
} |
||||
|
||||
void KevaMyNamespacesDialog::setModel(WalletModel *_model) |
||||
{ |
||||
this->model = _model; |
||||
|
||||
if(_model && _model->getOptionsModel()) |
||||
{ |
||||
_model->getKevaNamespaceModel()->sort(KevaNamespaceModel::Name, Qt::DescendingOrder); |
||||
QTableView* tableView = ui->namespaceView; |
||||
|
||||
tableView->verticalHeader()->hide(); |
||||
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||
tableView->setModel(_model->getKevaNamespaceModel()); |
||||
tableView->setAlternatingRowColors(true); |
||||
tableView->setSelectionBehavior(QAbstractItemView::SelectRows); |
||||
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection); |
||||
//tableView->setColumnWidth(KevaNamespaceModel::Id, ID_COLUMN_WIDTH);
|
||||
//tableView->setColumnWidth(KevaNamespaceModel::Name, NAME_COLUMN_WIDTH);
|
||||
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
||||
|
||||
connect(tableView->selectionModel(), |
||||
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, |
||||
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection))); |
||||
} |
||||
} |
||||
|
||||
void KevaMyNamespacesDialog::accept() |
||||
{ |
||||
// Create the namespace here.
|
||||
QDialog::accept(); |
||||
} |
||||
|
||||
KevaMyNamespacesDialog::~KevaMyNamespacesDialog() |
||||
{ |
||||
delete ui; |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2011-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_QT_KEVAMYNMAESPACESDIALOG_H |
||||
#define BITCOIN_QT_KEVAMYNMAESPACESDIALOG_H |
||||
|
||||
#include <QObject> |
||||
#include <QString> |
||||
|
||||
#include <QDialog> |
||||
|
||||
class WalletModel; |
||||
|
||||
namespace Ui { |
||||
class KevaMyNamespacesDialog; |
||||
} |
||||
|
||||
|
||||
/** Dialog showing namepsace creation. */ |
||||
class KevaMyNamespacesDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
enum ColumnWidths { |
||||
ID_COLUMN_WIDTH = 260, |
||||
NAME_COLUMN_WIDTH = 260, |
||||
MINIMUM_COLUMN_WIDTH = 260 |
||||
}; |
||||
|
||||
public: |
||||
explicit KevaMyNamespacesDialog(QWidget *parent = 0); |
||||
~KevaMyNamespacesDialog(); |
||||
void accept(); |
||||
void setModel(WalletModel *_model); |
||||
|
||||
private: |
||||
Ui::KevaMyNamespacesDialog *ui; |
||||
WalletModel *model; |
||||
}; |
||||
|
||||
#endif // BITCOIN_QT_KEVAMYNMAESPACESDIALOG_H
|
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <qt/kevanamespacemodel.h> |
||||
|
||||
#include <qt/bitcoinunits.h> |
||||
#include <qt/guiutil.h> |
||||
#include <qt/optionsmodel.h> |
||||
|
||||
#include <clientversion.h> |
||||
#include <streams.h> |
||||
|
||||
|
||||
KevaNamespaceModel::KevaNamespaceModel(CWallet *wallet, WalletModel *parent) : |
||||
QAbstractTableModel(parent), walletModel(parent) |
||||
{ |
||||
Q_UNUSED(wallet) |
||||
|
||||
/* These columns must match the indices in the ColumnIndex enumeration */ |
||||
columns << tr("Id") << tr("Name"); |
||||
} |
||||
|
||||
KevaNamespaceModel::~KevaNamespaceModel() |
||||
{ |
||||
/* Intentionally left empty */ |
||||
} |
||||
|
||||
int KevaNamespaceModel::rowCount(const QModelIndex &parent) const |
||||
{ |
||||
Q_UNUSED(parent); |
||||
|
||||
return list.length(); |
||||
} |
||||
|
||||
int KevaNamespaceModel::columnCount(const QModelIndex &parent) const |
||||
{ |
||||
Q_UNUSED(parent); |
||||
|
||||
return columns.length(); |
||||
} |
||||
|
||||
QVariant KevaNamespaceModel::data(const QModelIndex &index, int role) const |
||||
{ |
||||
if(!index.isValid() || index.row() >= list.length()) |
||||
return QVariant(); |
||||
|
||||
if(role == Qt::DisplayRole || role == Qt::EditRole) |
||||
{ |
||||
const NamespaceEntry *rec = &list[index.row()]; |
||||
switch(index.column()) |
||||
{ |
||||
case Id: |
||||
return QString::fromStdString(rec->id); |
||||
case Name: |
||||
return QString::fromStdString(rec->name); |
||||
} |
||||
} |
||||
else if (role == Qt::TextAlignmentRole) |
||||
{ |
||||
return (int)(Qt::AlignLeft|Qt::AlignVCenter); |
||||
} |
||||
return QVariant(); |
||||
} |
||||
|
||||
bool KevaNamespaceModel::setData(const QModelIndex &index, const QVariant &value, int role) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
QVariant KevaNamespaceModel::headerData(int section, Qt::Orientation orientation, int role) const |
||||
{ |
||||
if(orientation == Qt::Horizontal) |
||||
{ |
||||
if(role == Qt::DisplayRole && section < columns.size()) |
||||
{ |
||||
return columns[section]; |
||||
} |
||||
} |
||||
return QVariant(); |
||||
} |
||||
|
||||
|
||||
QModelIndex KevaNamespaceModel::index(int row, int column, const QModelIndex &parent) const |
||||
{ |
||||
Q_UNUSED(parent); |
||||
|
||||
return createIndex(row, column); |
||||
} |
||||
|
||||
bool KevaNamespaceModel::removeRows(int row, int count, const QModelIndex &parent) |
||||
{ |
||||
Q_UNUSED(parent); |
||||
|
||||
if(count > 0 && row >= 0 && (row+count) <= list.size()) |
||||
{ |
||||
beginRemoveRows(parent, row, row + count - 1); |
||||
list.erase(list.begin() + row, list.begin() + row + count); |
||||
endRemoveRows(); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
Qt::ItemFlags KevaNamespaceModel::flags(const QModelIndex &index) const |
||||
{ |
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled; |
||||
} |
||||
|
||||
|
||||
// actually add to table in GUI
|
||||
void KevaNamespaceModel::setNamespace(std::vector<NamespaceEntry> vNamespaceEntries) |
||||
{ |
||||
// Remove the old ones.
|
||||
removeRows(0, list.size()); |
||||
list.clear(); |
||||
|
||||
for (auto it = vNamespaceEntries.begin(); it != vNamespaceEntries.end(); it++) { |
||||
beginInsertRows(QModelIndex(), 0, 0); |
||||
list.prepend(*it); |
||||
endInsertRows(); |
||||
} |
||||
} |
||||
|
||||
void KevaNamespaceModel::sort(int column, Qt::SortOrder order) |
||||
{ |
||||
qSort(list.begin(), list.end(), NamespaceEntryLessThan(column, order)); |
||||
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex())); |
||||
} |
||||
|
||||
|
||||
bool NamespaceEntryLessThan::operator()(NamespaceEntry &left, NamespaceEntry &right) const |
||||
{ |
||||
NamespaceEntry *pLeft = &left; |
||||
NamespaceEntry *pRight = &right; |
||||
if (order == Qt::DescendingOrder) |
||||
std::swap(pLeft, pRight); |
||||
|
||||
switch(column) |
||||
{ |
||||
case KevaNamespaceModel::Id: |
||||
return pLeft->id < pRight->id; |
||||
case KevaNamespaceModel::Name: |
||||
return pLeft->name < pRight->name; |
||||
default: |
||||
return pLeft->id < pRight->id; |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_QT_KEVANAMESPACEMODEL_H |
||||
#define BITCOIN_QT_KEVANAMESPACEMODEL_H |
||||
|
||||
#include <qt/walletmodel.h> |
||||
|
||||
#include <QAbstractTableModel> |
||||
#include <QStringList> |
||||
#include <QDateTime> |
||||
|
||||
class CWallet; |
||||
|
||||
class NamespaceEntry |
||||
{ |
||||
public: |
||||
NamespaceEntry() { } |
||||
|
||||
std::string id; |
||||
std::string name; |
||||
}; |
||||
|
||||
class NamespaceEntryLessThan |
||||
{ |
||||
public: |
||||
NamespaceEntryLessThan(int nColumn, Qt::SortOrder fOrder): |
||||
column(nColumn), order(fOrder) {} |
||||
bool operator()(NamespaceEntry &left, NamespaceEntry &right) const; |
||||
|
||||
private: |
||||
int column; |
||||
Qt::SortOrder order; |
||||
}; |
||||
|
||||
/** Model for list of recently generated payment requests / bitcoin: URIs.
|
||||
* Part of wallet model. |
||||
*/ |
||||
class KevaNamespaceModel: public QAbstractTableModel |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit KevaNamespaceModel(CWallet *wallet, WalletModel *parent); |
||||
~KevaNamespaceModel(); |
||||
|
||||
enum ColumnIndex { |
||||
Id = 0, |
||||
Name = 1, |
||||
NUMBER_OF_COLUMNS |
||||
}; |
||||
|
||||
/** @name Methods overridden from QAbstractTableModel
|
||||
@{*/ |
||||
int rowCount(const QModelIndex &parent) const; |
||||
int columnCount(const QModelIndex &parent) const; |
||||
QVariant data(const QModelIndex &index, int role) const; |
||||
bool setData(const QModelIndex &index, const QVariant &value, int role); |
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const; |
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
||||
Qt::ItemFlags flags(const QModelIndex &index) const; |
||||
/*@}*/ |
||||
|
||||
const NamespaceEntry &entry(int row) const { return list[row]; } |
||||
void setNamespace(std::vector<NamespaceEntry> vNamespaceEntries); |
||||
|
||||
public Q_SLOTS: |
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); |
||||
|
||||
private: |
||||
WalletModel *walletModel; |
||||
QStringList columns; |
||||
QList<NamespaceEntry> list; |
||||
int64_t nReceiveRequestsMaxId; |
||||
}; |
||||
|
||||
#endif // BITCOIN_QT_KEVANAMESPACEMODEL_H
|
Loading…
Reference in new issue