forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
omnicore_qtutils : move StripTrailingZeros() & add PopulateSimpleDial…
…og()
- Loading branch information
1 parent
b14074f
commit 0346243
Showing
5 changed files
with
92 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "omnicore_qtutils.h" | ||
#include "guiutil.h" | ||
|
||
#include <string> | ||
#include <QDialog> | ||
#include <QVBoxLayout> | ||
#include <QTextEdit> | ||
#include <QDialogButtonBox> | ||
#include <QPushButton> | ||
#include <QObject> | ||
#include <QWidget> | ||
|
||
namespace mastercore | ||
{ | ||
|
||
/** | ||
* Sets up a simple dialog layout that can be used to provide selectable text to the user | ||
* | ||
* Note: used in place of standard dialogs in cases where text selection & copy to clipboard functions are useful | ||
*/ | ||
void PopulateSimpleDialog(const std::string& content, const std::string& title, const std::string& tooltip) | ||
{ | ||
QDialog *simpleDlg = new QDialog; | ||
QLayout *dlgLayout = new QVBoxLayout; | ||
dlgLayout->setSpacing(12); | ||
dlgLayout->setMargin(12); | ||
QTextEdit *dlgTextEdit = new QTextEdit; | ||
dlgTextEdit->setText(QString::fromStdString(content)); | ||
dlgTextEdit->setStatusTip(QString::fromStdString(tooltip)); | ||
dlgTextEdit->setReadOnly(true); | ||
dlgTextEdit->setTextInteractionFlags(dlgTextEdit->textInteractionFlags() | Qt::TextSelectableByKeyboard); | ||
dlgLayout->addWidget(dlgTextEdit); | ||
QPushButton *closeButton = new QPushButton(QObject::tr("&Close")); | ||
closeButton->setDefault(true); | ||
QDialogButtonBox *buttonBox = new QDialogButtonBox; | ||
buttonBox->addButton(closeButton, QDialogButtonBox::AcceptRole); | ||
dlgLayout->addWidget(buttonBox); | ||
QObject::connect(buttonBox, SIGNAL(accepted()), simpleDlg, SLOT(accept())); | ||
simpleDlg->setAttribute(Qt::WA_DeleteOnClose); | ||
simpleDlg->setWindowTitle(QString::fromStdString(title)); | ||
simpleDlg->setLayout(dlgLayout); | ||
simpleDlg->resize(700, 360); | ||
if (simpleDlg->exec() == QDialog::Accepted) { } //do nothing but close | ||
} | ||
|
||
/** | ||
* Strips trailing zeros from a string containing a divisible value | ||
*/ | ||
std::string StripTrailingZeros(const std::string& inputStr) | ||
{ | ||
size_t dot = inputStr.find("."); | ||
std::string outputStr = inputStr; // make a copy we will manipulate and return | ||
if (dot==std::string::npos) { // could not find a decimal marker, unsafe - return original input string | ||
return inputStr; | ||
} | ||
size_t lastZero = outputStr.find_last_not_of('0') + 1; | ||
if (lastZero > dot) { // trailing zeros are after decimal marker, safe to remove | ||
outputStr.erase ( lastZero, std::string::npos ); | ||
if (outputStr.length() > 0) { std::string::iterator it = outputStr.end() - 1; if (*it == '.') { outputStr.erase(it); } } //get rid of trailing dot if needed | ||
} else { // last non-zero is before the decimal marker, this is a whole number | ||
outputStr.erase ( dot, std::string::npos ); | ||
} | ||
return outputStr; | ||
} | ||
|
||
} // end namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef OMNICORE_QTUTILS | ||
#define OMNICORE_QTUTILS | ||
|
||
#include <QDialog> | ||
#include <string> | ||
|
||
namespace mastercore | ||
{ | ||
/** | ||
* Sets up a simple dialog layout that can be used to provide selectable text to the user | ||
*/ | ||
void PopulateSimpleDialog(const std::string& content, const std::string& title, const std::string& tooltip); | ||
|
||
/** | ||
* Strips trailing zeros from a string containing a divisible value | ||
*/ | ||
std::string StripTrailingZeros(const std::string& inputStr); | ||
} | ||
|
||
#endif // OMNICORE_QTUTILS |