17#include "moc_qgsfindfilesbypatternwidget.cpp"
22#include <QDirIterator>
23#include <QDialogButtonBox>
32 mResultsTable->setColumnCount( 2 );
34 mResultsTable->setHorizontalHeaderLabels( QStringList() << tr(
"File" ) << tr(
"Directory" ) );
35 mResultsTable->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
36 mResultsTable->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
38 connect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::find );
41 mFolderWidget->setFilePath( settings.
value( QStringLiteral(
"qgis/lastFindRecursiveFolder" ) ).toString() );
42 mFindButton->setEnabled( !mFolderWidget->filePath().isEmpty() );
46 settings.
setValue( QStringLiteral(
"qgis/lastFindRecursiveFolder" ), filePath );
47 mFindButton->setEnabled( !filePath.isEmpty() );
52void QgsFindFilesByPatternWidget::find()
54 mFindButton->setText( tr(
"Cancel" ) );
55 disconnect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::find );
56 connect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::cancel );
59 mResultsTable->setRowCount( 0 );
62 const QString pattern = mPatternLineEdit->text();
63 const QString path = mFolderWidget->filePath();
65 const QDir startDir( path );
68 if ( !pattern.isEmpty() )
71 QDirIterator it( path, filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, mRecursiveCheckBox->isChecked() ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags );
72 while ( it.hasNext() )
74 const QString fullPath = it.next();
77 const QFileInfo fi( fullPath );
79 const QString toolTip = QDir::toNativeSeparators( fullPath );
80 const QString fileName = fi.fileName();
81 const QString relativeDirectory = QDir::toNativeSeparators( startDir.relativeFilePath( fi.dir().absolutePath() ) );
82 const QString fullDirectory = QDir::toNativeSeparators( fi.dir().absolutePath() );
84 QTableWidgetItem *fileNameItem =
new QTableWidgetItem( fileName );
85 fileNameItem->setToolTip( toolTip );
86 fileNameItem->setFlags( fileNameItem->flags() ^ Qt::ItemIsEditable );
88 QTableWidgetItem *directoryItem =
new QTableWidgetItem( relativeDirectory );
89 directoryItem->setToolTip( fullDirectory );
90 directoryItem->setFlags( directoryItem->flags() ^ Qt::ItemIsEditable );
92 const int row = mResultsTable->rowCount();
93 mResultsTable->insertRow( row );
94 mResultsTable->setItem( row, 0, fileNameItem );
95 mResultsTable->setItem( row, 1, directoryItem );
97 QCoreApplication::processEvents();
102 mFindButton->setText( tr(
"Find Files" ) );
103 disconnect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::cancel );
104 connect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::find );
109void QgsFindFilesByPatternWidget::cancel()
122 setWindowTitle( tr(
"Find Files by Pattern" ) );
123 setObjectName(
"QgsFindFilesByPatternDialog" );
127 QVBoxLayout *vLayout =
new QVBoxLayout();
130 vLayout->addWidget( mWidget );
131 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
132 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
133 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
134 vLayout->addWidget( mButtonBox );
135 setLayout( vLayout );
137 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
140 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !
files.empty() );
146 return mWidget->
files();
QStringList files() const
Returns the list of files found by the dialog.
QgsFindFilesByPatternDialog(QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor for QgsFindFilesByPatternDialog, with the specified parent widget.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.