Skip to content

Commit

Permalink
Fix Enter key behavior in Add new torrent dialog
Browse files Browse the repository at this point in the history
Prevent inappropriate default completer from being used by path edit.

PR qbittorrent#20670.
Closes qbittorrent#20663.
  • Loading branch information
glassez committed Apr 8, 2024
1 parent 684a561 commit a7dfefc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/gui/fspathedit_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ QValidator::State Private::FileSystemPathValidator::validate(QString &input, int
Private::FileLineEdit::FileLineEdit(QWidget *parent)
: QLineEdit(parent)
{
setCompleter(new QCompleter(this));
connect(this, &QLineEdit::textChanged, this, &FileLineEdit::validateText);
}

Expand Down Expand Up @@ -222,7 +223,7 @@ void Private::FileLineEdit::keyPressEvent(QKeyEvent *e)

if ((e->key() == Qt::Key_Space) && (e->modifiers() == Qt::CTRL))
{
if (!m_completer)
if (!m_completerModel)
{
m_iconProvider = new QFileIconProvider;
m_iconProvider->setOptions(QFileIconProvider::DontUseCustomDirectoryIcons);
Expand All @@ -235,9 +236,7 @@ void Private::FileLineEdit::keyPressEvent(QKeyEvent *e)
| (m_completeDirectoriesOnly ? QDir::Dirs : QDir::AllEntries);
m_completerModel->setFilter(filters);

m_completer = new QCompleter(this);
m_completer->setModel(m_completerModel);
setCompleter(m_completer);
completer()->setModel(m_completerModel);
}

m_completerModel->setRootPath(Path(text()).data());
Expand All @@ -261,8 +260,8 @@ void Private::FileLineEdit::contextMenuEvent(QContextMenuEvent *event)

void Private::FileLineEdit::showCompletionPopup()
{
m_completer->setCompletionPrefix(text());
m_completer->complete();
completer()->setCompletionPrefix(text());
completer()->complete();
}

void Private::FileLineEdit::validateText()
Expand Down
2 changes: 0 additions & 2 deletions src/gui/fspathedit_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "base/pathfwd.h"

class QAction;
class QCompleter;
class QContextMenuEvent;
class QFileIconProvider;
class QFileSystemModel;
Expand Down Expand Up @@ -141,7 +140,6 @@ namespace Private
static QString warningText(FileSystemPathValidator::TestResult result);

QFileSystemModel *m_completerModel = nullptr;
QCompleter *m_completer = nullptr;
QAction *m_browseAction = nullptr;
QAction *m_warningAction = nullptr;
QFileIconProvider *m_iconProvider = nullptr;
Expand Down

0 comments on commit a7dfefc

Please sign in to comment.