Skip to content

Commit

Permalink
Implementation of SideStakeTableModel and sidestakeTableView in options
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Oct 6, 2023
1 parent 89f9a90 commit 392b2fd
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ QT_MOC_CPP = \
qt/moc_rpcconsole.cpp \
qt/moc_sendcoinsdialog.cpp \
qt/moc_sendcoinsentry.cpp \
qt/moc_sidestaketablemodel.cpp \
qt/moc_signverifymessagedialog.cpp \
qt/moc_trafficgraphwidget.cpp \
qt/moc_transactiondesc.cpp \
Expand Down
20 changes: 16 additions & 4 deletions src/gridcoin/sidestake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,21 @@ SideStakePayload::SideStakePayload(SideStake entry)
// -----------------------------------------------------------------------------
// Class: SideStakeRegistry
// -----------------------------------------------------------------------------
const SideStakeRegistry::SideStakeMap& SideStakeRegistry::SideStakeEntries() const
const std::vector<SideStake_ptr> SideStakeRegistry::SideStakeEntries() const
{
return m_sidestake_entries;
std::vector<SideStake_ptr> sidestakes;

LOCK(cs_lock);

for (const auto& entry : m_sidestake_entries) {
sidestakes.push_back(entry.second);
}

for (const auto& entry : m_local_sidestake_entries) {
sidestakes.push_back(entry.second);
}

return sidestakes;
}

const std::vector<SideStake_ptr> SideStakeRegistry::ActiveSideStakeEntries()
Expand Down Expand Up @@ -586,8 +598,8 @@ void SideStakeRegistry::LoadLocalSideStakesFromConfig()

