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() );
45 settings.
setValue( QStringLiteral(
"qgis/lastFindRecursiveFolder" ), filePath );
46 mFindButton->setEnabled( !filePath.isEmpty() );
50void QgsFindFilesByPatternWidget::find()
52 mFindButton->setText( tr(
"Cancel" ) );
53 disconnect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::find );
54 connect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::cancel );
57 mResultsTable->setRowCount( 0 );
60 const QString pattern = mPatternLineEdit->text();
61 const QString path = mFolderWidget->filePath();
63 const QDir startDir( path );
66 if ( !pattern.isEmpty() )
69 QDirIterator it( path, filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, mRecursiveCheckBox->isChecked() ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags );
70 while ( it.hasNext() )
72 const QString fullPath = it.next();
75 const QFileInfo fi( fullPath );
77 const QString toolTip = QDir::toNativeSeparators( fullPath );
78 const QString fileName = fi.fileName();
79 const QString relativeDirectory = QDir::toNativeSeparators( startDir.relativeFilePath( fi.dir().absolutePath() ) );
80 const QString fullDirectory = QDir::toNativeSeparators( fi.dir().absolutePath() );
82 QTableWidgetItem *fileNameItem =
new QTableWidgetItem( fileName );
83 fileNameItem->setToolTip( toolTip );
84 fileNameItem->setFlags( fileNameItem->flags() ^ Qt::ItemIsEditable );
86 QTableWidgetItem *directoryItem =
new QTableWidgetItem( relativeDirectory );
87 directoryItem->setToolTip( fullDirectory );
88 directoryItem->setFlags( directoryItem->flags() ^ Qt::ItemIsEditable );
90 const int row = mResultsTable->rowCount();
91 mResultsTable->insertRow( row );
92 mResultsTable->setItem( row, 0, fileNameItem );
93 mResultsTable->setItem( row, 1, directoryItem );
95 QCoreApplication::processEvents();
100 mFindButton->setText( tr(
"Find Files" ) );
101 disconnect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::cancel );
102 connect( mFindButton, &QPushButton::clicked,
this, &QgsFindFilesByPatternWidget::find );
107void QgsFindFilesByPatternWidget::cancel()
120 setWindowTitle( tr(
"Find Files by Pattern" ) );
121 setObjectName(
"QgsFindFilesByPatternDialog" );
125 QVBoxLayout *vLayout =
new QVBoxLayout();
128 vLayout->addWidget( mWidget );
129 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
130 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
131 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
132 vLayout->addWidget( mButtonBox );
133 setLayout( vLayout );
135 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
137 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !
files.empty() );
143 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.