Skip to content

Commit

Permalink
Merge pull request bitcoin#21 from CryptAxe/master
Browse files Browse the repository at this point in the history
Fix Author widget issues / bugs found testing
  • Loading branch information
psztorc committed Jan 28, 2016
2 parents ec9afa5 + cc3d864 commit f82c96e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 48 deletions.
97 changes: 96 additions & 1 deletion src/qt/authorpendingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QVariant AuthorPendingTableModel::data(const QModelIndex &index, int role) const
{
json_spirit::Array pendingCreation = pending.at(row);

/* Display data shared between decisions and markets */
/* Display data shared between all types */

// Type
std::string type = json_spirit::write_string(pendingCreation.back(), true);
Expand All @@ -52,6 +52,101 @@ QVariant AuthorPendingTableModel::data(const QModelIndex &index, int role) const
return "0.02"; // Dummy temp
}

/* Display Combo */

if (type == "\"combo\"") {
// Branch ID
if (col == 3) {
std::string branchID = json_spirit::write_string(pendingCreation.at(1), true);
return QString::fromStdString(branchID);
}

// Prompt
if (col == 4) {
std::string prompt = json_spirit::write_string(pendingCreation.at(2), true);
return QString::fromStdString(prompt);
}

// Event Over By
if (col == 5) {
int eventOverBy = pendingCreation.at(3).get_int();
return eventOverBy;
}

// Answer Optionality
if (col == 6) {
bool answerOptionality = pendingCreation.at(4).get_bool();
return answerOptionality;
}

// Is Scaled?
bool scaled = false;
if (col == 7) {
scaled = pendingCreation.at(5).get_bool();
return scaled;
}

// Decision ID
if (col == 8) {
std::string decisionID = json_spirit::write_string(pendingCreation.at(8), true);
return QString::fromStdString(decisionID);
}

// Liquidity Factor (B)
if (col == 9) {
double B = pendingCreation.at(9).get_real();
return B;
}

// Trading Fee
if (col == 10) {
double tradingFee = pendingCreation.at(10).get_real();
return tradingFee;
}

// Max Commission
if (col == 11) {
double maxCommission = pendingCreation.at(11).get_real();
return maxCommission;
}

// Title
if (col == 12) {
std::string title = json_spirit::write_string(pendingCreation.at(12), true);
return QString::fromStdString(title);
}

// Description
if (col == 13) {
std::string description = json_spirit::write_string(pendingCreation.at(13), true);
return QString::fromStdString(description);
}

// Tags
if (col == 14) {
std::string tags = json_spirit::write_string(pendingCreation.at(14), true);
return QString::fromStdString(tags);
}

// Maturation
if (col == 15) {
int maturation = pendingCreation.at(15).get_int();
return maturation;
}

// txPoWh
if (col == 16) {
int txPoWh = pendingCreation.at(16).get_int();
return txPoWh;
}

// txPoWd
if (col == 17) {
int txPoWd = pendingCreation.at(17).get_int();
return txPoWd;
}
}

/* Display data unique to decisions */

if (type == "\"decision\"") {
Expand Down
1 change: 1 addition & 0 deletions src/qt/authorview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ AuthorView::AuthorView(QWidget *parent) :
pendingTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
pendingTableModel = new AuthorPendingTableModel(this);
pendingTableView->setModel(pendingTableModel);
pendingTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->frameLeft->layout()->addWidget(pendingTableView);

// Setup signals
Expand Down
3 changes: 3 additions & 0 deletions src/qt/decisioncreationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ void DecisionCreationWidget::editArray(json_spirit::Array array)
ui->doubleSpinBoxScaledMax->setValue(scaledMax.get_real());
}

// Unhide the scaled spinboxes if the decision is scaled
on_radioButtonScaled_clicked(isScaled);

