From 0d742a641a56c6ad206c43585037238288bfc08a Mon Sep 17 00:00:00 2001 From: zathras-crypto Date: Wed, 8 Apr 2015 20:14:18 -0700 Subject: [PATCH] metadexdialog.cpp : clean up FullRefresh() and optimize address population --- src/qt/metadexdialog.cpp | 111 ++++++++------------------------------- 1 file changed, 23 insertions(+), 88 deletions(-) diff --git a/src/qt/metadexdialog.cpp b/src/qt/metadexdialog.cpp index d364f390cad5e..24df8011a6250 100755 --- a/src/qt/metadexdialog.cpp +++ b/src/qt/metadexdialog.cpp @@ -80,41 +80,10 @@ MetaDExDialog::MetaDExDialog(QWidget *parent) : //open global_metadex_market = 3; - //hide pending -// ui->pendingLabel->setVisible(false); //prep lists ui->buyList->setColumnCount(3); ui->sellList->setColumnCount(3); -// ui->openOrders->setColumnCount(5); - - //dummy orders -// const int currentRow = ui->openOrders->rowCount(); -// ui->openOrders->setRowCount(currentRow + 1); -// ui->openOrders->setItem(currentRow, 0, new QTableWidgetItem("1FakeBitcoinAddressDoNotSend")); -// ui->openOrders->setItem(currentRow, 1, new QTableWidgetItem("Sell")); -// ui->openOrders->setItem(currentRow, 2, new QTableWidgetItem("0.00004565")); -// ui->openOrders->setItem(currentRow, 3, new QTableWidgetItem("345.45643222")); -// ui->openOrders->setItem(currentRow, 4, new QTableWidgetItem("0.015770081")); - -// ui->openOrders->setHorizontalHeaderItem(0, new QTableWidgetItem("Address")); -// ui->openOrders->setHorizontalHeaderItem(1, new QTableWidgetItem("Type")); -// ui->openOrders->setHorizontalHeaderItem(2, new QTableWidgetItem("Unit Price")); -// ui->openOrders->verticalHeader()->setVisible(false); - #if QT_VERSION < 0x050000 -// ui->openOrders->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - #else -// ui->openOrders->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - #endif -// ui->openOrders->horizontalHeader()->resizeSection(1, 60); -// ui->openOrders->horizontalHeader()->resizeSection(2, 140); -// ui->openOrders->horizontalHeader()->resizeSection(3, 140); -// ui->openOrders->horizontalHeader()->resizeSection(4, 140); -// ui->openOrders->setShowGrid(false); -// ui->openOrders->setSelectionBehavior(QAbstractItemView::SelectRows); - ui->buyList->setHorizontalHeaderItem(0, new QTableWidgetItem("Unit Price")); - ui->buyList->setHorizontalHeaderItem(1, new QTableWidgetItem("Total SP#3")); - ui->buyList->setHorizontalHeaderItem(2, new QTableWidgetItem("Total MSC")); ui->buyList->verticalHeader()->setVisible(false); ui->buyList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui->buyList->setShowGrid(false); @@ -122,10 +91,7 @@ MetaDExDialog::MetaDExDialog(QWidget *parent) : ui->buyList->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->buyList->setSelectionMode(QAbstractItemView::SingleSelection); ui->buyList->setAlternatingRowColors(true); - ui->sellList->setHorizontalHeaderItem(0, new QTableWidgetItem("Unit Price")); - ui->sellList->setHorizontalHeaderItem(1, new QTableWidgetItem("Total SP#3")); - ui->sellList->setHorizontalHeaderItem(2, new QTableWidgetItem("Total MSC")); ui->sellList->verticalHeader()->setVisible(false); ui->sellList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui->sellList->setShowGrid(false); @@ -395,19 +361,18 @@ void MetaDExDialog::UpdateBuyAddress() void MetaDExDialog::FullRefresh() { - // populate from address selector + // populate market information unsigned int propertyId = global_metadex_market; string propNameStr = getPropertyName(propertyId); bool testeco = false; if (propertyId >= TEST_ECO_PROPERTY_1) testeco = true; - if(testeco) - { + if(testeco) { ui->marketLabel->setText(QString::fromStdString("Trade " + propNameStr + " (#" + FormatIndivisibleMP(propertyId) + ") for Test Mastercoin")); - } - else - { + } else { ui->marketLabel->setText(QString::fromStdString("Trade " + propNameStr + " (#" + FormatIndivisibleMP(propertyId) + ") for Mastercoin")); } + + // TODO: take a look at locks, what do we need here? LOCK(cs_tally); // get currently selected addresses @@ -418,32 +383,24 @@ void MetaDExDialog::FullRefresh() ui->buyAddressCombo->clear(); ui->sellAddressCombo->clear(); - // update form labels - if (testeco) - { + // update form labels to reflect market + if (testeco) { ui->exchangeLabel->setText("Exchange - SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId)) + "/TMSC"); ui->buyList->setHorizontalHeaderItem(2, new QTableWidgetItem("TMSC")); ui->sellList->setHorizontalHeaderItem(2, new QTableWidgetItem("TMSC")); ui->buyTotalLabel->setText("0.00000000 TMSC"); ui->sellTotalLabel->setText("0.00000000 TMSC"); -// ui->openOrders->setHorizontalHeaderItem(3, new QTableWidgetItem("SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId)))); -// ui->openOrders->setHorizontalHeaderItem(4, new QTableWidgetItem("TMSC")); ui->sellTM->setText("TMSC"); ui->buyTM->setText("TMSC"); - } - else - { + } else { ui->exchangeLabel->setText("Exchange - SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId)) + "/MSC"); ui->buyList->setHorizontalHeaderItem(2, new QTableWidgetItem("MSC")); ui->sellList->setHorizontalHeaderItem(2, new QTableWidgetItem("MSC")); ui->buyTotalLabel->setText("0.00000000 MSC"); ui->sellTotalLabel->setText("0.00000000 MSC"); -// ui->openOrders->setHorizontalHeaderItem(3, new QTableWidgetItem("SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId)))); -// ui->openOrders->setHorizontalHeaderItem(4, new QTableWidgetItem("MSC")); ui->sellTM->setText("MSC"); ui->buyTM->setText("MSC"); } - ui->buyMarketLabel->setText("BUY SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId))); ui->sellMarketLabel->setText("SELL SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId))); ui->buyList->setHorizontalHeaderItem(1, new QTableWidgetItem("SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId)))); @@ -451,56 +408,34 @@ void MetaDExDialog::FullRefresh() ui->sellButton->setText("Sell SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId))); ui->buyButton->setText("Buy SP#" + QString::fromStdString(FormatIndivisibleMP(propertyId))); - // sell addresses - for(map::iterator my_it = mp_tally_map.begin(); my_it != mp_tally_map.end(); ++my_it) - { + // populate buy and sell addresses + for(map::iterator my_it = mp_tally_map.begin(); my_it != mp_tally_map.end(); ++my_it) { string address = (my_it->first).c_str(); unsigned int id; - bool includeAddress=false; (my_it->second).init(); - while (0 != (id = (my_it->second).next())) - { - if(id==propertyId) { includeAddress=true; break; } - } - if (!includeAddress) continue; //ignore this address, has never transacted in this propertyId - if (!IsMyAddress(address)) continue; //ignore this address, it's not ours - ui->sellAddressCombo->addItem((my_it->first).c_str()); - } - // buy addresses - for(map::iterator my_it = mp_tally_map.begin(); my_it != mp_tally_map.end(); ++my_it) - { - string address = (my_it->first).c_str(); - unsigned int id; - bool includeAddress=false; - (my_it->second).init(); - while (0 != (id = (my_it->second).next())) - { - if((id==OMNI_PROPERTY_MSC) && (!testeco)) { includeAddress=true; break; } - if((id==OMNI_PROPERTY_TMSC) && (testeco)) { includeAddress=true; break; } + while (0 != (id = (my_it->second).next())) { + if(id==propertyId) { + if (IsMyAddress(address)) ui->sellAddressCombo->addItem((my_it->first).c_str()); // only include wallet addresses + } + if (((id==OMNI_PROPERTY_MSC) && (!testeco)) || ((id==OMNI_PROPERTY_TMSC) && (testeco))) { + if (IsMyAddress(address)) ui->buyAddressCombo->addItem((my_it->first).c_str()); + } } - if (!includeAddress) continue; //ignore this address, has never transacted in this propertyId - if (!IsMyAddress(address)) continue; //ignore this address, it's not ours - ui->buyAddressCombo->addItem((my_it->first).c_str()); } - // attempt to set buy and sell addresses back to values before refresh + // attempt to set buy and sell addresses back to values before refresh - may not be possible if it's a new market int sellIdx = ui->sellAddressCombo->findText(currentSetSellAddress); if (sellIdx != -1) { ui->sellAddressCombo->setCurrentIndex(sellIdx); } // -1 means the new prop doesn't have the previously selected address int buyIdx = ui->buyAddressCombo->findText(currentSetBuyAddress); - if (buyIdx != -1) { ui->buyAddressCombo->setCurrentIndex(buyIdx); } // -1 means the new prop doesn't have the previously selected address - // update the balances + if (buyIdx != -1) { ui->buyAddressCombo->setCurrentIndex(buyIdx); } + + // update the balances for the buy and sell addreses UpdateSellAddress(); UpdateBuyAddress(); + + // update the buy and sell offers UpdateBuyOffers(); UpdateSellOffers(); - // silly sizing -// QRect rect = ui->openOrders->geometry(); -// int tableHeight = 2 + ui->openOrders->horizontalHeader()->height(); -// for(int i = 0; i < ui->openOrders->rowCount(); i++){ -// tableHeight += ui->openOrders->rowHeight(i); -// } -// rect.setHeight(tableHeight); -// ui->openOrders->setGeometry(rect); } void MetaDExDialog::buyAddressComboBoxChanged(int idx)