-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Martin Ribelotta <[email protected]>
- Loading branch information
1 parent
669791b
commit 20ce25d
Showing
9 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "findandopenfiledialog.h" | ||
#include "ui_findandopenfiledialog.h" | ||
|
||
#include <QDirIterator> | ||
#include <QStandardItemModel> | ||
#include <QStringListModel> | ||
#include <QPushButton> | ||
|
||
FindAndOpenFileDialog::FindAndOpenFileDialog(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::FindAndOpenFileDialog) | ||
{ | ||
ui->setupUi(this); | ||
ui->buttonBox->button(QDialogButtonBox::Open)->setDisabled(true); | ||
connect(ui->fileList, &QAbstractItemView::activated, this, &QDialog::accept); | ||
} | ||
|
||
FindAndOpenFileDialog::~FindAndOpenFileDialog() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void FindAndOpenFileDialog::setFileList(const QString& prefix, const QStringList &list) | ||
{ | ||
if (ui->fileList->model()) | ||
ui->fileList->model()->deleteLater(); | ||
auto m = new QStandardItemModel(this); | ||
for (const auto& e: list) { | ||
auto item = new QStandardItem{"..." + QString{e}.remove(prefix)}; | ||
item->setData(e, Qt::UserRole + 1); | ||
m->appendRow(item); | ||
} | ||
ui->fileList->setModel(m); | ||
ui->buttonBox->button(QDialogButtonBox::Open)->setDisabled(list.isEmpty()); | ||
} | ||
|
||
QString FindAndOpenFileDialog::selectedFile() const | ||
{ | ||
auto idx = ui->fileList->currentIndex(); | ||
return ui->fileList->model()->data(idx, Qt::UserRole + 1).toString(); | ||
} | ||
|
||
QStringList FindAndOpenFileDialog::findFilesInPath(const QString &file, const QString &path) | ||
{ | ||
QStringList list; | ||
QDirIterator it(path, { file }, QDir::NoDotAndDotDot | QDir::Files, QDirIterator::Subdirectories); | ||
while (it.hasNext()) { | ||
list.append(it.next()); | ||
} | ||
return list; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef FINDANDOPENFILEDIALOG_H | ||
#define FINDANDOPENFILEDIALOG_H | ||
|
||
#include <QDialog> | ||
|
||
namespace Ui { | ||
class FindAndOpenFileDialog; | ||
} | ||
|
||
class FindAndOpenFileDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit FindAndOpenFileDialog(QWidget *parent = nullptr); | ||
~FindAndOpenFileDialog(); | ||
|
||
void setFileList(const QString &prefix, const QStringList &list); | ||
QString selectedFile() const; | ||
|
||
static QStringList findFilesInPath(const QString& file, const QString& path); | ||
|
||
private: | ||
Ui::FindAndOpenFileDialog *ui; | ||
}; | ||
|
||
#endif // FINDANDOPENFILEDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>FindAndOpenFileDialog</class> | ||
<widget class="QDialog" name="FindAndOpenFileDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>582</width> | ||
<height>355</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Select file to open</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QListView" name="fileList"> | ||
<property name="editTriggers"> | ||
<set>QAbstractItemView::NoEditTriggers</set> | ||
</property> | ||
<property name="alternatingRowColors"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Open</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>FindAndOpenFileDialog</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>FindAndOpenFileDialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters