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()
// If there is more than one item in the m_items that we're dealing with...
QList<QWidget *> disabledForMulti;
disabledForMulti << fileNameLabel << fileNameBox << lengthLabel << lengthBox
......@@ -494,7 +493,7 @@ void TagEditor::setupLayout()
{
setupUi(this);
foreach(QWidget *input, findChildren<QWidget *>()) {
for(auto input : findChildren<QWidget *>()) {
if(input->inherits("QLineEdit"))
connect(input, SIGNAL(textChanged(QString)), this, SLOT(slotDataChanged()));
if(input->inherits("QComboBox")) {
......@@ -509,18 +508,26 @@ void TagEditor::setupLayout()
// Do some meta-programming to find the matching enable boxes
foreach(QCheckBox *enable, findChildren<QCheckBox *>(QRegExp("Enable"))) {
enable->hide();
QRegExp re('^' + enable->objectName().replace("Enable", "") + "(Box|Spin)$");
QList<QWidget *> targets = findChildren<QWidget *>(re);
Q_ASSERT(!targets.isEmpty());
m_enableBoxes[targets.front()] = enable;
for(auto enable : findChildren<QCheckBox *>(QRegExp("Enable$"))) {
enable->hide(); // These are shown only when multiple items are being edited
// Each enable checkbox is identified by having its objectName end in "Enable".
// The corresponding widget to be adjusted is identified by assigning a custom
// 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
// layout doesn't jump around.
// Make sure that the labels are as tall as the enable boxes so that the
// 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()))
label->setMinimumHeight(m_enableBoxes[label->buddy()]->height());
}
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>622</width>
<height>221</height>
<width>885</width>
<height>416</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
......@@ -193,6 +193,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>artistNameBox</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
......@@ -203,6 +206,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>trackNameBox</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
......@@ -210,6 +216,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>albumNameBox</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
......@@ -217,6 +226,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>genreBox</cstring>
</property>
</widget>
</item>
<item row="2" column="5">
......@@ -224,6 +236,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>trackSpin</cstring>
</property>
</widget>
</item>
<item row="2" column="9">
......@@ -231,6 +246,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>yearSpin</cstring>
</property>
</widget>
</item>
<item row="4" column="5" colspan="5">
......@@ -238,6 +256,9 @@
<property name="text">
<string>Enable</string>
</property>
<property name="associatedObjectName" stdset="0">
<cstring>commentBox</cstring>
</property>
</widget>
</item>
<item row="2" column="6" rowspan="2">
......@@ -253,9 +274,9 @@
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>KLineEdit</extends>
<header>klineedit.h</header>
<class>KTextEdit</class>
<extends>QTextEdit</extends>
<header>ktextedit.h</header>
</customwidget>
<customwidget>
<class>KComboBox</class>
......@@ -263,9 +284,9 @@
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KTextEdit</class>
<extends>QTextEdit</extends>
<header>ktextedit.h</header>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
</customwidgets>
<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