diff --git a/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.cpp b/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.cpp index d8c0b4c840..926163a42c 100644 --- a/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.cpp +++ b/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.cpp @@ -21,6 +21,7 @@ #include "RiaEnsembleNameTools.h" #include "RiaFilePathTools.h" #include "RiaGuiApplication.h" +#include "RiaStdStringTools.h" #include "RiaStringListSerializer.h" #include "RiuFileDialogTools.h" @@ -184,6 +185,9 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog( QWidget* parent, con m_searchRootContentLabel = new QLabel(); m_findOrCancelButton = new QPushButton(); m_fileTreeView = new QTreeView(); + m_treeViewFilterLabel = new QLabel( "Text Filter" ); + m_treeViewFilterLineEdit = new QLineEdit( "1-5,10" ); + m_treeViewFilterButton = new QPushButton( "Apply" ); m_buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel ); @@ -203,6 +207,9 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog( QWidget* parent, con this, SLOT( slotFileListCustomMenuRequested( const QPoint& ) ) ); + connect( m_treeViewFilterButton, SIGNAL( clicked() ), this, SLOT( slotFilterTreeViewClicked() ) ); + connect( m_treeViewFilterLineEdit, &QLineEdit::returnPressed, m_treeViewFilterButton, &QPushButton::click ); + connect( m_browseButton, SIGNAL( clicked() ), this, SLOT( slotBrowseButtonClicked() ) ); connect( m_findOrCancelButton, SIGNAL( clicked() ), this, SLOT( slotFindOrCancelButtonClicked() ) ); @@ -282,8 +289,11 @@ RicRecursiveFileSearchDialog::RicRecursiveFileSearchDialog( QWidget* parent, con outputGridLayout->addWidget( m_searchRootLabel, 1, 0 ); outputGridLayout->addWidget( m_searchRootContentLabel, 1, 1 ); - // outputGridLayout->addWidget(m_fileListLabel, 2, 0); - outputGridLayout->addWidget( m_fileTreeView, 2, 0, 1, 3 ); + outputGridLayout->addWidget( m_treeViewFilterLabel, 2, 0 ); + outputGridLayout->addWidget( m_treeViewFilterLineEdit, 2, 1 ); + outputGridLayout->addWidget( m_treeViewFilterButton, 2, 3 ); + + outputGridLayout->addWidget( m_fileTreeView, 3, 0, 1, 3 ); m_outputGroup->setLayout( outputGridLayout ); @@ -950,7 +960,8 @@ void RicRecursiveFileSearchDialog::slotFindOrCancelButtonClicked() } setOkButtonEnabled( !m_foundFiles.isEmpty() ); - m_buttons->button( QDialogButtonBox::Ok )->setDefault( true ); + + m_treeViewFilterButton->setDefault( true ); } else { @@ -958,14 +969,64 @@ void RicRecursiveFileSearchDialog::slotFindOrCancelButtonClicked() } } -// Function to collect checked items from the model -void getCheckedItems( QStandardItem* root, QStandardItem* parentItem, const QString& prefix, QStringList& checkedItems ) +namespace +{ +// Get all first level items, usually the ensemble items +auto firstLevelItems = []( QStandardItem* rootItem ) -> QList +{ + QList firstLevelItems; + + for ( int i = 0; i < rootItem->rowCount(); ++i ) + { + QStandardItem* item = rootItem->child( i ); + if ( item ) + { + firstLevelItems.append( item ); + } + } + + return firstLevelItems; +}; + +void uncheckAllItems( QStandardItem* parentItem ) +{ + if ( !parentItem ) return; + + for ( int i = 0; i < parentItem->rowCount(); ++i ) + { + auto childItem = parentItem->child( i ); + if ( childItem && childItem->isCheckable() ) + { + childItem->setCheckState( Qt::Unchecked ); + } + + uncheckAllItems( childItem ); + } +} + +void findItemsMatching( QStandardItem* parentItem, const QString& substring, QList& matchingItems ) +{ + if ( !parentItem ) return; + + for ( int i = 0; i < parentItem->rowCount(); ++i ) + { + auto childItem = parentItem->child( i ); + if ( childItem && childItem->text().contains( substring, Qt::CaseInsensitive ) ) + { + matchingItems.append( childItem ); + } + + findItemsMatching( childItem, substring, matchingItems ); + } +} + +void getTextForCheckedItems( QStandardItem* root, QStandardItem* parentItem, const QString& prefix, QStringList& checkedItems ) { if ( !parentItem ) return; for ( int i = 0; i < parentItem->rowCount(); ++i ) { - QStandardItem* childItem = parentItem->child( i ); + auto childItem = parentItem->child( i ); if ( childItem && childItem->isCheckable() && childItem->checkState() == Qt::Checked ) { if ( parentItem != root ) @@ -973,7 +1034,35 @@ void getCheckedItems( QStandardItem* root, QStandardItem* parentItem, const QStr checkedItems.append( prefix + childItem->text() ); } - getCheckedItems( root, childItem, prefix, checkedItems ); + getTextForCheckedItems( root, childItem, prefix, checkedItems ); + } + } +} +} // namespace + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicRecursiveFileSearchDialog::slotFilterTreeViewClicked() +{ + auto items = firstLevelItems( m_filePathModel.invisibleRootItem() ); + for ( auto item : items ) + { + uncheckAllItems( item ); + } + + QString filterText = m_treeViewFilterLineEdit->text(); + auto values = RiaStdStringTools::valuesFromRangeSelection( filterText.toStdString() ); + + for ( auto val : values ) + { + QString searchString = "realization-" + QString::number( val ); + + QList matchingItems; + findItemsMatching( m_filePathModel.invisibleRootItem(), searchString, matchingItems ); + for ( auto item : matchingItems ) + { + item->setCheckState( Qt::Checked ); } } } @@ -984,7 +1073,7 @@ void getCheckedItems( QStandardItem* root, QStandardItem* parentItem, const QStr void RicRecursiveFileSearchDialog::slotDialogOkClicked() { QStringList checkedItems; - getCheckedItems( m_filePathModel.invisibleRootItem(), m_filePathModel.invisibleRootItem(), rootDirWithEndSeparator(), checkedItems ); + getTextForCheckedItems( m_filePathModel.invisibleRootItem(), m_filePathModel.invisibleRootItem(), rootDirWithEndSeparator(), checkedItems ); m_foundFiles = checkedItems; accept(); diff --git a/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.h b/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.h index 6792aa8595..8a8ad42ede 100644 --- a/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.h +++ b/ApplicationLibCode/Commands/RicRecursiveFileSearchDialog.h @@ -124,6 +124,7 @@ private slots: void slotBrowseButtonClicked(); void slotUseRealizationStarClicked(); void slotFindOrCancelButtonClicked(); + void slotFilterTreeViewClicked(); void slotFileListCustomMenuRequested( const QPoint& point ); void slotCopyFileItemText(); @@ -159,6 +160,10 @@ private slots: QLabel* m_searchRootLabel; QLabel* m_searchRootContentLabel; + QLabel* m_treeViewFilterLabel; + QLineEdit* m_treeViewFilterLineEdit; + QPushButton* m_treeViewFilterButton; + QTreeView* m_fileTreeView; QStandardItemModel m_filePathModel;