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

            Line data    Source code
       1              : /// Including Qt
       2              : #include <QVBoxLayout>
       3              : #include <QHeaderView>
       4              : #include <QMimeData>
       5              : #include <qevent.h>
       6              : 
       7              : /// Including dbe
       8              : #include "dbe/TableTab.hpp"
       9              : #include "dbe/MainWindow.hpp"
      10              : 
      11              : //------------------------------------------------------------------------------------------------------
      12              : /**
      13              :  * Construct a Tabletab and let everything unitialized until first use
      14              :  *
      15              :  * Set the geometry and operational properties of the object
      16              :  *
      17              :  * @param parent a pointer to the parent widget
      18              :  */
      19            0 : dbe::TableTab::TableTab ( QWidget * parent )
      20              :   : QWidget ( parent ),
      21            0 :     this_model ( nullptr ),
      22            0 :     this_filter ( nullptr ),
      23            0 :     this_delegate ( nullptr ),
      24            0 :     this_view ( nullptr )
      25              : {
      26            0 :   this_view = new CustomTableView();
      27              :   /// Adjusting layout
      28            0 :   QVBoxLayout * TabLayout = new QVBoxLayout ( this );
      29            0 :   TabLayout->addWidget ( this_view );
      30            0 :   this_view->hide();
      31            0 :   setAcceptDrops ( true );
      32            0 :   this_holder = dynamic_cast<QTabWidget *> ( parent );
      33            0 : }
      34              : 
      35            0 : dbe::TableTab::~TableTab()
      36              : {
      37            0 :   delete this_model;
      38            0 :   delete this_filter;
      39            0 :   delete this_delegate;
      40            0 :   delete this_view;
      41            0 : }
      42              : //------------------------------------------------------------------------------------------------------
      43              : 
      44              : //------------------------------------------------------------------------------------------------------
      45            0 : void dbe::TableTab::create_models()
      46              : {
      47              : 
      48            0 :   if ( this_model == nullptr )
      49              :   {
      50            0 :     this_model = new dbe::models::table();
      51            0 :     connect ( this, SIGNAL ( sig_data_dropped ( QMimeData const &, Qt::DropAction ) ),
      52              :               this_model,
      53              :               SLOT ( slot_data_dropped ( QMimeData const &, Qt::DropAction ) ) );
      54              :   }
      55              : 
      56            0 :   this_delegate = this_delegate == nullptr ? new CustomDelegate() : this_delegate;
      57            0 :   this_filter = this_filter == nullptr ? new dbe::models::tableselection() : this_filter;
      58            0 : }
      59              : 
      60            0 : void dbe::TableTab::reset_models()
      61              : {
      62            0 :   this_model->ResetModel();
      63            0 :   this_filter->ResetModel();
      64            0 : }
      65              : 
      66            0 : void dbe::TableTab::CreateModels()
      67              : {
      68            0 :   if ( this_model == nullptr )
      69              :   {
      70            0 :     create_models();
      71              :   }
      72              :   else
      73              :   {
      74            0 :     reset_models();
      75              :   }
      76              : 
      77            0 :   connect ( this_model, SIGNAL ( ResetTab() ), this, SLOT ( ResetTabView() ) );
      78            0 : }
      79              : //------------------------------------------------------------------------------------------------------
      80              : 
      81              : //------------------------------------------------------------------------------------------------------
      82            0 : void dbe::TableTab::DisconnectView()
      83              : {
      84            0 :   this_view->setModel ( NULL );
      85            0 : }
      86              : 
      87            0 : void dbe::TableTab::ResetTableView()
      88              : {
      89            0 :   this_filter->setSourceModel ( this_model );
      90              : 
      91            0 :   this_view->setItemDelegate ( this_delegate );
      92            0 :   this_view->setModel ( this_filter );
      93            0 :   this_view->show();
      94              : 
      95            0 :   ResizeHeaders();
      96            0 : }
      97              : 
      98            0 : void dbe::TableTab::ResizeHeaders()
      99              : {
     100              :     // TODO: at the moment the resize of columns creates too large columns when several data are in a cell
     101              :     //       the resize of rows is a little bit expensive with large tables
     102              :     //       to be re-evaluated
     103              :     //
     104              :     //  if ( this_view->model() != nullptr )
     105              :     //  {
     106              :     //      this_view->resizeRowsToContents();
     107              :     //      this_view->resizeColumnsToContents();
     108              :     //  }
     109            0 : }
     110              : 
     111            0 : void dbe::TableTab::ResetTabView()
     112              : {
     113            0 :   reset_models();
     114            0 :   ResetTableView();
     115            0 :   this_holder->setTabText ( this_holder->indexOf ( this ), this_model->get_class_name() );
     116            0 : }
     117              : //------------------------------------------------------------------------------------------------------
     118              : 
     119              : //------------------------------------------------------------------------------------------------------
     120              : /**
     121              :  * Capture event of the pointer entering the tabletab while dragging something
     122              :  *
     123              :  * @param event is a pointer to the associated qt event object
     124              :  */
     125            0 : void dbe::TableTab::dragEnterEvent ( QDragEnterEvent * event )
     126              : {
     127              : 
     128              :   // If there is nothing created then create as needed
     129            0 :   CreateModels();
     130              : 
     131              :   // Check that all mimetypes are supported
     132            0 :   for ( auto const & mimetype : this_model->mimeTypes() )
     133              :   {
     134            0 :     if ( not event->mimeData()->hasFormat( mimetype.toStdString().c_str() ) )
     135              :     {
     136            0 :       event->ignore();
     137            0 :       return;
     138              :     }
     139            0 :   }
     140              : 
     141              :   // Support only copy actions
     142            0 :   if ( event->proposedAction() != Qt::DropAction::CopyAction )
     143              :   {
     144              :     return;
     145              :   }
     146              : 
     147            0 :   event->acceptProposedAction();
     148              : 
     149              :   // connect signals
     150            0 :   MainWindow * mainwin = MainWindow::findthis();
     151            0 :   connect ( GetTableView(), SIGNAL ( OpenEditor ( tref ) ), mainwin,
     152              :             SLOT ( slot_launch_object_editor ( tref ) ), Qt::UniqueConnection );
     153            0 :   connect ( GetTableDelegate(), SIGNAL ( CreateObjectEditorSignal ( tref ) ), mainwin,
     154              :             SLOT ( slot_launch_object_editor ( tref ) ), Qt::UniqueConnection );
     155              : }
     156              : //------------------------------------------------------------------------------------------------------
     157              : 
     158              : //------------------------------------------------------------------------------------------------------
     159              : /**
     160              :  * Capture a mouse release event of a dragged object
     161              :  *
     162              :  * Properly emits a signal to the associated tablemodel, i.e. this is a thread safe operation
     163              :  *
     164              :  * @param event is a pointer to the associated qt event object
     165              :  */
     166            0 : void dbe::TableTab::dropEvent ( QDropEvent * event )
     167              : {
     168            0 :   emit sig_data_dropped ( *event->mimeData(), event->proposedAction() );
     169            0 : }
     170              : //------------------------------------------------------------------------------------------------------
     171              : 
     172              : //------------------------------------------------------------------------------------------------------
     173            0 : dbe::models::table * dbe::TableTab::GetTableModel() const
     174              : {
     175            0 :   return this_model;
     176              : }
     177              : 
     178            0 : dbe::models::tableselection * dbe::TableTab::GetTableFilter() const
     179              : {
     180            0 :   return this_filter;
     181              : }
     182              : 
     183            0 : dbe::CustomDelegate * dbe::TableTab::GetTableDelegate() const
     184              : {
     185            0 :   return this_delegate;
     186              : }
     187              : 
     188            0 : dbe::CustomTableView * dbe::TableTab::GetTableView() const
     189              : {
     190            0 :   return this_view;
     191              : }
     192              : //------------------------------------------------------------------------------------------------------
        

Generated by: LCOV version 2.0-1