[GUI] Add debugging UI for fetching accounts

This commit is contained in:
Nathan Hourt 2015-07-13 16:21:01 -04:00
parent 2f429e07f1
commit b8bd8a1905
3 changed files with 53 additions and 20 deletions

View file

@ -10,7 +10,7 @@ using namespace graphene::app;
ChainDataModel::ChainDataModel( fc::thread& t, QObject* parent ) ChainDataModel::ChainDataModel( fc::thread& t, QObject* parent )
:QObject(parent),m_thread(&t){} :QObject(parent),m_thread(&t){}
Account* ChainDataModel::getAccount(qint64 id) Account* ChainDataModel::getAccount(qint64 id)
{ {
auto itr = m_accounts.find( id ); auto itr = m_accounts.find( id );
if( itr != m_accounts.end() ) if( itr != m_accounts.end() )
@ -22,7 +22,7 @@ Account* ChainDataModel::getAccount(qint64 id)
auto insert_result = m_accounts.insert( acct ); auto insert_result = m_accounts.insert( acct );
/** execute in app thread */ /** execute in app thread */
m_thread->async( [=](){ m_thread->async( [=](){
try { try {
auto result = m_db_api->get_accounts( {account_id_type(id)} ); auto result = m_db_api->get_accounts( {account_id_type(id)} );
if( result.size() && result.front().valid() ) if( result.size() && result.front().valid() )
@ -30,7 +30,7 @@ Account* ChainDataModel::getAccount(qint64 id)
QString name = QString::fromStdString( result.front()->name ); QString name = QString::fromStdString( result.front()->name );
/** execute in main */ /** execute in main */
Q_EMIT queueExecute( [=](){ Q_EMIT queueExecute( [=](){
this->m_accounts.modify( insert_result.first, this->m_accounts.modify( insert_result.first,
[=]( Account* a ){ a->setProperty("name", name ); } [=]( Account* a ){ a->setProperty("name", name ); }
); );
}); });
@ -43,9 +43,10 @@ Account* ChainDataModel::getAccount(qint64 id)
m_accounts.erase( insert_result.first ); m_accounts.erase( insert_result.first );
}); });
} }
} }
catch ( const fc::exception& e ) catch ( const fc::exception& e )
{ {
edump((e.to_detail_string()));
Q_EMIT exceptionThrown( QString::fromStdString(e.to_string()) ); Q_EMIT exceptionThrown( QString::fromStdString(e.to_string()) );
} }
}); });
@ -53,7 +54,7 @@ Account* ChainDataModel::getAccount(qint64 id)
return acct; return acct;
} }
Account* ChainDataModel::getAccount(QString name) Account* ChainDataModel::getAccount(QString name)
{ {
auto itr = m_accounts.get<::by_name>().find(name); auto itr = m_accounts.get<::by_name>().find(name);
if( itr != m_accounts.get<::by_name>().end() ) if( itr != m_accounts.get<::by_name>().end() )
@ -61,23 +62,22 @@ Account* ChainDataModel::getAccount(QString name)
return *itr; return *itr;
} }
auto acct = new Account(this); auto acct = new Account(this);
acct->setProperty("id", --m_account_query_num ); acct->setProperty("id", --m_account_query_num );
acct->setProperty("name", name); acct->setProperty("name", name);
auto insert_result = m_accounts.insert( acct ); auto insert_result = m_accounts.insert( acct );
/** execute in app thread */ /** execute in app thread */
m_thread->async( [=](){ m_thread->async( [=](){
try { try {
auto result = m_db_api->lookup_account_names( {name.toStdString()} ); auto result = m_db_api->lookup_account_names( {name.toStdString()} );
if( result.size() && result.front().valid() ) if( result.size() && result.front().valid() )
{ {
/** execute in main */ /** execute in main */
Q_EMIT queueExecute( [=](){ Q_EMIT queueExecute( [=](){
this->m_accounts.modify( insert_result.first, this->m_accounts.modify( insert_result.first,
[=]( Account* a ){ [=]( Account* a ){
a->setProperty("id", result.front()->id.instance() ); a->setProperty("id", result.front()->id.instance() );
} }
); );
}); });
@ -90,14 +90,15 @@ Account* ChainDataModel::getAccount(QString name)
m_accounts.erase( insert_result.first ); m_accounts.erase( insert_result.first );
}); });
} }
} }
catch ( const fc::exception& e ) catch ( const fc::exception& e )
{ {
edump((e.to_detail_string()));
Q_EMIT exceptionThrown( QString::fromStdString(e.to_string()) ); Q_EMIT exceptionThrown( QString::fromStdString(e.to_string()) );
} }
}); });
return nullptr; return acct;
} }
QQmlListProperty<Balance> Account::balances() QQmlListProperty<Balance> Account::balances()

View file

@ -47,8 +47,8 @@ class Balance : public QObject {
class Account : public QObject { class Account : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString name MEMBER name) Q_PROPERTY(QString name MEMBER name NOTIFY nameChanged)
Q_PROPERTY(qint64 id MEMBER id) Q_PROPERTY(qint64 id MEMBER id NOTIFY idChanged)
Q_PROPERTY(QQmlListProperty<Balance> balances READ balances) Q_PROPERTY(QQmlListProperty<Balance> balances READ balances)
QString name; QString name;
@ -63,9 +63,13 @@ public:
qint64 getId()const { return id; } qint64 getId()const { return id; }
QQmlListProperty<Balance> balances(); QQmlListProperty<Balance> balances();
signals:
void nameChanged();
void idChanged();
}; };
struct by_id; struct by_id;
struct by_name; struct by_name;
/** /**
* @ingroup object_index * @ingroup object_index

View file

@ -38,13 +38,41 @@ ApplicationWindow {
id: appSettings id: appSettings
category: "appSettings" category: "appSettings"
} }
Connections {
target: app
onExceptionThrown: console.log("Exception from app: " + message)
}
Button { Column {
text: "Transfer"
anchors.centerIn: parent anchors.centerIn: parent
onClicked: formBox.showForm(Qt.createComponent("TransferForm.qml"), function() { Button {
console.log("Closed form") text: "Transfer"
}) onClicked: formBox.showForm(Qt.createComponent("TransferForm.qml"), function() {
console.log("Closed form")
})
}
TextField {
id: nameField
onAccepted: lookupButton.clicked()
focus: true
}
Button {
id: lookupButton
text: "Lookup"
onClicked: {
var acct = app.model.getAccount(nameField.text)
// @disable-check M126
if (acct == null)
console.log("Got back null account")
else if (acct.id >= 0)
console.log(JSON.stringify(acct))
else
console.log("Waiting for result...")
acct.idChanged.connect(function(loadedAcct) {
console.log(JSON.stringify(loadedAcct))
})
}
}
} }
FormBox { FormBox {