diff widgets/PropertyBox.cpp @ 1602:a798a7b5e215

Further removal of Qt 5.6+-only APIs
author Chris Cannam
date Wed, 29 Apr 2020 14:46:37 +0100
parents 26e80a450e74
children 5feb1a8318df
line wrap: on
line diff
--- a/widgets/PropertyBox.cpp	Wed Apr 29 14:23:51 2020 +0100
+++ b/widgets/PropertyBox.cpp	Wed Apr 29 14:46:37 2020 +0100
@@ -61,7 +61,8 @@
     m_container(container),
     m_showButton(nullptr),
     m_playButton(nullptr),
-    m_lastContextMenu(nullptr)
+    m_lastContextMenu(nullptr),
+    m_contextMenuOn(nullptr)
 {
 #ifdef DEBUG_PROPERTY_BOX
     SVDEBUG << "PropertyBox[" << this << "(\"" <<
@@ -695,26 +696,24 @@
 
     delete m_lastContextMenu;
     QMenu *m = new QMenu;
+
     m_lastContextMenu = m;
+    m_contextMenuOn = obj;
 
-    if (auto button = qobject_cast<QAbstractButton *>(obj)) {
+    if (qobject_cast<QAbstractButton *>(obj)) {
         if (value > 0) {
             MenuTitle::addTitle(m, tr("%1: On").arg(label));
         } else {
             MenuTitle::addTitle(m, tr("%1: Off").arg(label));
         }
-
-        m->addAction(tr("&Reset to Default"),
-                     [=]() {
-                         button->setChecked(deflt > 0);
-                     });
+        m->addAction(tr("&Reset to Default"), this,
+                     SLOT(propertyControllerResetRequested()));
 
     } else if (auto cb = qobject_cast<QComboBox *>(obj)) {
         MenuTitle::addTitle(m, tr("%1: %2").arg(label).arg(cb->itemText(value)));
-        m->addAction(tr("&Reset to Default"),
-                     [=]() {
-                         cb->setCurrentIndex(deflt);
-                     });
+        m->addAction(tr("&Reset to Default"), this,
+                     SLOT(propertyControllerResetRequested()));
+
     } else {
         // AudioDial has its own context menu, we don't handle it here
         return;
@@ -724,6 +723,24 @@
 }
 
 void
+PropertyBox::propertyControllerResetRequested()
+{
+    if (!m_contextMenuOn) return;
+    
+    QString name = m_contextMenuOn->objectName();
+    
+    QString label = m_container->getPropertyLabel(name);
+    int min = 0, max = 0, value = 0, deflt = 0;
+    value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
+    
+    if (auto button = qobject_cast<QAbstractButton *>(m_contextMenuOn)) {
+        button->setChecked(deflt > 0);
+    } else if (auto cb = qobject_cast<QComboBox *>(m_contextMenuOn)) {
+        cb->setCurrentIndex(deflt);
+    }
+}
+
+void
 PropertyBox::playAudibleChanged(bool audible)
 {
     m_playButton->setChecked(audible);