feat: validate maximum memory allocation in wizard

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-11-20 18:16:19 +01:00
parent b57fee1a44
commit 884fe0d574
No known key found for this signature in database
GPG Key ID: C10411294912A422
2 changed files with 42 additions and 9 deletions

View File

@ -71,6 +71,7 @@ void JavaSettingsWidget::setupUi()
m_memoryGroupBox->setObjectName(QStringLiteral("memoryGroupBox"));
m_gridLayout_2 = new QGridLayout(m_memoryGroupBox);
m_gridLayout_2->setObjectName(QStringLiteral("gridLayout_2"));
m_gridLayout_2->setColumnStretch(0, 1);
m_labelMinMem = new QLabel(m_memoryGroupBox);
m_labelMinMem->setObjectName(QStringLiteral("labelMinMem"));
@ -80,7 +81,7 @@ void JavaSettingsWidget::setupUi()
m_minMemSpinBox->setObjectName(QStringLiteral("minMemSpinBox"));
m_minMemSpinBox->setSuffix(QStringLiteral(" MiB"));
m_minMemSpinBox->setMinimum(128);
m_minMemSpinBox->setMaximum(m_availableMemory);
m_minMemSpinBox->setMaximum(1048576);
m_minMemSpinBox->setSingleStep(128);
m_labelMinMem->setBuddy(m_minMemSpinBox);
m_gridLayout_2->addWidget(m_minMemSpinBox, 0, 1, 1, 1);
@ -93,11 +94,15 @@ void JavaSettingsWidget::setupUi()
m_maxMemSpinBox->setObjectName(QStringLiteral("maxMemSpinBox"));
m_maxMemSpinBox->setSuffix(QStringLiteral(" MiB"));
m_maxMemSpinBox->setMinimum(128);
m_maxMemSpinBox->setMaximum(m_availableMemory);
m_maxMemSpinBox->setMaximum(1048576);
m_maxMemSpinBox->setSingleStep(128);
m_labelMaxMem->setBuddy(m_maxMemSpinBox);
m_gridLayout_2->addWidget(m_maxMemSpinBox, 1, 1, 1, 1);
m_labelMaxMemIcon = new QLabel(m_memoryGroupBox);
m_labelMaxMemIcon->setObjectName(QStringLiteral("labelMaxMemIcon"));
m_gridLayout_2->addWidget(m_labelMaxMemIcon, 1, 2, 1, 1);
m_labelPermGen = new QLabel(m_memoryGroupBox);
m_labelPermGen->setObjectName(QStringLiteral("labelPermGen"));
m_labelPermGen->setText(QStringLiteral("PermGen:"));
@ -108,7 +113,7 @@ void JavaSettingsWidget::setupUi()
m_permGenSpinBox->setObjectName(QStringLiteral("permGenSpinBox"));
m_permGenSpinBox->setSuffix(QStringLiteral(" MiB"));
m_permGenSpinBox->setMinimum(64);
m_permGenSpinBox->setMaximum(m_availableMemory);
m_permGenSpinBox->setMaximum(1048576);
m_permGenSpinBox->setSingleStep(8);
m_gridLayout_2->addWidget(m_permGenSpinBox, 2, 1, 1, 1);
m_permGenSpinBox->setVisible(false);
@ -130,6 +135,7 @@ void JavaSettingsWidget::initialize()
m_minMemSpinBox->setValue(observedMinMemory);
m_maxMemSpinBox->setValue(observedMaxMemory);
m_permGenSpinBox->setValue(observedPermGenMemory);
updateThresholds();
}
void JavaSettingsWidget::refresh()
@ -210,9 +216,9 @@ int JavaSettingsWidget::permGenSize() const
void JavaSettingsWidget::memoryValueChanged(int)
{
bool actuallyChanged = false;
int min = m_minMemSpinBox->value();
int max = m_maxMemSpinBox->value();
int permgen = m_permGenSpinBox->value();
unsigned int min = m_minMemSpinBox->value();
unsigned int max = m_maxMemSpinBox->value();
unsigned int permgen = m_permGenSpinBox->value();
QObject *obj = sender();
if (obj == m_minMemSpinBox && min != observedMinMemory)
{
@ -242,6 +248,7 @@ void JavaSettingsWidget::memoryValueChanged(int)
if(actuallyChanged)
{
checkJavaPathOnEdit(m_javaPathTextBox->text());
updateThresholds();
}
}
@ -435,3 +442,26 @@ void JavaSettingsWidget::retranslate()
m_permGenSpinBox->setToolTip(tr("The amount of memory available to store loaded Java classes."));
m_javaBrowseBtn->setText(tr("Browse"));
}
void JavaSettingsWidget::updateThresholds()
{
QString iconName;
if (observedMaxMemory >= m_availableMemory) {
iconName = "status-bad";
m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity."));
} else if (observedMaxMemory > (m_availableMemory * 0.9)) {
iconName = "status-yellow";
m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
} else {
iconName = "status-good";
m_labelMaxMemIcon->setToolTip("");
}
{
auto height = m_labelMaxMemIcon->fontInfo().pixelSize();
QIcon icon = APPLICATION->getThemedIcon(iconName);
QPixmap pix = icon.pixmap(height, height);
m_labelMaxMemIcon->setPixmap(pix);
}
}

View File

@ -56,6 +56,8 @@ public:
int maxHeapSize() const;
QString javaPath() const;
void updateThresholds();
protected slots:
void memoryValueChanged(int);
@ -85,6 +87,7 @@ private: /* data */
QSpinBox *m_maxMemSpinBox = nullptr;
QLabel *m_labelMinMem = nullptr;
QLabel *m_labelMaxMem = nullptr;
QLabel *m_labelMaxMemIcon = nullptr;
QSpinBox *m_minMemSpinBox = nullptr;
QLabel *m_labelPermGen = nullptr;
QSpinBox *m_permGenSpinBox = nullptr;
@ -92,9 +95,9 @@ private: /* data */
QIcon yellowIcon;
QIcon badIcon;
int observedMinMemory = 0;
int observedMaxMemory = 0;
int observedPermGenMemory = 0;
unsigned int observedMinMemory = 0;
unsigned int observedMaxMemory = 0;
unsigned int observedPermGenMemory = 0;
QString queuedCheck;
uint64_t m_availableMemory = 0ull;
shared_qobject_ptr<JavaChecker> m_checker;