Fix item selection not updating correctly

* Remove could lead to the "add" dialog being opened
* Rename could result in some entries not being renamed (due to
  FilterComboBox using a QComboBox with setEditable() set to true)
This commit is contained in:
WarmUpTill
2024-02-17 23:22:18 +01:00
committed by WarmUpTill
parent e13b9b0aa7
commit c94863b0cb
6 changed files with 27 additions and 27 deletions

View File

@@ -239,13 +239,11 @@ static bool AskForSettingsWrapper(QWidget *parent, Item &settings)
void ActionQueueSelection::SetActionQueue(
const std::weak_ptr<ActionQueue> &queue_)
{
const QSignalBlocker blocker(_selection);
auto queue = queue_.lock();
if (queue) {
_selection->setCurrentText(
QString::fromStdString(queue->Name()));
SetItem(queue->Name());
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}

View File

@@ -88,9 +88,12 @@ ItemSelection::ItemSelection(std::deque<std::shared_ptr<Item>> &items,
void ItemSelection::SetItem(const std::string &item)
{
const QSignalBlocker blocker(_selection);
if (!!GetItemByName(item, _items)) {
_selection->setCurrentText(QString::fromStdString(item));
if (_selection->lineEdit()) {
_selection->lineEdit()->setText(
QString::fromStdString(item));
}
} else {
_selection->setCurrentIndex(-1);
}
@@ -111,7 +114,6 @@ void ItemSelection::ChangeSelection(const QString &sel)
return;
}
_items.emplace_back(item);
const QSignalBlocker b(_selection);
const QString name = QString::fromStdString(item->_name);
AddItem(name);
_selection->setCurrentText(name);
@@ -195,6 +197,7 @@ void ItemSelection::RenameItem()
const auto oldName = item->_name;
item->_name = name;
SetItem(name);
emit ItemRenamed(QString::fromStdString(oldName),
QString::fromStdString(name));
}
@@ -205,7 +208,11 @@ void ItemSelection::RenameItem(const QString &oldName, const QString &name)
if (idx == -1) {
return;
}
auto currentText = _selection->currentText();
_selection->setItemText(idx, name);
if (oldName == currentText) {
SetItem(name.toStdString());
}
}
void ItemSelection::AddItem(const QString &name)
@@ -240,9 +247,10 @@ void ItemSelection::RemoveItem()
void ItemSelection::RemoveItem(const QString &name)
{
auto currentText = _selection->currentText();
const int idx = _selection->findText(name);
if (idx == _selection->currentIndex()) {
_selection->setCurrentIndex(-1);
if (currentText == name) {
SetItem("");
}
_selection->removeItem(idx);
}

View File

@@ -95,7 +95,7 @@ signals:
void ItemRemoved(const QString &);
void ItemRenamed(const QString &oldName, const QString &name);
protected:
private:
Item *GetCurrentItem();
FilterComboBox *_selection;

View File

@@ -285,22 +285,20 @@ VariableSelection::VariableSelection(QWidget *parent)
void VariableSelection::SetVariable(const std::string &variable)
{
const QSignalBlocker blocker(_selection);
if (!!GetVariableByName(variable)) {
_selection->setCurrentText(QString::fromStdString(variable));
SetItem(variable);
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}
void VariableSelection::SetVariable(const std::weak_ptr<Variable> &variable_)
{
const QSignalBlocker blocker(_selection);
auto var = variable_.lock();
if (var) {
SetVariable(var->Name());
SetItem(var->Name());
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}

View File

@@ -298,23 +298,21 @@ ConnectionSelection::ConnectionSelection(QWidget *parent)
void ConnectionSelection::SetConnection(const std::string &con)
{
const QSignalBlocker blocker(_selection);
if (!!GetConnectionByName(con)) {
_selection->setCurrentText(QString::fromStdString(con));
SetItem(con);
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}
void ConnectionSelection::SetConnection(
const std::weak_ptr<Connection> &connection_)
{
const QSignalBlocker blocker(_selection);
auto connection = connection_.lock();
if (connection) {
SetConnection(connection->Name());
SetItem(connection->Name());
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}

View File

@@ -397,23 +397,21 @@ TwitchConnectionSelection::TwitchConnectionSelection(QWidget *parent)
void TwitchConnectionSelection::SetToken(const std::string &token)
{
const QSignalBlocker blocker(_selection);
if (!!GetTwitchTokenByName(token)) {
_selection->setCurrentText(QString::fromStdString(token));
SetItem(token);
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}
void TwitchConnectionSelection::SetToken(
const std::weak_ptr<TwitchToken> &token_)
{
const QSignalBlocker blocker(_selection);
auto token = token_.lock();
if (token) {
SetToken(token->Name());
SetItem(token->Name());
} else {
_selection->setCurrentIndex(-1);
SetItem("");
}
}