LCOV - code coverage report
Current view: top level - dbe/src/structure - CustomFileView.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 200 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 15 0

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

Generated by: LCOV version 2.0-1