Skip to content

Commit

Permalink
Implementation of SideStakeTableModel and sidestakeTableView in optio…
Browse files Browse the repository at this point in the history
…ns (part 2).
  • Loading branch information
jamescowens committed Oct 6, 2023
1 parent e77d104 commit 1d89b71
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
37 changes: 36 additions & 1 deletion src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,42 @@
</widget>
</item>
<item>
<widget class="QTableView" name="sidestakingTableView"/>
<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>
Expand Down
34 changes: 32 additions & 2 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ void OptionsDialog::setModel(OptionsModel *model)
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 @@ -214,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 @@ -260,11 +263,21 @@ void OptionsDialog::on_applyButton_clicked()
{
mapper->submit();

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

disableApplyButton();
}

void OptionsDialog::newSideStakeButton_clicked()
{

}

void OptionsDialog::editSideStakeButton_clicked()
{

}

void OptionsDialog::showRestartWarning_Proxy()
{
if(!fRestartWarningDisplayed_Proxy)
Expand Down Expand Up @@ -334,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 @@ -391,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
6 changes: 6 additions & 0 deletions src/qt/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ private slots:
void on_cancelButton_clicked();
void on_applyButton_clicked();

void newSideStakeButton_clicked();
void editSideStakeButton_clicked();

void showRestartWarning_Proxy();
void showRestartWarning_Lang();
void updateDisplayUnit();
void updateStyle();
void hideStartMinimized();
void hideLimitTxnDisplayDate();
void hideStakeSplitting();
void hideSideStakeEdit();
void handleProxyIpValid(QValidatedLineEdit *object, bool fState);
void handleStakingEfficiencyValid(QValidatedLineEdit *object, bool fState);
void handleMinStakeSplitValueValid(QValidatedLineEdit *object, bool fState);

void refreshSideStakeTableModel();

signals:
void proxyIpValid(QValidatedLineEdit *object, bool fValid);
void stakingEfficiencyValid(QValidatedLineEdit *object, bool fValid);
Expand Down
4 changes: 2 additions & 2 deletions src/qt/sidestaketablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool SideStakeLessThan::operator()(const GRC::SideStake& left, const GRC::SideSt

switch (static_cast<SideStakeTableModel::ColumnIndex>(m_column)) {
case SideStakeTableModel::Address:
return pLeft->m_key.ToString().compare(pRight->m_key.ToString()) < 0;
return pLeft->m_key < pRight->m_key;
case SideStakeTableModel::Allocation:
return pLeft->m_allocation < pRight->m_allocation;
case SideStakeTableModel::Description:
Expand Down Expand Up @@ -56,7 +56,7 @@ class SideStakeTablePriv
m_cached_sidestakes.append(*entry);
}

if (m_sort_column > 0) {
if (m_sort_column >= 0) {
std::stable_sort(m_cached_sidestakes.begin(), m_cached_sidestakes.end(), SideStakeLessThan(m_sort_column, m_sort_order));
}
}
Expand Down

0 comments on commit 1d89b71

Please sign in to comment.