LCOV - code coverage report
Current view: top level - dbe/src/structure - CustomFileView.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 179 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 15 0

            Line data    Source code
       1              : // DUNE DAQ modification notice:
       2              : // This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
       3              : // Fork baseline commit: dbe-02-12-17 (2022-05-12).
       4              : // Renamed since fork: no.
       5              : 
       6              : /// Including QT Headers
       7              : #include "dbe/FileInfo.hpp"
       8              : #include "dbe/ui_constants.hpp"
       9              : 
      10              : #include <QAction>
      11              : #include <QContextMenuEvent>
      12              : #include <QHBoxLayout>
      13              : #include <QHeaderView>
      14              : #include <QLabel>
      15              : #include <QMenu>
      16              : #include <QMessageBox>
      17              : #include <QShortcut>
      18              : /// Including DBE
      19              : #include "dbe/CustomFileView.hpp"
      20              : #include "dbe/IncludeFileWidget.hpp"
      21              : 
      22            0 : dbe::CustomFileView::CustomFileView(QWidget* parent)
      23              :   : QTableView(parent)
      24            0 :   , ContextMenu(nullptr)
      25            0 :   , LaunchIncludeEditor(nullptr)
      26            0 :   , HideReadOnlyFiles(nullptr)
      27            0 :   , FindFile(nullptr)
      28            0 :   , FindFileDialog(nullptr)
      29            0 :   , LineEdit(nullptr)
      30            0 :   , NextButton(nullptr)
      31            0 :   , GoButton(nullptr)
      32              : {
      33            0 :   ConnectActions();
      34            0 :   CreateContextMenu();
      35            0 :   setSelectionBehavior(SelectionBehavior::SelectRows);
      36            0 :   horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::Stretch);
      37            0 :   setSortingEnabled(true);
      38              : 
      39            0 :   connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(file_info_slot(QModelIndex)));
      40            0 : }
      41              : 
      42              : void
      43            0 : dbe::CustomFileView::CreateActions()
      44              : {
      45            0 :   LaunchIncludeEditor = new QAction(tr("Add/Remove Files"), this);
      46            0 :   LaunchIncludeEditor->setShortcutContext(Qt::WidgetShortcut);
      47            0 :   connect(LaunchIncludeEditor, SIGNAL(triggered()), this, SLOT(LaunchIncludeEditorSlot()));
      48            0 :   ContextMenu->addAction(LaunchIncludeEditor);
      49              : 
      50            0 :   m_file_info_action = new QAction(tr("File &information"));
      51            0 :   connect(m_file_info_action, SIGNAL(triggered()), this, SLOT(file_info_slot()));
      52            0 :   ContextMenu->addAction(m_file_info_action);
      53              : 
      54            0 :   HideReadOnlyFiles = new QAction(tr("Hide Read Only Files"), this);
      55            0 :   HideReadOnlyFiles->setShortcutContext(Qt::WidgetShortcut);
      56            0 :   HideReadOnlyFiles->setCheckable(true);
      57            0 :   HideReadOnlyFiles->setChecked(false);
      58            0 :   connect(HideReadOnlyFiles, SIGNAL(triggered(bool)), this, SLOT(HideReadOnlyFilesSlot(bool)));
      59            0 :   ContextMenu->addAction(HideReadOnlyFiles);
      60              : 
      61            0 :   FindFile = new QAction(tr("Find File"), this);
      62            0 :   FindFile->setShortcut(QKeySequence(tr("Ctrl+F")));
      63            0 :   FindFile->setShortcutContext(Qt::WidgetShortcut);
      64            0 :   connect(FindFile, SIGNAL(triggered()), this, SLOT(FindFileSlot()));
      65              :   //  connect ( Shortcut, SIGNAL ( activated() ), this, SLOT ( FindFileSlot() ) );
      66            0 :   ContextMenu->addAction(FindFile);
      67            0 : }
      68              : 
      69              : void
      70            0 : dbe::CustomFileView::ConnectActions()
      71              : {
      72            0 :   connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(ChangeSelection(QModelIndex)));
      73            0 : }
      74              : 
      75              : void
      76            0 : dbe::CustomFileView::CreateContextMenu()
      77              : {
      78            0 :   if (ContextMenu == nullptr) {
      79            0 :     ContextMenu = new QMenu(this);
      80            0 :     CreateActions();
      81              :   }
      82            0 : }
      83              : 
      84              : void
      85            0 : dbe::CustomFileView::contextMenuEvent(QContextMenuEvent* Event)
      86              : {
      87            0 :   QModelIndex index = indexAt(Event->pos());
      88              : 
      89            0 :   if (index.isValid()) {
      90            0 :     if (model()->data(model()->index(index.row(), 2)).toString() == "RO") {
      91            0 :       ContextMenu->actions().at(0)->setVisible(false);
      92              :     } else {
      93            0 :       ContextMenu->actions().at(0)->setVisible(true);
      94              :     }
      95            0 :     ContextMenu->actions().at(1)->setVisible(true);
      96              : 
      97            0 :     setCurrentIndex(index);
      98            0 :     selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
      99              :   } else {
     100            0 :     ContextMenu->actions().at(0)->setVisible(false);
     101            0 :     ContextMenu->actions().at(1)->setVisible(false);
     102              :   }
     103            0 :   ContextMenu->exec(Event->globalPos());
     104            0 : }
     105              : 
     106              : void
     107            0 : dbe::CustomFileView::GoToFile()
     108              : {
     109            0 :   ListIndex = 0;
     110            0 :   ListOfMatch.clear();
     111              : 
     112            0 :   QString UserType = LineEdit->text();
     113              : 
     114            0 :   if (UserType.isEmpty()) {
     115            0 :     return;
     116              :   }
     117              : 
     118            0 :   QAbstractItemModel* Model = model();
     119              : 
     120            0 :   if (Model != nullptr) {
     121            0 :     QVariant StringCriterium = QVariant(UserType);
     122              : 
     123            0 :     QModelIndex find_by_name = Model->index(0, 0);
     124            0 :     QModelIndex find_by_path = Model->index(0, 1);
     125              : 
     126            0 :     Qt::MatchFlags options = Qt::MatchContains;
     127              : 
     128            0 :     if (CaseSensitiveCheckBox->isChecked()) {
     129            0 :       options = options | Qt::MatchCaseSensitive;
     130              :     }
     131              : 
     132            0 :     if (WholeWordCheckBox->isChecked()) {
     133            0 :       options = Qt::MatchExactly;
     134              :     }
     135              : 
     136            0 :     ListOfMatch = Model->match(find_by_name, Qt::DisplayRole, StringCriterium, 1000, options);
     137              : 
     138            0 :     ListOfMatch.append(Model->match(find_by_path, Qt::DisplayRole, StringCriterium, 1000, options));
     139              : 
     140            0 :     if (ListOfMatch.size() > 0) {
     141            0 :       ListIndex = 0;
     142            0 :       scrollTo(ListOfMatch.value(ListIndex), QAbstractItemView::EnsureVisible);
     143            0 :       selectRow(ListOfMatch.value(ListIndex).row());
     144            0 :       resizeColumnToContents(ListIndex);
     145              : 
     146            0 :       GoButton->setDisabled(true);
     147            0 :       NextButton->setEnabled(true);
     148              : 
     149            0 :       disconnect(LineEdit, SIGNAL(returnPressed()), this, SLOT(GoToFile()));
     150            0 :       connect(LineEdit, SIGNAL(returnPressed()), this, SLOT(GoToNext()));
     151            0 :       ChangeSelection(ListOfMatch.at(ListIndex));
     152              :     }
     153            0 :   }
     154            0 : }
     155              : 
     156              : void
     157            0 : dbe::CustomFileView::GoToNext()
     158              : {
     159            0 :   if ((LineEdit->text()).isEmpty()) {
     160            0 :     ListIndex = 0;
     161            0 :     ListOfMatch.clear();
     162            0 :     return;
     163              :   }
     164              : 
     165            0 :   if (ListOfMatch.size() > 0) {
     166            0 :     if ((++ListIndex) < ListOfMatch.size()) {
     167            0 :       scrollTo(ListOfMatch.value(ListIndex), QAbstractItemView::EnsureVisible);
     168            0 :       selectRow(ListOfMatch.value(ListIndex).row());
     169            0 :       resizeColumnToContents(ListIndex);
     170            0 :       ChangeSelection(ListOfMatch.at(ListIndex));
     171              :     } else {
     172            0 :       ListIndex = 0;
     173            0 :       scrollTo(ListOfMatch.value(ListIndex), QAbstractItemView::EnsureVisible);
     174            0 :       selectRow(ListOfMatch.value(ListIndex).row());
     175            0 :       resizeColumnToContents(ListIndex);
     176            0 :       ChangeSelection(ListOfMatch.at(ListIndex));
     177              :     }
     178              :   }
     179              : }
     180              : 
     181              : void
     182            0 : dbe::CustomFileView::FindFileSlot()
     183              : {
     184            0 :   if (FindFileDialog != nullptr) {
     185            0 :     delete FindFileDialog;
     186            0 :     FindFileDialog = nullptr;
     187              :   }
     188              : 
     189            0 :   FindFileDialog = new QDialog(this);
     190            0 :   FindFileDialog->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
     191            0 :   FindFileDialog->setToolTip("Type string to edit line and press Enter.");
     192            0 :   FindFileDialog->setWindowTitle("Search for a file name in the table");
     193              : 
     194            0 :   QHBoxLayout* FileLayout = new QHBoxLayout();
     195            0 :   QLabel* Label = new QLabel(QString("Find File:"));
     196            0 :   NextButton = new QPushButton("Next");
     197            0 :   GoButton = new QPushButton("Go !");
     198            0 :   LineEdit = new QLineEdit();
     199            0 :   LineEdit->setToolTip("Type string and press Enter");
     200              : 
     201            0 :   FileLayout->addWidget(Label);
     202            0 :   FileLayout->addWidget(LineEdit);
     203            0 :   FileLayout->addWidget(GoButton);
     204            0 :   FileLayout->addWidget(NextButton);
     205              : 
     206            0 :   QHBoxLayout* ButtonsLayout = new QHBoxLayout();
     207            0 :   WholeWordCheckBox = new QCheckBox("Whole String");
     208            0 :   CaseSensitiveCheckBox = new QCheckBox("Case Sensitive");
     209              : 
     210            0 :   ButtonsLayout->addWidget(WholeWordCheckBox);
     211            0 :   ButtonsLayout->addWidget(CaseSensitiveCheckBox);
     212              : 
     213            0 :   QVBoxLayout* FindDialogLayout = new QVBoxLayout();
     214            0 :   FindDialogLayout->addItem(FileLayout);
     215            0 :   FindDialogLayout->addItem(ButtonsLayout);
     216              : 
     217            0 :   FindFileDialog->setLayout(FindDialogLayout);
     218            0 :   FindFileDialog->show();
     219              :   // NextButton->setDisabled(true);
     220              : 
     221            0 :   connect(LineEdit, SIGNAL(textEdited(QString)), this, SLOT(EditedSearchString(QString)));
     222            0 :   connect(WholeWordCheckBox, SIGNAL(clicked()), this, SLOT(EditedSearchString()));
     223            0 :   connect(CaseSensitiveCheckBox, SIGNAL(clicked()), this, SLOT(EditedSearchString()));
     224              : 
     225            0 :   connect(LineEdit, SIGNAL(returnPressed()), this, SLOT(GoToFile()));
     226            0 :   connect(GoButton, SIGNAL(clicked()), this, SLOT(GoToFile()));
     227            0 :   connect(NextButton, SIGNAL(clicked()), this, SLOT(GoToNext()));
     228            0 : }
     229              : 
     230              : void
     231            0 : dbe::CustomFileView::file_info_slot()
     232              : {
     233            0 :   file_info_slot(currentIndex());
     234            0 : }
     235              : 
     236              : void
     237            0 : dbe::CustomFileView::file_info_slot(QModelIndex index)
     238              : {
     239            0 :   QString file = model()->data(model()->index(index.row(), 0, index.parent())).toString();
     240            0 :   QString path = model()->data(model()->index(index.row(), 1, index.parent())).toString();
     241            0 :   auto full_name = path + "/" + file;
     242              : 
     243            0 :   FileInfo::show_file_info(full_name);
     244            0 : }
     245              : 
     246              : void
     247            0 : dbe::CustomFileView::LaunchIncludeEditorSlot()
     248              : {
     249            0 :   QModelIndex index = currentIndex();
     250            0 :   QString file = model()->data(model()->index(index.row(), 0, index.parent())).toString();
     251            0 :   QString path = model()->data(model()->index(index.row(), 1, index.parent())).toString();
     252            0 :   auto full_name = path + "/" + file;
     253            0 :   auto* file_widget = new IncludeFileWidget(full_name);
     254              : 
     255            0 :   file_widget->show();
     256            0 : }
     257              : 
     258              : void
     259            0 : dbe::CustomFileView::HideReadOnlyFilesSlot(bool Hide)
     260              : {
     261            0 :   for (int i = 0; i < model()->rowCount(); ++i) {
     262            0 :     if (model()->data(model()->index(i, 2)).toString() == "RO") {
     263            0 :       if (Hide) {
     264            0 :         hideRow(i);
     265              :       } else {
     266            0 :         showRow(i);
     267              :       }
     268              :     }
     269              :   }
     270            0 : }
     271              : 
     272              : void
     273            0 : dbe::CustomFileView::EditedSearchString(QString Text)
     274              : {
     275            0 :   Q_UNUSED(Text)
     276              : 
     277            0 :   connect(LineEdit, SIGNAL(returnPressed()), this, SLOT(GoToFile()));
     278            0 :   disconnect(LineEdit, SIGNAL(returnPressed()), this, SLOT(GoToNext()));
     279              : 
     280            0 :   GoButton->setEnabled(true);
     281            0 :   NextButton->setDisabled(true);
     282            0 : }
     283              : 
     284              : void
     285            0 : dbe::CustomFileView::EditedSearchString()
     286              : {
     287            0 :   QString Dummy("Dummy");
     288            0 :   EditedSearchString(Dummy);
     289            0 : }
     290              : 
     291              : void
     292            0 : dbe::CustomFileView::ChangeSelection(QModelIndex index)
     293              : {
     294            0 :   QString file = model()->data(model()->index(index.row(), 0, index.parent())).toString();
     295            0 :   QString path = model()->data(model()->index(index.row(), 1, index.parent())).toString();
     296            0 :   auto full_name = path + "/" + file;
     297            0 :   emit stateChanged(full_name);
     298            0 : }
        

Generated by: LCOV version 2.0-1