Skip to content

Commit

Permalink
[Trivial] Styling: spaces and brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Mar 9, 2020
1 parent 5a600ba commit d56a8f8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 78 deletions.
89 changes: 55 additions & 34 deletions src/qt/pivx/masternodeswidget.cpp
Expand Up @@ -37,14 +37,16 @@ class MNHolder : public FurListRow<QWidget*>
public:
MNHolder();

explicit MNHolder(bool _isLightTheme) : FurListRow(), isLightTheme(_isLightTheme){}
explicit MNHolder(bool _isLightTheme) : FurListRow(), isLightTheme(_isLightTheme) {}

MNRow* createHolder(int pos) override{
if(!cachedRow) cachedRow = new MNRow();
MNRow* createHolder(int pos) override
{
if (!cachedRow) cachedRow = new MNRow();
return cachedRow;
}

void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override{
void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override
{
MNRow* row = static_cast<MNRow*>(holder);
QString label = index.data(Qt::DisplayRole).toString();
QString address = index.sibling(index.row(), MNModel::ADDRESS).data(Qt::DisplayRole).toString();
Expand All @@ -53,7 +55,8 @@ class MNHolder : public FurListRow<QWidget*>
row->updateView("Address: " + address, label, status, wasCollateralAccepted);
}

QColor rectColor(bool isHovered, bool isSelected) override{
QColor rectColor(bool isHovered, bool isSelected) override
{
return getRowColor(isLightTheme, isHovered, isSelected);
}

Expand Down Expand Up @@ -133,41 +136,46 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
connect(ui->btnAboutController, &OptionButton::clicked, [this](){window->openFAQ(10);});
}

void MasterNodesWidget::showEvent(QShowEvent *event){
void MasterNodesWidget::showEvent(QShowEvent *event)
{
if (mnModel) mnModel->updateMNList();
if(!timer) {
if (!timer) {
timer = new QTimer(this);
connect(timer, &QTimer::timeout, [this]() {mnModel->updateMNList();});
}
timer->start(30000);
}

void MasterNodesWidget::hideEvent(QHideEvent *event){
if(timer) timer->stop();
void MasterNodesWidget::hideEvent(QHideEvent *event)
{
if (timer) timer->stop();
}

void MasterNodesWidget::loadWalletModel(){
if(walletModel) {
void MasterNodesWidget::loadWalletModel()
{
if (walletModel) {
ui->listMn->setModel(mnModel);
ui->listMn->setModelColumn(AddressTableModel::Label);
updateListState();
}
}

void MasterNodesWidget::updateListState() {
void MasterNodesWidget::updateListState()
{
bool show = mnModel->rowCount() > 0;
ui->listMn->setVisible(show);
ui->emptyContainer->setVisible(!show);
ui->pushButtonStartAll->setVisible(show);
}

void MasterNodesWidget::onMNClicked(const QModelIndex &index){
void MasterNodesWidget::onMNClicked(const QModelIndex &index)
{
ui->listMn->setCurrentIndex(index);
QRect rect = ui->listMn->visualRect(index);
QPoint pos = rect.topRight();
pos.setX(pos.x() - (DECORATION_SIZE * 2));
pos.setY(pos.y() + (DECORATION_SIZE * 1.5));
if(!this->menu){
if (!this->menu) {
this->menu = new TooltipMenu(window, this);
this->menu->setEditBtnText(tr("Start"));
this->menu->setDeleteBtnText(tr("Delete"));
Expand All @@ -190,14 +198,16 @@ void MasterNodesWidget::onMNClicked(const QModelIndex &index){
ui->listMn->setFocus();
}

bool MasterNodesWidget::checkMNsNetwork() {
bool MasterNodesWidget::checkMNsNetwork()
{
bool isTierTwoSync = mnModel->isMNsNetworkSynced();
if (!isTierTwoSync) inform(tr("Please wait until the node is fully synced"));
return isTierTwoSync;
}

void MasterNodesWidget::onEditMNClicked(){
if(walletModel) {
void MasterNodesWidget::onEditMNClicked()
{
if (walletModel) {
if (!checkMNsNetwork()) return;
if (index.sibling(index.row(), MNModel::WAS_COLLATERAL_ACCEPTED).data(Qt::DisplayRole).toBool()) {
// Start MN
Expand All @@ -212,7 +222,8 @@ void MasterNodesWidget::onEditMNClicked(){
}
}

void MasterNodesWidget::startAlias(QString strAlias) {
void MasterNodesWidget::startAlias(QString strAlias)
{
QString strStatusHtml;
strStatusHtml += "Alias: " + strAlias + " ";

Expand All @@ -227,12 +238,14 @@ void MasterNodesWidget::startAlias(QString strAlias) {
updateModelAndInform(strStatusHtml);
}

void MasterNodesWidget::updateModelAndInform(QString informText) {
void MasterNodesWidget::updateModelAndInform(QString informText)
{
mnModel->updateMNList();
inform(informText);
}

bool MasterNodesWidget::startMN(CMasternodeConfig::CMasternodeEntry mne, std::string& strError) {
bool MasterNodesWidget::startMN(CMasternodeConfig::CMasternodeEntry mne, std::string& strError)
{
CMasternodeBroadcast mnb;
if (!CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb))
return false;
Expand All @@ -242,7 +255,8 @@ bool MasterNodesWidget::startMN(CMasternodeConfig::CMasternodeEntry mne, std::st
return true;
}

void MasterNodesWidget::onStartAllClicked(int type) {
void MasterNodesWidget::onStartAllClicked(int type)
{
if (!verifyWalletUnlocked()) return;
if (!checkMNsNetwork()) return;
if (isLoading) {
Expand All @@ -256,7 +270,8 @@ void MasterNodesWidget::onStartAllClicked(int type) {
}
}

bool MasterNodesWidget::startAll(QString& failText, bool onlyMissing) {
bool MasterNodesWidget::startAll(QString& failText, bool onlyMissing)
{
int amountOfMnFailed = 0;
int amountOfMnStarted = 0;
for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) {
Expand All @@ -282,7 +297,8 @@ bool MasterNodesWidget::startAll(QString& failText, bool onlyMissing) {
return true;
}

void MasterNodesWidget::run(int type) {
void MasterNodesWidget::run(int type)
{
bool isStartMissing = type == REQUEST_START_MISSING;
if (type == REQUEST_START_ALL || isStartMissing) {
QString failText;
Expand All @@ -294,15 +310,17 @@ void MasterNodesWidget::run(int type) {
isLoading = false;
}

void MasterNodesWidget::onError(QString error, int type) {
void MasterNodesWidget::onError(QString error, int type)
{
if (type == REQUEST_START_ALL) {
QMetaObject::invokeMethod(this, "inform", Qt::QueuedConnection,
Q_ARG(QString, "Error starting all Masternodes"));
}
}

void MasterNodesWidget::onInfoMNClicked() {
if(!verifyWalletUnlocked()) return;
void MasterNodesWidget::onInfoMNClicked()
{
if (!verifyWalletUnlocked()) return;
showHideOp(true);
MnInfoDialog* dialog = new MnInfoDialog(window);
QString label = index.data(Qt::DisplayRole).toString();
Expand All @@ -314,7 +332,7 @@ void MasterNodesWidget::onInfoMNClicked() {
dialog->setData(pubKey, label, address, txId, outIndex, status);
dialog->adjustSize();
showDialog(dialog, 3, 17);
if (dialog->exportMN){
if (dialog->exportMN) {
if (ask(tr("Remote Masternode Data"),
tr("You are just about to export the required data to run a Masternode\non a remote server to your clipboard.\n\n\n"
"You will only have to paste the data in the pivx.conf file\nof your remote server and start it, "
Expand All @@ -333,7 +351,8 @@ void MasterNodesWidget::onInfoMNClicked() {
dialog->deleteLater();
}

void MasterNodesWidget::onDeleteMNClicked(){
void MasterNodesWidget::onDeleteMNClicked()
{
QString qAliasString = index.data(Qt::DisplayRole).toString();
std::string aliasToRemove = qAliasString.toStdString();

Expand All @@ -342,7 +361,7 @@ void MasterNodesWidget::onDeleteMNClicked(){

std::string strConfFile = "masternode.conf";
std::string strDataDir = GetDataDir().string();
if (strConfFile != boost::filesystem::basename(strConfFile) + boost::filesystem::extension(strConfFile)){
if (strConfFile != boost::filesystem::basename(strConfFile) + boost::filesystem::extension(strConfFile)) {
throw std::runtime_error(strprintf(_("masternode.conf %s resides outside data directory %s"), strConfFile, strDataDir));
}

Expand Down Expand Up @@ -425,15 +444,16 @@ void MasterNodesWidget::onDeleteMNClicked(){
}
}

void MasterNodesWidget::onCreateMNClicked(){
if(verifyWalletUnlocked()) {
if(walletModel->getBalance() <= (COIN * 10000)){
void MasterNodesWidget::onCreateMNClicked()
{
if (verifyWalletUnlocked()) {
if (walletModel->getBalance() <= (COIN * 10000)) {
inform(tr("Not enough balance to create a masternode, 10,000 PIV required."));
return;
}
showHideOp(true);
MasterNodeWizardDialog *dialog = new MasterNodeWizardDialog(walletModel, window);
if(openDialogWithOpaqueBackgroundY(dialog, window, 5, 7)) {
if (openDialogWithOpaqueBackgroundY(dialog, window, 5, 7)) {
if (dialog->isOk) {
// Update list
mnModel->addMn(dialog->mnEntry);
Expand All @@ -448,7 +468,8 @@ void MasterNodesWidget::onCreateMNClicked(){
}
}

void MasterNodesWidget::changeTheme(bool isLightTheme, QString& theme){
void MasterNodesWidget::changeTheme(bool isLightTheme, QString& theme)
{
static_cast<MNHolder*>(this->delegate->getRowFactory())->isLightTheme = isLightTheme;
}

Expand Down
35 changes: 20 additions & 15 deletions src/qt/pivx/masternodewizarddialog.cpp
Expand Up @@ -12,7 +12,6 @@
#include <QFile>
#include <QIntValidator>
#include <QHostAddress>
#include <QRegExpValidator>

MasterNodeWizardDialog::MasterNodeWizardDialog(WalletModel *model, QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -64,7 +63,7 @@ MasterNodeWizardDialog::MasterNodeWizardDialog(WalletModel *model, QWidget *pare
initCssEditLine(ui->lineEditPort);
ui->stackedWidget->setCurrentIndex(pos);
ui->lineEditPort->setValidator(new QIntValidator(0, 9999999, ui->lineEditPort));
if(walletModel->isTestNetwork()){
if (walletModel->isTestNetwork()) {
ui->lineEditPort->setEnabled(false);
ui->lineEditPort->setText("51474");
} else {
Expand Down Expand Up @@ -96,8 +95,9 @@ void MasterNodeWizardDialog::showEvent(QShowEvent *event)
if (ui->btnNext) ui->btnNext->setFocus();
}

void MasterNodeWizardDialog::onNextClicked(){
switch(pos){
void MasterNodeWizardDialog::onNextClicked()
{
switch(pos) {
case 0:{
ui->stackedWidget->setCurrentIndex(1);
ui->pushName4->setChecked(false);
Expand Down Expand Up @@ -145,7 +145,8 @@ void MasterNodeWizardDialog::onNextClicked(){
pos++;
}

bool MasterNodeWizardDialog::createMN(){
bool MasterNodeWizardDialog::createMN()
{
if (walletModel) {
/**
*
Expand Down Expand Up @@ -178,7 +179,7 @@ bool MasterNodeWizardDialog::createMN(){
}
// TODO: Validate IP address..
int portInt = portStr.toInt();
if (portInt <= 0 && portInt > 999999){
if (portInt <= 0 && portInt > 999999) {
returnStr = tr("Invalid port number");
return false;
}
Expand Down Expand Up @@ -238,7 +239,7 @@ bool MasterNodeWizardDialog::createMN(){
// now change the conf
std::string strConfFile = "masternode.conf";
std::string strDataDir = GetDataDir().string();
if (strConfFile != boost::filesystem::basename(strConfFile) + boost::filesystem::extension(strConfFile)){
if (strConfFile != boost::filesystem::basename(strConfFile) + boost::filesystem::extension(strConfFile)) {
throw std::runtime_error(strprintf(_("masternode.conf %s resides outside data directory %s"), strConfFile, strDataDir));
}

Expand Down Expand Up @@ -291,9 +292,9 @@ bool MasterNodeWizardDialog::createMN(){
CWalletTx* walletTx = currentTransaction.getTransaction();
std::string txID = walletTx->GetHash().GetHex();
int indexOut = -1;
for (int i=0; i < (int)walletTx->vout.size(); i++){
for (int i=0; i < (int)walletTx->vout.size(); i++) {
CTxOut& out = walletTx->vout[i];
if (out.nValue == 10000 * COIN){
if (out.nValue == 10000 * COIN) {
indexOut = i;
}
}
Expand Down Expand Up @@ -342,10 +343,11 @@ bool MasterNodeWizardDialog::createMN(){
return false;
}

void MasterNodeWizardDialog::onBackClicked(){
void MasterNodeWizardDialog::onBackClicked()
{
if (pos == 0) return;
pos--;
switch(pos){
switch(pos) {
case 0:{
ui->stackedWidget->setCurrentIndex(0);
ui->btnNext->setFocus();
Expand Down Expand Up @@ -373,7 +375,8 @@ void MasterNodeWizardDialog::onBackClicked(){
}
}

void MasterNodeWizardDialog::inform(QString text){
void MasterNodeWizardDialog::inform(QString text)
{
if (!snackBar)
snackBar = new SnackBar(nullptr, this);
snackBar->setText(text);
Expand All @@ -382,7 +385,8 @@ void MasterNodeWizardDialog::inform(QString text){
}

QSize BUTTON_SIZE = QSize(22, 22);
void MasterNodeWizardDialog::initBtn(std::initializer_list<QPushButton*> args){
void MasterNodeWizardDialog::initBtn(std::initializer_list<QPushButton*> args)
{
for (QPushButton* btn : args) {
btn->setMinimumSize(BUTTON_SIZE);
btn->setMaximumSize(BUTTON_SIZE);
Expand All @@ -393,7 +397,8 @@ void MasterNodeWizardDialog::initBtn(std::initializer_list<QPushButton*> args){
}
}

MasterNodeWizardDialog::~MasterNodeWizardDialog(){
if(snackBar) delete snackBar;
MasterNodeWizardDialog::~MasterNodeWizardDialog()
{
if (snackBar) delete snackBar;
delete ui;
}

0 comments on commit d56a8f8

Please sign in to comment.