// Check for update index from model
if (isScaled && array.size() == 10) {
ui->pushButtonCreateDecision->hide();
Expand Down
42 changes: 37 additions & 5 deletions src/qt/decisionmarketcreationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@ json_spirit::Array DecisionMarketCreationWidget::createDecisionMarketArray()
{
// Grab user input from the ui
QString address = ui->lineEditAuthorAddress->text();
std::string decisionID = ui->lineEditDecisions->text().toStdString();
decisionID += ":";
decisionID += ui->comboBoxFunctions->currentText().toStdString();
QString decisions = ui->lineEditDecisions->text();

if (decisions.contains(", ")) {
QStringList decisionList = decisions.split(",");
QString combined = "";
for (int i = 0; i < decisionList.size(); i++) {
QString hex = decisionList.at(i);
QString function = ui->comboBoxFunctions->currentText();
QString formatted = hex + ":" + function;

combined.push_back(formatted);
if (i != decisionList.size() - 1) {
combined.push_back(",");
}
}
decisions = combined;
}

double B = ui->doubleSpinBoxB->value();
double tradingFee = ui->doubleSpinBoxTradeFee->value();
double maxCommission = ui->doubleSpinBoxMaxCommission->value();
Expand All @@ -54,7 +69,7 @@ json_spirit::Array DecisionMarketCreationWidget::createDecisionMarketArray()
error = true;
}

if (decisionID.size() == 0) {
if (decisions.size() == 0) {
emit inputError("You must enter a decision ID!");
error = true;
}
Expand Down Expand Up @@ -106,7 +121,7 @@ json_spirit::Array DecisionMarketCreationWidget::createDecisionMarketArray()
if (error) return params;

params.push_back(address.toStdString());
params.push_back(decisionID);
params.push_back(decisions.toStdString());
params.push_back(B);
params.push_back(tradingFee);
params.push_back(maxCommission);
Expand Down Expand Up @@ -165,6 +180,9 @@ void DecisionMarketCreationWidget::on_pushButtonSelectDecision_clicked()
connect(decisionSelection, SIGNAL(decisionSelected(QString)),
this, SLOT(decisionSelected(QString)));

connect(decisionSelection, SIGNAL(multipleDecisionsSelected(QStringList)),
this, SLOT(multipleDecisionsSelected(QStringList)));

// Display the decision selection widget
QHBoxLayout *hbox = new QHBoxLayout(this);
hbox->addWidget(decisionSelection);
Expand Down Expand Up @@ -271,3 +289,17 @@ void DecisionMarketCreationWidget::decisionSelected(QString decisionHex)
{
ui->lineEditDecisions->setText(decisionHex);
}

void DecisionMarketCreationWidget::multipleDecisionsSelected(QStringList hexList)
{
// Comma seperated list of hex's
QString csList = "";

for (int i = 0; i < hexList.size(); i++) {
csList.push_back(hexList.at(i));
if (i != hexList.size() - 1) {
csList.push_back(",");
}
}
ui->lineEditDecisions->setText(csList);
}
3 changes: 3 additions & 0 deletions src/qt/decisionmarketcreationwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "decisionselectionview.h"

#include <QWidget>
#include <QStringList>

namespace Ui {
class DecisionMarketCreationWidget;
Expand Down Expand Up @@ -38,6 +39,8 @@ public slots:

void decisionSelected(QString decisionHex);

void multipleDecisionsSelected(QStringList hexList);

signals:
/** Signal raised when json_spirit::Array for new Decision Market is created */
void newDecisionMarketArray(const json_spirit::Array array);
Expand Down
20 changes: 19 additions & 1 deletion src/qt/decisionselectionview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "decisionselectionview.h"
#include "decisionselectionview.h"
#include "ui_decisionselectionview.h"

#include <QItemSelectionModel>
#include <QModelIndexList>

#include <iostream>

DecisionSelectionView::DecisionSelectionView(QWidget *parent) :
QWidget(parent),
ui(new Ui::DecisionSelectionView)
Expand All @@ -13,6 +18,7 @@ DecisionSelectionView::DecisionSelectionView(QWidget *parent) :
decisionSelectionTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
decisionSelectionModel = new DecisionSelectionModel(this);
decisionSelectionTable->setModel(decisionSelectionModel);
decisionSelectionTable->setSelectionBehavior(QAbstractItemView::SelectRows);

ui->frame->layout()->addWidget(decisionSelectionTable);

Expand Down Expand Up @@ -40,5 +46,17 @@ void DecisionSelectionView::on_table_doubleClicked(QModelIndex index)

void DecisionSelectionView::on_pushButtonDone_clicked()
{
QItemSelectionModel *selection = decisionSelectionTable->selectionModel();
QStringList hexList;

if (selection->hasSelection()) {
QModelIndexList list = selection->selectedRows();

for (int i = 0; i < list.size(); i++) {
QString hex = decisionSelectionTable->model()->data(decisionSelectionTable->model()->index(i, 1)).toString();
hexList.push_back(hex);
}
}
emit multipleDecisionsSelected(hexList);
emit done();
}
2 changes: 2 additions & 0 deletions src/qt/decisionselectionview.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QTableView>
#include <QWidget>
#include <QStringList>

namespace Ui {
class DecisionSelectionView;
Expand All @@ -24,6 +25,7 @@ public slots:

signals:
void decisionSelected(QString decisionHex);
void multipleDecisionsSelected(QStringList hexList);
void done();

private slots:
Expand Down
Loading

0 comments on commit f82c96e

Please sign in to comment.