-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a widget for editing file names #5375
Conversation
src/gui/fspathedit.cpp
Outdated
#endif | ||
} | ||
|
||
#include "moc_fspathedit.cpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you include this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to Q_PRIVATE_SLOT(d_func(), void browseActionTriggered())
in the FileSystemPathEdit
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q_PRIVATE_SLOT replaced with lambda.
Is it a good idea to move the new code to its own folder |
IMO, it's good. |
Maybe |
Then we should move all other widgets there. |
... and do the same for |
src/gui/addnewtorrentdialog.cpp
Outdated
size_string += ")"; | ||
ui->size_lbl->setText(size_string); | ||
} | ||
|
||
void AddNewTorrentDialog::onSavePathChanged(int index) | ||
void AddNewTorrentDialog::onSavePathChanged(const QString &/*text*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can connect slots with fewer parameters than signal has.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me, I don't understand what did you mean here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean you can turn it to void AddNewTorrentDialog::onSavePathChanged()
unless you need QString
param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks.
src/gui/addnewtorrentdialog.cpp
Outdated
@@ -658,6 +623,15 @@ void AddNewTorrentDialog::accept() | |||
BitTorrent::Session::instance()->addTorrent(m_torrentInfo, params); | |||
|
|||
m_torrentGuard->markAsAddedToSession(); | |||
|
|||
// add selected save path to the save path history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about it outside of class. Why not do this in the destructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not delved much into the logic (leave that for the author), but the code structure looks good. I left some comments. This is a very useful widget. I hope you will expand it in the future to support relative paths too.
src/gui/fspathedit.cpp
Outdated
#include <QToolButton> | ||
|
||
#include "fspathedit_p.h" | ||
#include "base/utils/fs.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move one line up.
src/gui/fspathedit.cpp
Outdated
break; | ||
case FileSystemPathEdit::Mode::DirectoryOpen: | ||
case FileSystemPathEdit::Mode::DirectorySave: | ||
selectedPath = QFileDialog::getExistingDirectory(q, dialogCaptionOrDefault(), directory, QFileDialog::DontResolveSymlinks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split this line on some param boundary.
src/gui/fspathedit.cpp
Outdated
connect(d->m_browseAction, SIGNAL(triggered(bool)), this, SLOT(browseActionTriggered())); | ||
} | ||
|
||
FileSystemPathEdit::~FileSystemPathEdit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to omit this body and use = default
in header?
src/gui/fspathedit.cpp
Outdated
Q_D(FileSystemPathEdit); | ||
d->m_fileNameFilter = val; | ||
|
||
#if 0 // QFileSystemModel applies name filters to directories too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move comment to the next line.
src/gui/fspathedit.cpp
Outdated
Q_D(FileSystemPathEdit); | ||
QString newPath = selectedPath(); | ||
if (newPath != d->m_lastSignaledPath) { | ||
Q_EMIT selectedPathChanged(newPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We support emit
keyword, isn't it?
src/gui/fspathedit.h
Outdated
|
||
enum class Mode | ||
{ | ||
FileOpen, //!< Working mode for opening files, shows open dialog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to put these comments closer to the enum items?
src/gui/fspathedit.h
Outdated
protected slots: | ||
void onPathEdited(); | ||
|
||
signals: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public members should appear before protected/private. Signals are public.
Also protected/private slots is less protected/private than other protected/private members.
src/gui/fspathedit.h
Outdated
Q_DISABLE_COPY(FileSystemPathEdit) | ||
class FileSystemPathEditPrivate; | ||
Q_DECLARE_PRIVATE(FileSystemPathEdit) | ||
Q_PRIVATE_SLOT(d_func(), void browseActionTriggered()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qt has a naming convention for private slots (don't remember exactly how it looks).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with lambda.
src/gui/fspathedit.h
Outdated
class FileSystemPathEditPrivate; | ||
Q_DECLARE_PRIVATE(FileSystemPathEdit) | ||
Q_PRIVATE_SLOT(d_func(), void browseActionTriggered()) | ||
QScopedPointer<FileSystemPathEditPrivate> const d_ptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use QScopedPointers in these places? Why not usual Qt ownership?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The private class does not inherit QObject.
src/gui/fspathedit_p.cpp
Outdated
, m_completer {new QCompleter(this)} | ||
, m_browseAction {nullptr} | ||
{ | ||
#if !defined QBT_USES_QT5 && defined Q_OS_WIN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QBT_USES_QT5 is outdated.
{ | ||
public: | ||
virtual ~FileEditorWithCompletion() = default; | ||
virtual void completeDirectoriesOnly(bool completeDirsOnly) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why C++ still does not have abstract
keyword for this purpose?
When I update this PR now, do you think I should move its files into |
Not here, exactly. |
Or you can wait till most existing PRs are merged, we are merging fast recently... |
OK, thank you for your input! Then for this one the files will be kept at the same place. |
PR updated:
|
src/gui/fspathedit.h
Outdated
|
||
virtual void clear() = 0; | ||
|
||
signals: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken indentation. And next line too.
src/gui/fspathedit_p.cpp
Outdated
m_completer->setCompletionMode(QCompleter::PopupCompletion); | ||
setCompleter(m_completer); | ||
|
||
connect(m_completerModel, SIGNAL(directoryLoaded(QString)), this, SLOT(showCompletionPopup())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use Qt5 style here too.
src/gui/fspathedit.cpp
Outdated
m_browseAction->setIconText(browseButtonBriefText.tr()); | ||
m_browseAction->setText(browseButtonFullText.tr()); | ||
m_browseAction->setToolTip(browseButtonFullText.tr().remove(QLatin1Char('&'))); | ||
m_browseAction->setShortcut({Qt::CTRL + Qt::Key_B}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly braces required?
src/gui/fspathedit.cpp
Outdated
|
||
void FileSystemPathEdit::FileSystemPathEditPrivate::browseActionTriggered() | ||
{ | ||
QString selectedPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this to just above switch expression.
src/gui/fspathedit.cpp
Outdated
pixmap = QStyle::SP_DirOpenIcon; | ||
showDirsOnly = true; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if a default case would make sense... but it doesn't hurt to add one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes! default
with throw
was mistakenly forgotten here.
Q_D(FileSystemPathEdit); | ||
d->m_fileNameFilter = val; | ||
|
||
#if 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if 0
for comments? /**/
does not suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, #if 0
is perfect for commenting out a block of code which itself contains comments inside.
#include <QFileSystemModel> | ||
#include <QKeyEvent> | ||
#include <QLineEdit> | ||
#include <QMenu> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forward declare as much as possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is important here, because this is a private header, included from only single other place.
src/gui/optionsdlg.cpp
Outdated
|
||
m_ui->textFilterPath->setDialogCaption(tr("Choose an IP filter file")); | ||
m_ui->textFilterPath->setFileNameFilter(tr("All supported filters") | ||
+ QString(" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QString
-> QLatin1String
?
Comments from reviewers are addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have commented something, but it's optional, you don't have to fix anything anymore.
@@ -34,6 +34,7 @@ | |||
#include <QUrl> | |||
#include <QMenu> | |||
#include <QFileDialog> | |||
#include <QPushButton> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this include needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is needed. Otherwise:
../../src/gui/addnewtorrentdialog.cpp:148:45: error: invalid use of incomplete type ‘class QPushButton’
ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus();
^~
src/gui/fspathedit.cpp
Outdated
QString m_dialogCaption; | ||
}; | ||
|
||
FileSystemPathEdit::FileSystemPathEditPrivate::FileSystemPathEditPrivate(FileSystemPathEdit *q, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it would be better if you insert line break before first param (instead of second one).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken.
@@ -357,6 +353,25 @@ OptionsDialog::OptionsDialog(QWidget *parent) | |||
m_ui->advPageLayout->addWidget(advancedSettings); | |||
connect(advancedSettings, SIGNAL(settingsChanged()), this, SLOT(enableApplyButton())); | |||
|
|||
m_ui->textFileLogPath->setDialogCaption(tr("Choose a save directory")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you set these properties in designer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I do not export the widget to Designer completely. Probably, with only a single custom widget in the app it does not make sense.
PR updated: taken two last suggestions from the reviewers. @sledgehammer999, do you want to say anything? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
@sledgehammer999, should I count a week? Are you interested in this? |
OK, a week has passed, merging. |
Might be related to this PR, I got the following when opening options dialog:
|
Damn, we should prohibit using old connect syntax in new code to prevent this bugs in future. |
I'm sorry for that. See #6795, please. |
<width>779</width> | ||
<height>591</height> | ||
<width>1116</width> | ||
<height>838</height> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing the default dialog size to be large than ever, is it intentional?
Do you mind we switch back?
Did you consider the cases where the users manually writes invalid file paths? |
The combinations of
QLineEdit
orQComboBox
with a browse button for file system paths editing most likely results in selecting files or dirs via the button and a file dialog. However, typing with auto completion might provide a better alternative. This PR implements it in the standard for Qt way, usingQCompleter
andQFileSystemModel
.The PR adds
FileSystemPathLineEdit
andFileSystemPathComboEdit
classes (share most of the implementation) that provides widgets for editing file names withQLineEdit
orQComboBox
(in editable mode). The widgets also contain the "Browse" button, which launches a file dialog. Properties of the dialog (title, file filter, etc.) are specified asFileSystemPathEdit
class properties.The class also uses
Utils::Fs::fromNativePath()
andUtils::Fs::toNativePath()
internally thus eliminating the need to use them with each widget explicitly.Screenshots show example for Add torrent dialog: