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

            Line data    Source code
       1              : /// Include Qt Headers
       2              : #include <QValidator>
       3              : #include <QApplication>
       4              : #include <QMenu>
       5              : #include <QContextMenuEvent>
       6              : /// Include DBE
       7              : #include "dbe/string_attr_text_edit.hpp"
       8              : #include "dbe/StyleUtility.hpp"
       9              : 
      10            0 : dbe::string_attr_text_edit::string_attr_text_edit ( QWidget * parent, bool IsNull, bool IsMulti )
      11              :   : QTextEdit ( parent ),
      12            0 :     Valid ( false ),
      13            0 :     NullCheck ( IsNull ),
      14            0 :     CheckDefault ( true ),
      15            0 :     PopupMenu ( false ),
      16            0 :     IsMultiValue ( IsMulti ),
      17            0 :     ContextMenu ( nullptr ),
      18            0 :     Dec ( nullptr ),
      19            0 :     Oct ( nullptr ),
      20            0 :     Hex ( nullptr ),
      21            0 :     Validator ( nullptr )
      22              : {
      23            0 :   connect ( this, SIGNAL ( textChanged (  ) ), this,
      24              :             SLOT ( TryValidate (  ) ) );
      25              :   //this->setFixedHeight ( 30 );
      26              :   //this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
      27            0 : }
      28              : 
      29            0 : dbe::string_attr_text_edit::~string_attr_text_edit()
      30              : {
      31            0 :   if ( Validator != nullptr )
      32              :   {
      33            0 :     delete Validator;
      34              :   }
      35            0 : }
      36              : 
      37            0 : void dbe::string_attr_text_edit::SetNullCheck ( bool IsNull )
      38              : {
      39            0 :   NullCheck = IsNull;
      40              : 
      41            0 :   if ( NullCheck == false )
      42              :   {
      43            0 :     setPalette ( QApplication::palette ( this ) );
      44              :   }
      45            0 : }
      46              : 
      47            0 : void dbe::string_attr_text_edit::SetMultiCheck ( bool IsMulti )
      48              : {
      49            0 :   IsMultiValue = IsMulti;
      50            0 : }
      51              : 
      52            0 : bool dbe::string_attr_text_edit::IsNullCheck()
      53              : {
      54            0 :   return NullCheck;
      55              : }
      56              : 
      57            0 : bool dbe::string_attr_text_edit::IsValid()
      58              : {
      59            0 :   return Valid;
      60              : }
      61              : 
      62            0 : void dbe::string_attr_text_edit::SetCheckDefault ( bool Default )
      63              : {
      64            0 :   CheckDefault = Default;
      65            0 : }
      66              : 
      67            0 : void dbe::string_attr_text_edit::SetDefaultValue ( QString ValueDefault )
      68              : {
      69            0 :   DefaultValue = ValueDefault;
      70            0 : }
      71              : 
      72            0 : void dbe::string_attr_text_edit::ValidateText()
      73              : {
      74            0 : }
      75              : 
      76            0 : void dbe::string_attr_text_edit::SetLoadedDefaultFlag ( bool Loaded )
      77              : {
      78            0 :   setProperty ( "loadedDefaults", Loaded );
      79            0 : }
      80              : 
      81            0 : void dbe::string_attr_text_edit::SetValidator ( QValidator * ValidatorSet )
      82              : {
      83            0 :   Validator = ValidatorSet;
      84            0 : }
      85              : 
      86            0 : void dbe::string_attr_text_edit::SetPopupMenu()
      87              : {
      88            0 :   PopupMenu = true;
      89            0 : }
      90              : 
      91            0 : void dbe::string_attr_text_edit::CreateActions()
      92              : {
      93            0 :   Dec = new QAction ( tr ( "Dec" ), this );
      94            0 :   Dec->setShortcutContext ( Qt::WidgetShortcut );
      95            0 :   connect ( Dec, SIGNAL ( triggered() ), this, SLOT ( EmitDecSlot() ) );
      96            0 :   Dec->setCheckable ( true );
      97            0 :   Dec->setChecked ( false );
      98            0 :   ContextMenu->addAction ( Dec );
      99              : 
     100            0 :   Oct = new QAction ( tr ( "Oct" ), this );
     101            0 :   Oct->setShortcutContext ( Qt::WidgetShortcut );
     102            0 :   connect ( Oct, SIGNAL ( triggered() ), this, SLOT ( EmitOctSlot() ) );
     103            0 :   Oct->setCheckable ( true );
     104            0 :   Oct->setChecked ( false );
     105            0 :   ContextMenu->addAction ( Oct );
     106              : 
     107            0 :   Hex = new QAction ( tr ( "Hex" ), this );
     108            0 :   Hex->setShortcutContext ( Qt::WidgetShortcut );
     109            0 :   Hex->setCheckable ( true );
     110            0 :   Hex->setChecked ( false );
     111            0 :   connect ( Hex, SIGNAL ( triggered() ), this, SLOT ( EmitHexSlot() ) );
     112            0 :   ContextMenu->addAction ( Hex );
     113            0 : }
     114              : 
     115            0 : void dbe::string_attr_text_edit::TryValidate ( )
     116              : {
     117            0 :   QString tmp_st = this->toPlainText();
     118            0 :   int i = 0;
     119              : 
     120            0 :   if ( tmp_st.isEmpty() && NullCheck )
     121              :   {
     122            0 :     Valid = false;
     123              : 
     124            0 :     if ( !IsMultiValue )
     125              :     {
     126            0 :       this->setPalette ( StyleUtility::WarningStatusBarPallete );
     127            0 :       setToolTip ( QString ( "Field cannot be empty!" ) );
     128              :     }
     129              : 
     130            0 :     emit StringValidated(); // it is caught by EditStringAttrWidget
     131              :   }
     132            0 :   else if ( Validator != 0 )
     133              :   {
     134            0 :     if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Acceptable )
     135              :     {
     136            0 :       Valid = true;
     137            0 :       this->setPalette ( QApplication::palette ( this ) );
     138            0 :       setToolTip ( QString ( "This new object ID is unique" ) );
     139              :     }
     140            0 :     else if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Intermediate )
     141              :     {
     142            0 :       Valid = false;
     143            0 :       this->setPalette ( StyleUtility::AlertStatusBarPallete );
     144            0 :       setToolTip ( QString ( "This UID is already used" ) );
     145              :     }
     146              :   }
     147            0 :   else if ( Validator == 0 )
     148              :   {
     149            0 :     Valid = true;
     150            0 :     setPalette ( QApplication::palette ( this ) );
     151              : 
     152            0 :     if ( tmp_st == DefaultValue && CheckDefault )
     153              :     {
     154            0 :       this->setPalette ( StyleUtility::LoadedDefault );
     155              :     }
     156              :     else
     157              :     {
     158            0 :       this->setPalette ( QApplication::palette ( this ) );
     159              :     }
     160              : 
     161            0 :     emit StringValidated();
     162              :   }
     163            0 : }
     164              : 
     165            0 : void dbe::string_attr_text_edit::EmitDecSlot()
     166              : {
     167            0 :   Dec->setChecked ( true );
     168            0 :   Oct->setChecked ( false );
     169            0 :   Hex->setChecked ( false );
     170            0 :   emit DecChange();
     171            0 : }
     172              : 
     173            0 : void dbe::string_attr_text_edit::EmitOctSlot()
     174              : {
     175            0 :   Dec->setChecked ( false );
     176            0 :   Oct->setChecked ( true );
     177            0 :   Hex->setChecked ( false );
     178            0 :   emit OctChange();
     179            0 : }
     180              : 
     181            0 : void dbe::string_attr_text_edit::EmitHexSlot()
     182              : {
     183            0 :   Dec->setChecked ( false );
     184            0 :   Oct->setChecked ( false );
     185            0 :   Hex->setChecked ( true );
     186            0 :   emit HexChange();
     187            0 : }
     188              : 
     189            0 : void dbe::string_attr_text_edit::contextMenuEvent ( QContextMenuEvent * Event )
     190              : {
     191            0 :   if ( !PopupMenu )
     192              :   {
     193              :     return;
     194              :   }
     195              : 
     196            0 :   if ( ContextMenu == nullptr )
     197              :   {
     198            0 :     ContextMenu = new QMenu ( this );
     199            0 :     CreateActions();
     200              :   }
     201              : 
     202            0 :   ContextMenu->exec ( Event->globalPos() );
     203              : }
        

Generated by: LCOV version 2.0-1