// First, determine allocation already taken by mandatory sidestakes, because they must be allocated first.
for (const auto& entry : SideStakeEntries()) {
if (entry.second->m_status == SideStakeStatus::MANDATORY) {
dSumAllocation += entry.second->m_allocation;
if (entry->m_status == SideStakeStatus::MANDATORY) {
dSumAllocation += entry->m_allocation;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/sidestake.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class SideStakeRegistry : public IContractHandler
//!
//! \return \c A reference to the current sidestake entries stored in the registry.
//!
const SideStakeMap& SideStakeEntries() const;
const std::vector<SideStake_ptr> SideStakeEntries() const;

//!
//! \brief Get the collection of active sidestake entries. This is presented as a vector of
Expand Down
2 changes: 2 additions & 0 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_library(gridcoinqt STATIC
rpcconsole.cpp
sendcoinsdialog.cpp
sendcoinsentry.cpp
sidestaketablemodel.cpp
signverifymessagedialog.cpp
trafficgraphwidget.cpp
transactiondesc.cpp
Expand Down Expand Up @@ -122,6 +123,7 @@ set_source_files_properties(
mrcmodel.cpp
qtipcserver.cpp
researcher/researchermodel.cpp
sidestaketablemodel.cpp
transactiondesc.cpp
transactiontablemodel.cpp
voting/votingmodel.cpp
Expand Down
209 changes: 119 additions & 90 deletions src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::North</enum>
Expand Down Expand Up @@ -245,93 +245,122 @@
<attribute name="title">
<string>Staking</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>651</width>
<height>291</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_StakeSplit">
<item>
<widget class="QCheckBox" name="enableStaking">
<property name="toolTip">
<string>This enables or disables staking (the default is enabled). Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
<property name="text">
<string>Enable Staking</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableStakeSplit">
<property name="toolTip">
<string>This enables or disables splitting of stake outputs to optimize staking (default disabled). Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
<property name="text">
<string>Enable Stake Splitting</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_StakeSplit">
<item>
<widget class="QLabel" name="stakingEfficiencyLabel">
<property name="text">
<string>Target Efficiency</string>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="stakingEfficiency">
<property name="toolTip">
<string>Valid values are between 75 and 98 percent. Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="minPostSplitOutputValueLabel">
<property name="text">
<string>Min Post Split UTXO</string>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="minPostSplitOutputValue">
<property name="toolTip">
<string>Valid values are 800 or greater. Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_StakeSplit">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="enableSideStaking">
<property name="text">
<string>Enable Locally Specified Sidestaking</string>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="sidestakingTableWidget"/>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_StakeSplit">
<item>
<widget class="QCheckBox" name="enableStaking">
<property name="toolTip">
<string>This enables or disables staking (the default is enabled). Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
<property name="text">
<string>Enable Staking</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableStakeSplit">
<property name="toolTip">
<string>This enables or disables splitting of stake outputs to optimize staking (default disabled). Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
<property name="text">
<string>Enable Stake Splitting</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_StakeSplit">
<item>
<widget class="QLabel" name="stakingEfficiencyLabel">
<property name="text">
<string>Target Efficiency</string>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="stakingEfficiency">
<property name="toolTip">
<string>Valid values are between 75 and 98 percent. Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="minPostSplitOutputValueLabel">
<property name="text">
<string>Min Post Split UTXO</string>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="minPostSplitOutputValue">
<property name="toolTip">
<string>Valid values are 800 or greater. Note that a change to this setting will permanently override the config file with an entry in the settings file.</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_StakeSplit">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="enableSideStaking">
<property name="text">
<string>Enable Locally Specified Sidestaking</string>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="sidestakingTableView">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayoutSideStake">
<item>
<widget class="QPushButton" name="pushButtonNewSideStake">
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonEditSideStake">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_SideStake">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWindow">
<attribute name="title">
Expand Down Expand Up @@ -513,7 +542,7 @@
</widget>
</widget>
</item>
<item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_Buttons">
<item>
<spacer name="horizontalSpacer_1">
Expand Down
54 changes: 53 additions & 1 deletion src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "qt/decoration.h"
#include "init.h"
#include "miner.h"
#include "sidestaketablemodel.h"

#include <QDir>
#include <QIntValidator>
Expand Down Expand Up @@ -140,6 +141,27 @@ void OptionsDialog::setModel(OptionsModel *model)
mapper->setModel(model);
setMapper();
mapper->toFirst();

SideStakeTableModel* sidestake_model = model->getSideStakeTableModel();

sidestake_model->refresh();

ui->sidestakingTableView->setModel(sidestake_model);
ui->sidestakingTableView->verticalHeader()->hide();
ui->sidestakingTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->sidestakingTableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui->sidestakingTableView->setContextMenuPolicy(Qt::CustomContextMenu);

// Scale column widths by the logical DPI over 96.0 to deal with hires displays.
ui->sidestakingTableView->setColumnWidth(SideStakeTableModel::Address, GRC::ScalePx(this, ADDRESS_COLUMN_WIDTH));
ui->sidestakingTableView->setColumnWidth(SideStakeTableModel::Allocation, GRC::ScalePx(this, ALLOCATION_COLUMN_WIDTH));
ui->sidestakingTableView->setColumnWidth(SideStakeTableModel::Description, GRC::ScalePx(this, DESCRIPTION_COLUMN_WIDTH));
ui->sidestakingTableView->setColumnWidth(SideStakeTableModel::Status, GRC::ScalePx(this, STATUS_COLUMN_WIDTH));
ui->sidestakingTableView->horizontalHeader()->setStretchLastSection(true);
ui->sidestakingTableView->setShowGrid(true);

connect(ui->enableSideStaking, &QCheckBox::toggled, this, &OptionsDialog::hideSideStakeEdit);
connect(ui->enableSideStaking, &QCheckBox::toggled, this, &OptionsDialog::refreshSideStakeTableModel);
}

/* update the display unit, to not use the default ("BTC") */
Expand Down Expand Up @@ -195,7 +217,7 @@ void OptionsDialog::setMapper()
mapper->addMapping(ui->styleComboBox, OptionsModel::WalletStylesheet,"currentData");
mapper->addMapping(ui->limitTxnDisplayCheckBox, OptionsModel::LimitTxnDisplay);
mapper->addMapping(ui->limitTxnDisplayDateEdit, OptionsModel::LimitTxnDate);
mapper->addMapping(ui->displayAddresses, OptionsModel::DisplayAddresses);
mapper->addMapping(ui->displayAddresses, OptionsModel::DisplayAddresses);
}

void OptionsDialog::enableApplyButton()
Expand Down Expand Up @@ -240,9 +262,22 @@ void OptionsDialog::on_cancelButton_clicked()
void OptionsDialog::on_applyButton_clicked()
{
mapper->submit();

refreshSideStakeTableModel();

disableApplyButton();
}

void OptionsDialog::newSideStakeButton_clicked()
{

}

void OptionsDialog::editSideStakeButton_clicked()
{

}

void OptionsDialog::showRestartWarning_Proxy()
{
if(!fRestartWarningDisplayed_Proxy)
Expand Down Expand Up @@ -312,6 +347,16 @@ void OptionsDialog::hideStakeSplitting()
}
}

void OptionsDialog::hideSideStakeEdit()
{
if (model) {
bool local_side_staking_enabled = ui->enableSideStaking->isChecked();

ui->pushButtonNewSideStake->setHidden(!local_side_staking_enabled);
ui->pushButtonEditSideStake->setHidden(!local_side_staking_enabled);
}
}

void OptionsDialog::handleProxyIpValid(QValidatedLineEdit *object, bool fState)
{
// this is used in a check before re-enabling the save buttons
Expand Down Expand Up @@ -369,6 +414,13 @@ void OptionsDialog::handleMinStakeSplitValueValid(QValidatedLineEdit *object, bo
}
}

void OptionsDialog::refreshSideStakeTableModel()
{
mapper->submit();

model->getSideStakeTableModel()->refresh();
}

bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::FocusOut)
Expand Down
Loading

0 comments on commit 392b2fd

Please sign in to comment.