mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
perf: skip some excess announce list rebuilds
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QStyle>
|
||||
@@ -239,12 +240,47 @@ void PrefsDialog::linkWidgetToPref(QWidget* widget, int pref_key)
|
||||
connect(spin_box, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::spinBoxEditingFinished);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto const* edit = qobject_cast<QPlainTextEdit*>(widget); edit != nullptr)
|
||||
static bool isDescendantOf(QObject const* descendant, QObject const* ancestor)
|
||||
{
|
||||
if (ancestor == nullptr)
|
||||
{
|
||||
connect(edit, &QPlainTextEdit::textChanged, this, &PrefsDialog::plainTextChanged);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
while (descendant != nullptr)
|
||||
{
|
||||
if (descendant == ancestor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
descendant = descendant->parent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PrefsDialog::focusChanged(QWidget* old, QWidget* cur)
|
||||
{
|
||||
// We don't want to change the preference every time there's a keystroke
|
||||
// in a QPlainTextEdit, so instead of connecting to the textChanged signal,
|
||||
// only update the pref when the text changed AND focus was lost.
|
||||
char const constexpr* const StartValue = "StartValue";
|
||||
|
||||
if (auto* const edit = qobject_cast<QPlainTextEdit*>(cur); isDescendantOf(edit, this))
|
||||
{
|
||||
edit->setProperty(StartValue, edit->toPlainText());
|
||||
}
|
||||
|
||||
if (auto const* const edit = qobject_cast<QPlainTextEdit*>(old); isDescendantOf(edit, this))
|
||||
{
|
||||
if (auto const val = edit->toPlainText(); val != edit->property(StartValue).toString())
|
||||
{
|
||||
setPref(PreferenceWidget{ old }.getPrefKey(), val);
|
||||
}
|
||||
}
|
||||
|
||||
// (TODO: we probably want to do this for single-line text entries too?)
|
||||
}
|
||||
|
||||
void PrefsDialog::checkBoxToggled(bool checked)
|
||||
@@ -306,22 +342,6 @@ void PrefsDialog::pathChanged(QString const& path)
|
||||
}
|
||||
}
|
||||
|
||||
void PrefsDialog::plainTextChanged()
|
||||
{
|
||||
PreferenceWidget const pref_widget(sender());
|
||||
|
||||
if (pref_widget.is<QPlainTextEdit>())
|
||||
{
|
||||
auto const* const plain_text_edit = pref_widget.as<QPlainTextEdit>();
|
||||
|
||||
if (plain_text_edit->document()->isModified())
|
||||
{
|
||||
prefs_.set(pref_widget.getPrefKey(), plain_text_edit->toPlainText());
|
||||
// we avoid using setPref() because the included refreshPref() call would reset the cursor while we're editing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
@@ -704,6 +724,8 @@ PrefsDialog::PrefsDialog(Session& session, Prefs& prefs, QWidget* parent)
|
||||
}
|
||||
|
||||
adjustSize();
|
||||
|
||||
connect(qApp, &QApplication::focusChanged, this, &PrefsDialog::focusChanged);
|
||||
}
|
||||
|
||||
void PrefsDialog::setPref(int key, QVariant const& v)
|
||||
|
||||
Reference in New Issue
Block a user