Commit 3d153778 authored by Michael Pyne's avatar Michael Pyne

Use a less magical way of hooking widgets together in tag editor.

Before this, we used a convention involving object names assigned in the
.ui XML to figure out at runtime which QCheckBoxes were used to enable
which widgets for multi-item edit ("configuration by convention" before
Rails made it cool!).

But, I found it hard to understand years later so I'm trying for
something more direct.  Hopefully it will be easier to understand to
whoever reads this 10 years from now.
parent d7c56f4f
...@@ -257,7 +257,6 @@ void TagEditor::slotRefresh() ...@@ -257,7 +257,6 @@ void TagEditor::slotRefresh()
// If there is more than one item in the m_items that we're dealing with... // If there is more than one item in the m_items that we're dealing with...
QList<QWidget *> disabledForMulti; QList<QWidget *> disabledForMulti;
disabledForMulti << fileNameLabel << fileNameBox << lengthLabel << lengthBox disabledForMulti << fileNameLabel << fileNameBox << lengthLabel << lengthBox
...@@ -494,7 +493,7 @@ void TagEditor::setupLayout() ...@@ -494,7 +493,7 @@ void TagEditor::setupLayout()
{ {
setupUi(this); setupUi(this);
foreach(QWidget *input, findChildren<QWidget *>()) { for(auto input : findChildren<QWidget *>()) {
if(input->inherits("QLineEdit")) if(input->inherits("QLineEdit"))
connect(input, SIGNAL(textChanged(QString)), this, SLOT(slotDataChanged())); connect(input, SIGNAL(textChanged(QString)), this, SLOT(slotDataChanged()));
if(input->inherits("QComboBox")) { if(input->inherits("QComboBox")) {
...@@ -509,18 +508,26 @@ void TagEditor::setupLayout() ...@@ -509,18 +508,26 @@ void TagEditor::setupLayout()
// Do some meta-programming to find the matching enable boxes // Do some meta-programming to find the matching enable boxes
foreach(QCheckBox *enable, findChildren<QCheckBox *>(QRegExp("Enable"))) { for(auto enable : findChildren<QCheckBox *>(QRegExp("Enable$"))) {
enable->hide(); enable->hide(); // These are shown only when multiple items are being edited
QRegExp re('^' + enable->objectName().replace("Enable", "") + "(Box|Spin)$");
QList<QWidget *> targets = findChildren<QWidget *>(re); // Each enable checkbox is identified by having its objectName end in "Enable".
Q_ASSERT(!targets.isEmpty()); // The corresponding widget to be adjusted is identified by assigning a custom
m_enableBoxes[targets.front()] = enable; // property in Qt Designer "associatedObjectName", the value of which is the name
// for the widget to be enabled (or not).
auto associatedVariantValue = enable->property("associatedObjectName");
Q_ASSERT(associatedVariantValue.isValid());
QWidget *associatedWidget = findChild<QWidget *>(associatedVariantValue.toString());
Q_ASSERT(associatedWidget != nullptr);
m_enableBoxes[associatedWidget] = enable;
} }
// Make sure that the labels are as tall as the enable buttons so that the // Make sure that the labels are as tall as the enable boxes so that the
// layout doesn't jump around. // layout doesn't jump around as the enable boxes are shown/hidden.
foreach(QLabel *label, findChildren<QLabel *>()) { for(auto label : findChildren<QLabel *>()) {
if(m_enableBoxes.contains(label->buddy())) if(m_enableBoxes.contains(label->buddy()))
label->setMinimumHeight(m_enableBoxes[label->buddy()]->height()); label->setMinimumHeight(m_enableBoxes[label->buddy()]->height());
} }
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>622</width> <width>885</width>
<height>221</height> <height>416</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
...@@ -193,6 +193,9 @@ ...@@ -193,6 +193,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>artistNameBox</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
...@@ -203,6 +206,9 @@ ...@@ -203,6 +206,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>trackNameBox</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
...@@ -210,6 +216,9 @@ ...@@ -210,6 +216,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>albumNameBox</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
...@@ -217,6 +226,9 @@ ...@@ -217,6 +226,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>genreBox</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="5"> <item row="2" column="5">
...@@ -224,6 +236,9 @@ ...@@ -224,6 +236,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>trackSpin</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="9"> <item row="2" column="9">
...@@ -231,6 +246,9 @@ ...@@ -231,6 +246,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>yearSpin</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="5" colspan="5"> <item row="4" column="5" colspan="5">
...@@ -238,6 +256,9 @@ ...@@ -238,6 +256,9 @@
<property name="text"> <property name="text">
<string>Enable</string> <string>Enable</string>
</property> </property>
<property name="associatedObjectName" stdset="0">
<cstring>commentBox</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="6" rowspan="2"> <item row="2" column="6" rowspan="2">
...@@ -253,9 +274,9 @@ ...@@ -253,9 +274,9 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>KLineEdit</class> <class>KTextEdit</class>
<extends>KLineEdit</extends> <extends>QTextEdit</extends>
<header>klineedit.h</header> <header>ktextedit.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>KComboBox</class> <class>KComboBox</class>
...@@ -263,9 +284,9 @@ ...@@ -263,9 +284,9 @@
<header>kcombobox.h</header> <header>kcombobox.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>KTextEdit</class> <class>KLineEdit</class>
<extends>QTextEdit</extends> <extends>QLineEdit</extends>
<header>ktextedit.h</header> <header>klineedit.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment