summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKatja Marttila <[email protected]>2025-05-22 11:46:16 +0300
committerKatja Marttila <[email protected]>2025-05-27 15:51:10 +0300
commitf4ec5b8ef15b2574076b4f3d0dabb6e42d8bdb22 (patch)
tree316d9bc45bc861d69cbe7d5310e15af3daad8fd8 /src
parentaf6aa8d69d2633196cbe1e08b0a1709087032619 (diff)
Add possibility to add warning labels from scriptHEADdev
Introducing new invokable methods, addWizardPageWarning() and removeWizardPageWarning() to add and remove warning messages to existing pages. Warning messages can be added also with existing addWizardPageItem() -function, but the new method utilizes the LabelWithPixmap -class, which draws a warning image and a label with text wrapped. Task-number: QTIFW-3555 Change-Id: Ie7867d369762f7616ce8c7ca47d102111d651da5 Reviewed-by: Arttu Tarkiainen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/libs/installer/packagemanagercore.cpp50
-rw-r--r--src/libs/installer/packagemanagercore.h4
-rw-r--r--src/libs/installer/packagemanagergui.cpp81
-rw-r--r--src/libs/installer/packagemanagergui.h2
4 files changed, 122 insertions, 15 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 81fd8ad18..8bcbd3ba8 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -1999,6 +1999,56 @@ bool PackageManagerCore::removeWizardPageItem(Component *component, const QStrin
}
/*!
+ \fn QInstaller::PackageManagerCore::addWizardPageWarning(const QString &message,
+ PackageManagerCore::WizardPage page, const QString &id, int position)
+
+ Adds a warning label into the installer's GUI wizard. The label is added on
+ \a page ordered by \a position number. If several widgets are added to the same
+ page, the widget with lower \a position number will be inserted on top. The label
+ is identified with \a id.
+
+ See \l{Controller Scripting} for the possible values of \a page.
+
+ If the installation is not a command line install, returns \c true and emits the
+ wizardPageWarningInsertionRequested() signal.
+
+ \sa {installer::addWizardPageWarning}{installer.addWizardPageWarning}
+ \sa removeWizardPageWarning(), wizardPageWarningInsertionRequested()
+*/
+
+bool PackageManagerCore::addWizardPageWarning(const QString &message, PackageManagerCore::WizardPage page, const QString &id, int position)
+{
+ if (!isCommandLineInstance()) {
+ emit wizardPageWarningInsertionRequested(message, static_cast<WizardPage>(page), id, position);
+ return true;
+ } else {
+ qCDebug(QInstaller::lcDeveloperBuild) << "Headless installation: skip warning page item addition: " << id;
+ }
+ return false;
+}
+
+/*!
+ \fn QInstaller::PackageManagerCore::removeWizardPageWarning(const QString &id)
+
+ Removes the widget with the identification \a id, previously added to the
+ installer's wizard by addWizardPageWarning().
+
+ If the installation is not a command line install, returns \c true and
+ emits the wizardPageWarningRemovalRequested() signal.
+
+ \sa {installer::removeWizardPageWarning}{installer.removeWizardPageWarning}
+ \sa addWizardPageWarning()
+*/
+bool PackageManagerCore::removeWizardPageWarning(const QString &id)
+{
+ if (!isCommandLineInstance()) {
+ emit wizardPageWarningRemovalRequested(id);
+ return true;
+ }
+ return false;
+}
+
+/*!
Registers additional \a repositories.
\sa {installer::addUserRepositories}{installer.addUserRepositories}
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index f896f89d5..2c89f412a 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -365,6 +365,8 @@ public:
Q_INVOKABLE bool addWizardPageItem(QInstaller::Component *component, const QString &name,
int page, int position = 100);
Q_INVOKABLE bool removeWizardPageItem(QInstaller::Component *component, const QString &name);
+ Q_INVOKABLE bool addWizardPageWarning(const QString &message, PackageManagerCore::WizardPage page, const QString &id, int position = 100);
+ Q_INVOKABLE bool removeWizardPageWarning(const QString &id);
Q_INVOKABLE bool setDefaultPageVisible(int page, bool visible);
Q_INVOKABLE void setValidatorForCustomPage(QInstaller::Component *component, const QString &name,
const QString &callbackName);
@@ -457,6 +459,8 @@ Q_SIGNALS:
void wizardWidgetInsertionRequested(QWidget *widget, QInstaller::PackageManagerCore::WizardPage page,
int position);
void wizardWidgetRemovalRequested(QWidget *widget);
+ void wizardPageWarningInsertionRequested(const QString &message, PackageManagerCore::WizardPage page, const QString &id, int position);
+ void wizardPageWarningRemovalRequested(const QString &id);
void wizardPageVisibilityChangeRequested(bool visible, int page);
void setValidatorForCustomPageRequested(QInstaller::Component *component, const QString &name,
const QString &callbackName);
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index 0412d67ef..8b3293de1 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -44,6 +44,7 @@
#include "loggingutils.h"
#include "readyforinstallationpage_p.h"
#include "clickablelabel.h"
+#include "labelwithpixmap.h"
#include "sysinfo.h"
#include "globals.h"
@@ -253,6 +254,25 @@ public:
m_showSettingsButton = show;
}
+ void addAndOrderCustomWidgets(PackageManagerPage *p, QWidget *widget)
+ {
+ if (p->m_customWidgets.count() > 1 ) {
+ //Reorder the custom widgets based on their position
+ QMultiMap<int, QWidget*>::Iterator it = p->m_customWidgets.begin();
+ while (it != p->m_customWidgets.end()) {
+ p->layout()->removeWidget(it.value());
+ ++it;
+ }
+ it = p->m_customWidgets.begin();
+ while (it != p->m_customWidgets.end()) {
+ p->layout()->addWidget(it.value());
+ ++it;
+ }
+ } else {
+ p->layout()->addWidget(widget);
+ }
+ }
+
PackageManagerGui *q;
int m_currentId;
bool m_modified;
@@ -455,6 +475,10 @@ PackageManagerGui::PackageManagerGui(PackageManagerCore *core, QWidget *parent)
this, &PackageManagerGui::wizardWidgetInsertionRequested);
connect(m_core, &PackageManagerCore::wizardWidgetRemovalRequested,
this, &PackageManagerGui::wizardWidgetRemovalRequested);
+ connect(m_core, &PackageManagerCore::wizardPageWarningInsertionRequested,
+ this, &PackageManagerGui::wizardPageWarningInsertionRequested);
+ connect(m_core, &PackageManagerCore::wizardPageWarningRemovalRequested,
+ this, &PackageManagerGui::wizardPageWarningRemovalRequested);
connect(m_core, &PackageManagerCore::wizardPageVisibilityChangeRequested,
this, &PackageManagerGui::wizardPageVisibilityChangeRequested, Qt::QueuedConnection);
@@ -889,21 +913,7 @@ void PackageManagerGui::wizardWidgetInsertionRequested(QWidget *widget,
if (PackageManagerPage *p = qobject_cast<PackageManagerPage *>(QWizard::page(page))) {
p->m_customWidgets.insert(position, widget);
- if (p->m_customWidgets.count() > 1 ) {
- //Reorder the custom widgets based on their position
- QMultiMap<int, QWidget*>::Iterator it = p->m_customWidgets.begin();
- while (it != p->m_customWidgets.end()) {
- p->layout()->removeWidget(it.value());
- ++it;
- }
- it = p->m_customWidgets.begin();
- while (it != p->m_customWidgets.end()) {
- p->layout()->addWidget(it.value());
- ++it;
- }
- } else {
- p->layout()->addWidget(widget);
- }
+ d->addAndOrderCustomWidgets(p, widget);
packageManagerCore()->controlScriptEngine()->addToGlobalObject(p);
packageManagerCore()->componentScriptEngine()->addToGlobalObject(p);
}
@@ -927,6 +937,47 @@ void PackageManagerGui::wizardWidgetRemovalRequested(QWidget *widget)
}
/*!
+ Requests the insertion of warning label on \a page. Warning label consists of a warning
+ image and \a message. Widget with lower \a position number will be inserted on top.
+ Warning label is identified with \a id.
+*/
+void PackageManagerGui::wizardPageWarningInsertionRequested(const QString &message, PackageManagerCore::WizardPage page, const QString &id, int position)
+{
+ // Check if the warning is already added
+ if (findChild<LabelWithPixmap* >(QLatin1String("LabelWithPixmap_") + id)) {
+ qCDebug(QInstaller::lcDeveloperBuild) << "Warning label with id " << id << "already added";
+ return;
+ }
+
+ if (PackageManagerPage *p = qobject_cast<PackageManagerPage *>(QWizard::page(page))) {
+ LabelWithPixmap *warningLabel = new LabelWithPixmap(message, QLatin1String(":/warning.png"));
+ warningLabel->setObjectName(QLatin1String("LabelWithPixmap_") + id);
+ p->m_customWidgets.insert(position, warningLabel);
+ d->addAndOrderCustomWidgets(p, warningLabel);
+ packageManagerCore()->controlScriptEngine()->addToGlobalObject(warningLabel);
+ packageManagerCore()->componentScriptEngine()->addToGlobalObject(warningLabel);
+ }
+}
+
+/*!
+ Requests the removal of the warning label, identified with \a id, from installer page.
+*/
+void PackageManagerGui::wizardPageWarningRemovalRequested(const QString &id)
+{
+ LabelWithPixmap *warningLabel = findChild<LabelWithPixmap* >(QLatin1String("LabelWithPixmap_") + id);
+ if (!warningLabel)
+ return;
+ const QList<int> pages = pageIds();
+ for (const int id : pages) {
+ PackageManagerPage *managerPage = qobject_cast<PackageManagerPage *>(page(id));
+ managerPage->removeCustomWidget(warningLabel);
+ }
+ warningLabel->setParent(nullptr);
+ packageManagerCore()->controlScriptEngine()->removeFromGlobalObject(warningLabel);
+ packageManagerCore()->componentScriptEngine()->removeFromGlobalObject(warningLabel);
+}
+
+/*!
Requests changing the visibility of the page specified by \a p to
\a visible.
*/
diff --git a/src/libs/installer/packagemanagergui.h b/src/libs/installer/packagemanagergui.h
index 95ec6cb2e..397cfefe5 100644
--- a/src/libs/installer/packagemanagergui.h
+++ b/src/libs/installer/packagemanagergui.h
@@ -122,6 +122,8 @@ protected Q_SLOTS:
void wizardWidgetInsertionRequested(QWidget *widget, QInstaller::PackageManagerCore::WizardPage page,
int position);
void wizardWidgetRemovalRequested(QWidget *widget);
+ void wizardPageWarningInsertionRequested(const QString &message, PackageManagerCore::WizardPage page, const QString &id, int position);
+ void wizardPageWarningRemovalRequested(const QString &id);
void wizardPageVisibilityChangeRequested(bool visible, int page);
void setValidatorForCustomPageRequested(QInstaller::Component *component, const QString &name,
const QString &callbackName);