Skip to content

Commit

Permalink
Refresh DP_Product dir when changing RUN
Browse files Browse the repository at this point in the history
This commit changes the DP panel's
DP product parent dir when the
RUN changes, so one can quickly select
a DP after loading RUNs.
  • Loading branch information
keithvetter committed Aug 20, 2024
1 parent c730247 commit e25d0f6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 32 deletions.
84 changes: 54 additions & 30 deletions libkoviz/dptreewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DPTreeWidget::DPTreeWidget(const QString& timeName,
_msgLabel(0),
_searchBox(0)
{
_setupModel();
_setupModel(_dpDirName);

_gridLayout = new QGridLayout(parent);

Expand Down Expand Up @@ -97,12 +97,14 @@ DPTreeWidget::DPTreeWidget(const QString& timeName,
_msgLabel->hide();
_loadDPFiles();
}

connect(_runs, SIGNAL(runsRefreshed()),
this, SLOT(_runsRefreshed()));
}

DPTreeWidget::~DPTreeWidget()
{
delete _dpModel;
delete _dir;
delete _dpFilterModel;

foreach ( ProgramModel* program, _programModels ) {
Expand All @@ -111,49 +113,46 @@ DPTreeWidget::~DPTreeWidget()
_programModels.clear();
}

//
// DP File/Sys Model and Filter Proxy Model
//
void DPTreeWidget::_setupModel()
QString DPTreeWidget::_findDPDir(const QString &startDir)
{
_dir = new QDir(_dpDirName);
QDir* searchDir = new QDir(startDir);

// Change directory from RUN/MONTE dir to DP_Product dir (if possible)
bool isFound = false;
while ( 1 ) {
QString path1 = QDir::cleanPath(_dir->absolutePath());
QString path1 = QDir::cleanPath(searchDir->absolutePath());
QStringList dpDirFilter;
dpDirFilter << "DP_Product";
QStringList dpdirs = _dir->entryList(dpDirFilter);
QStringList dpdirs = searchDir->entryList(dpDirFilter);
if ( !dpdirs.isEmpty() ) {
_dir->cd(dpdirs.at(0));
searchDir->cd(dpdirs.at(0));
isFound = true;
break;
}
_dir->cdUp();
QString path2 = QDir::cleanPath(_dir->absolutePath());
searchDir->cdUp();
QString path2 = QDir::cleanPath(searchDir->absolutePath());
if ( path1 == path2 ) {
// Since cdUP returned same path, assume path1==path2=="/" (root)
break;
}
}

if ( isFound == false ) {
// No DP_Product dir found at or above data dir
// Search for DP_ files at or above data dir
delete _dir;
_dir = new QDir(_dpDirName);
// No DP_Product dir found at or above run dir
// Search for DP_ files at or above run dir
delete searchDir;
searchDir = new QDir(startDir);
while ( 1 ) {
QString path1 = QDir::cleanPath(_dir->absolutePath());
QString path1 = QDir::cleanPath(searchDir->absolutePath());
QStringList dpDirFilter;
dpDirFilter << "DP_*";
QStringList dps = _dir->entryList(dpDirFilter);
QStringList dps = searchDir->entryList(dpDirFilter);
if ( !dps.isEmpty() ) {
isFound = true;
break;
}
_dir->cdUp();
QString path2 = QDir::cleanPath(_dir->absolutePath());
searchDir->cdUp();
QString path2 = QDir::cleanPath(searchDir->absolutePath());
if ( path1 == path2 ) {
// Since cdUP returned same path, assume path1==path2=="/"(root)
break;
Expand All @@ -164,19 +163,19 @@ void DPTreeWidget::_setupModel()
if ( isFound == false ) {
// No DP_* files or Data_Product dirs found
// Try for parent SIM_ dir
delete _dir;
_dir = new QDir(_dpDirName);
delete searchDir;
searchDir = new QDir(startDir);
while ( 1 ) {
QString path1 = QDir::cleanPath(_dir->absolutePath());
QString path1 = QDir::cleanPath(searchDir->absolutePath());
QStringList simDirFilter;
simDirFilter << "SIM_*";
QStringList sims = _dir->entryList(simDirFilter);
QStringList sims = searchDir->entryList(simDirFilter);
if ( !sims.isEmpty() ) {
isFound = true;
break;
}
_dir->cdUp();
QString path2 = QDir::cleanPath(_dir->absolutePath());
searchDir->cdUp();
QString path2 = QDir::cleanPath(searchDir->absolutePath());
if ( path1 == path2 ) {
// Since cdUP returned same path, assume path1==path2=="/"(root)
break;
Expand All @@ -187,13 +186,26 @@ void DPTreeWidget::_setupModel()
if ( isFound == false ) {
// No DP_* files, Data_Product dirs or SIM_ dirs found
// Use directory above as last ditch try
delete _dir;
_dir = new QDir(_dpDirName);
_dir->cdUp();
delete searchDir;
searchDir = new QDir(startDir);
searchDir->cdUp();
}

QString dpDir = searchDir->absolutePath();
delete searchDir;

return dpDir;

}

//
// DP File/Sys Model and Filter Proxy Model
//
void DPTreeWidget::_setupModel(const QString& dpSearchDir)
{
QString dpDir = _findDPDir(dpSearchDir);
_dpModel = new QFileSystemModel;
_dpModelRootIdx = _dpModel->setRootPath(_dir->path());
_dpModelRootIdx = _dpModel->setRootPath(dpDir);
QStringList filters;
//filters << "DP_*" << "SET_*"; // _dpFilterModel does additional filtering
_dpModel->setNameFilters(filters);
Expand Down Expand Up @@ -314,6 +326,18 @@ void DPTreeWidget::_tvModelAboutToBeReset()
_tvCurveModels.clear();
}

void DPTreeWidget::_runsRefreshed()
{
if ( _runs->runPaths().isEmpty() ) {
return;
}
QString dpDir = _findDPDir(_runs->runPaths().at(0));
_dpModelRootIdx = _dpModel->setRootPath(dpDir);
QModelIndex sourceIndex = _dpModel->index(dpDir);
QModelIndex proxyIndex = _dpFilterModel->mapFromSource(sourceIndex);
_dpTreeView->setRootIndex(proxyIndex);
}

//
// The DP tree that this creates must be coordinated with
// * plotbookmodel
Expand Down
5 changes: 3 additions & 2 deletions libkoviz/dptreewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public slots:
QString _dpDirName;
QStringList _dpFiles;
Runs* _runs;
QDir* _dir;
QStringList _runPaths;
PlotBookModel* _bookModel;
QItemSelectionModel* _bookSelectModel;
Expand All @@ -85,7 +84,8 @@ public slots:
QList<ProgramModel*> _programModels;
QList<CurveModel*> _tvCurveModels; // list for tv model reset

void _setupModel();
QString _findDPDir(const QString& startDir);
void _setupModel(const QString &dpSearchDir);
void _createDP(const QString& dpfile);
void _createDPPages(const QString& dpfile);
void _createDPTables(const QString& dpfile);
Expand Down Expand Up @@ -114,6 +114,7 @@ private slots:
void _setMsgLabel(const QString& msg);
void _tvModelRowAppended(const QModelIndex &parent,int start,int end);
void _tvModelAboutToBeReset();
void _runsRefreshed();

};

Expand Down

0 comments on commit e25d0f6

Please sign in to comment.