LCOV - code coverage report
Current view: top level - dbe/src/widgets - ObjectCreator.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 361 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 29 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              : #include "dbe/ObjectCreator.hpp"
       7              : #include "dbe/StyleUtility.hpp"
       8              : #include "dbe/Validator.hpp"
       9              : #include "dbe/confaccessor.hpp"
      10              : #include "dbe/config_api.hpp"
      11              : #include "dbe/config_api_commands.hpp"
      12              : #include "dbe/config_api_graph.hpp"
      13              : #include "dbe/config_api_set.hpp"
      14              : #include "dbe/messenger.hpp"
      15              : #include "ui_ObjectCreator.h"
      16              : 
      17              : #include "logging/Logging.hpp"
      18              : 
      19              : #include <boost/scope_exit.hpp>
      20              : 
      21              : #include <QCloseEvent>
      22              : #include <QCompleter>
      23              : #include <QFileDialog>
      24              : #include <QFileInfo>
      25              : #include <QMenu>
      26              : #include <QMessageBox>
      27              : 
      28              : enum EditStates
      29              : {
      30              :   editorOk = 0,
      31              :   classNotSelected = 1,
      32              :   uidNotSet = 2,
      33              :   fileNotSet = 4,
      34              :   nullNotFilled = 8
      35              : };
      36              : 
      37              : //------------------------------------------------------------------------------------------
      38            0 : dbe::ObjectCreator::~ObjectCreator() = default;
      39              : //------------------------------------------------------------------------------------------
      40              : 
      41              : //------------------------------------------------------------------------------------------
      42              : /*
      43              :  * Create an object in a class
      44              :  */
      45            0 : dbe::ObjectCreator::ObjectCreator(dunedaq::conffwk::class_t const& cinfo, QWidget* parent)
      46              :   : QWidget(parent)
      47            0 :   , ui(new Ui::ObjectCreator)
      48            0 :   , this_object_class(cinfo)
      49            0 :   , this_target_object(nullptr)
      50            0 :   , this_relation(dunedaq::conffwk::relationship_t())
      51            0 :   , this_files(nullptr)
      52            0 :   , this_status_bar(nullptr)
      53            0 :   , this_state(0)
      54            0 :   , UidSet(false)
      55            0 :   , this_associated_editor(nullptr)
      56            0 :   , ContextMenu(nullptr)
      57            0 :   , this_is_temporary(false)
      58            0 :   , this_object_changed(false)
      59            0 :   , this_create_copy(false)
      60            0 :   , uuid(QUuid::createUuid())
      61              : {
      62            0 :   ui->setupUi(this);
      63            0 :   this_status_bar = new QStatusBar(ui->StatusFrame);
      64              : 
      65            0 :   QString cname = QString::fromStdString(this_object_class.p_name);
      66            0 :   setWindowTitle(QString("Create New Object of Class %1").arg(cname));
      67              : 
      68            0 :   SetComboClass();
      69            0 :   ui->LineEditUID->setToolTip(QString("Type Object unique ID and press ENTER"));
      70              : 
      71            0 :   ui->ComboBoxForbiddenUid->hide();
      72            0 :   ui->SetFileButton->hide();
      73              : 
      74            0 :   SetController();
      75            0 :   BuildFileModel();
      76            0 :   SetStatusBar();
      77            0 :   BuildContextMenu();
      78              : 
      79            0 :   int index = ui->ComboBoxClass->findText(cname);
      80            0 :   ui->ComboBoxClass->setCurrentIndex(1);     // If index is 0 somehow this doesnt work
      81            0 :   ui->ComboBoxClass->setCurrentIndex(index); // Now set it to the right value posssibly 0
      82            0 :   setup_editor();
      83            0 :   ui->ComboBoxClass->setEditText(cname);
      84              : 
      85            0 :   ui->SetUidButton->setVisible(false);
      86            0 :   UpdateActions();
      87              : 
      88            0 :   QSize SplitterSize = ui->splitter->size();
      89            0 :   int Width = SplitterSize.width() / 2;
      90              : 
      91            0 :   QList<int> List;
      92            0 :   List.push_back(Width);
      93            0 :   List.push_back(Width);
      94              : 
      95            0 :   ui->splitter->setSizes(List);
      96            0 : }
      97              : 
      98              : //------------------------------------------------------------------------------------------
      99              : 
     100              : //------------------------------------------------------------------------------------------
     101              : /*
     102              :  * Clone an object in a class , uid will be required to be set explicitly
     103              :  */
     104            0 : dbe::ObjectCreator::ObjectCreator(tref const& clonefrom,
     105              :                                   dunedaq::conffwk::relationship_t const& the_relation,
     106            0 :                                   QWidget* parent)
     107            0 :   : ObjectCreator(config::api::info::onclass::definition(clonefrom.class_name(), false), parent)
     108              : {
     109            0 :   this_target_object.reset(new tref(clonefrom));
     110            0 :   this_relation = the_relation;
     111            0 : }
     112              : 
     113              : //------------------------------------------------------------------------------------------
     114              : 
     115              : //------------------------------------------------------------------------------------------
     116            0 : dbe::ObjectCreator::ObjectCreator(tref const& clonefrom, QWidget* parent)
     117              :   : QWidget(parent)
     118            0 :   , ui(new Ui::ObjectCreator)
     119            0 :   , this_object_class(config::api::info::onclass::definition(clonefrom.class_name(), false))
     120            0 :   , this_src_object(new tref(clonefrom))
     121            0 :   , this_files(nullptr)
     122            0 :   , this_status_bar(nullptr)
     123            0 :   , UidSet(false)
     124            0 :   , this_associated_editor(nullptr)
     125            0 :   , ContextMenu(nullptr)
     126            0 :   , this_is_temporary(false)
     127            0 :   , this_object_changed(false)
     128            0 :   , this_create_copy(true)
     129            0 :   , uuid(QUuid::createUuid())
     130              : {
     131            0 :   ui->setupUi(this);
     132            0 :   this_status_bar = new QStatusBar(ui->StatusFrame);
     133              : 
     134            0 :   setWindowTitle(QString("Create New Object of Class %1").arg(QString::fromStdString(this_object_class.p_name)));
     135              : 
     136            0 :   SetComboClass();
     137            0 :   ui->LineEditUID->setToolTip(QString("Type Object unique ID and press ENTER"));
     138              : 
     139            0 :   ui->ComboBoxForbiddenUid->hide();
     140            0 :   ui->SetFileButton->hide();
     141              : 
     142            0 :   SetController();
     143            0 :   BuildFileModel();
     144            0 :   SetStatusBar();
     145            0 :   BuildContextMenu();
     146              : 
     147            0 :   int index = ui->ComboBoxClass->findText(QString::fromStdString(clonefrom.class_name()));
     148              : 
     149            0 :   ui->ComboBoxClass->setCurrentIndex(index);
     150            0 :   setup_copy_editor();
     151              : 
     152              :   /// Setting the same file as the object being copied
     153            0 :   QString const& fn = QString::fromStdString(this_src_object->contained_in());
     154            0 :   QFileInfo fileinfo(fn);
     155            0 :   QModelIndexList ListOfMatch = this_files->match(this_files->index(0, 0),
     156              :                                                   Qt::DisplayRole,
     157            0 :                                                   fileinfo.fileName(),
     158              :                                                   1000,
     159            0 :                                                   Qt::MatchContains | Qt::MatchWrap | Qt::MatchRecursive);
     160              : 
     161            0 :   ui->FileView->selectRow(ListOfMatch.at(0).row());
     162              : 
     163            0 :   ActiveFileChanged(fn);
     164              : 
     165              :   // Set uid to the that of the object being copied
     166            0 :   ui->LineEditUID->setText(QString::fromStdString(clonefrom.UID()));
     167            0 :   ui->ComboBoxClass->setEditText(QString::fromStdString(clonefrom.class_name()));
     168              : 
     169            0 :   ui->SetUidButton->setVisible(false);
     170            0 :   UpdateActions();
     171              : 
     172            0 :   QSize spliter_size = ui->splitter->size();
     173            0 :   int w = spliter_size.width() / 2;
     174            0 :   ui->splitter->setSizes(QList<int>{ w, w });
     175            0 : }
     176              : 
     177              : //------------------------------------------------------------------------------------------
     178              : 
     179              : //------------------------------------------------------------------------------------------
     180              : void
     181            0 : dbe::ObjectCreator::SetComboClass()
     182              : {
     183            0 :   QStringList ListOfClasses(dbe::config::api::info::onclass::allnames<QStringList>());
     184            0 :   ui->ComboBoxClass->addItems(ListOfClasses);
     185              : 
     186            0 :   QCompleter* completer = new QCompleter(ui->ComboBoxClass->model(), ui->ComboBoxClass);
     187            0 :   completer->setCaseSensitivity(Qt::CaseInsensitive);
     188            0 :   completer->setFilterMode(Qt::MatchContains);
     189            0 :   ui->ComboBoxClass->setCompleter(completer);
     190            0 :   ui->ComboBoxClass->setEditable(true);
     191              : 
     192            0 :   QVariant VarFromList(ListOfClasses);
     193            0 :   ValidatorAcceptMatch* Validator = new ValidatorAcceptMatch(VarFromList, this);
     194            0 :   ui->ComboBoxClass->setValidator(Validator);
     195            0 : }
     196              : 
     197              : void
     198            0 : dbe::ObjectCreator::SetController()
     199              : {
     200            0 :   connect(ui->FileView,
     201              :           SIGNAL(stateChanged(const QString&)),
     202              :           this,
     203              :           SLOT(ActiveFileChanged(const QString&)),
     204              :           Qt::UniqueConnection);
     205              : 
     206            0 :   connect(ui->CreateObjectButton, SIGNAL(clicked()), this, SLOT(CreateObject()), Qt::UniqueConnection);
     207              : 
     208            0 :   connect(ui->CreateOpenObjectButton, SIGNAL(clicked()), this, SLOT(CreateOpenObject()), Qt::UniqueConnection);
     209              : 
     210            0 :   connect(ui->ExitButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection);
     211              : 
     212            0 :   connect(ui->LineEditUID, SIGNAL(textChanged(QString)), this, SLOT(UpdateActions(QString)), Qt::UniqueConnection);
     213              : 
     214            0 :   connect(ui->LineEditUID,
     215              :           SIGNAL(textEdited(const QString&)),
     216              :           this,
     217              :           SLOT(MustPressReturn(const QString&)),
     218              :           Qt::UniqueConnection);
     219              : 
     220            0 :   connect(this, SIGNAL(stateChanged()), this, SLOT(UpdateActions()), Qt::UniqueConnection);
     221              : 
     222            0 :   connect(this, SIGNAL(stateChanged()), this, SLOT(SetObjectChanged()), Qt::UniqueConnection);
     223            0 : }
     224              : 
     225              : void
     226            0 : dbe::ObjectCreator::BuildFileModel()
     227              : {
     228            0 :   if (not confaccessor::db_implementation_name().contains("roksconflibs")) {
     229            0 :     if (this_files != nullptr) {
     230            0 :       delete this_files;
     231            0 :       this_files = nullptr;
     232              :     }
     233              : 
     234            0 :     this_files = new FileModel(confaccessor::ref().GetIncludedFileCache());
     235              : 
     236            0 :     this_sort.setSourceModel(this_files);
     237            0 :     ui->FileView->setModel(&this_sort);
     238            0 :     ui->FileView->sortByColumn(2, Qt::DescendingOrder);
     239              : 
     240              :     // ui->FileView->HideReadOnlyFilesSlot(true);
     241            0 :     ui->FileView->setColumnHidden(2, true);
     242            0 :     ui->FileView->setColumnHidden(3, true);
     243            0 :     ui->FileView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
     244              :   }
     245            0 : }
     246              : 
     247              : void
     248            0 : dbe::ObjectCreator::SetStatusBar()
     249              : {
     250            0 :   this_status_bar->setSizeGripEnabled(false);
     251            0 :   this_status_bar->setAutoFillBackground(true);
     252            0 :   this_status_bar->showMessage(QString("Select class, set new object UID, select file where to create object!"));
     253            0 :   ui->StatusFrame->setFrameStyle(QFrame::NoFrame);
     254            0 :   ui->StatusLayout->addWidget(this_status_bar);
     255            0 : }
     256              : 
     257              : void
     258            0 : dbe::ObjectCreator::UpdateActions()
     259              : {
     260            0 :   bool ReleaseEditor = true;
     261            0 :   this_state = editorOk;
     262              : 
     263            0 :   if (!ui->LineEditUID->IsValid() || ui->LineEditUID->text().isEmpty()) {
     264            0 :     this_state |= uidNotSet;
     265            0 :     ReleaseEditor = false;
     266            0 :     this_newuid = QString();
     267              :   } else {
     268            0 :     this_state &= ~uidNotSet;
     269            0 :     this_newuid = ui->LineEditUID->text();
     270              :   }
     271              : 
     272            0 :   if (this_file_for_new_object.isEmpty()) {
     273            0 :     this_state |= fileNotSet;
     274            0 :     ReleaseEditor = false;
     275              :   } else {
     276            0 :     this_state &= ~fileNotSet;
     277              :   }
     278              : 
     279            0 :   if (ReleaseEditor) {
     280            0 :     this_associated_editor->setEnabled(true);
     281              :   }
     282              : 
     283            0 :   if (this_associated_editor != nullptr) {
     284            0 :     if (!this_associated_editor->IsEditorValid()) {
     285            0 :       this_state |= nullNotFilled;
     286              :     } else {
     287            0 :       this_state &= ~nullNotFilled;
     288              :     }
     289              :   }
     290              : 
     291            0 :   if (this_state == editorOk) {
     292            0 :     ui->CreateObjectButton->setEnabled(true);
     293            0 :     ui->CreateObjectButton->setPalette(StyleUtility::PaleGreenPalleteButton);
     294              : 
     295            0 :     ui->CreateOpenObjectButton->setEnabled(true);
     296            0 :     ui->CreateOpenObjectButton->setPalette(StyleUtility::PaleGreenPalleteButton);
     297              : 
     298            0 :     this_status_bar->setPalette(QApplication::palette(this));
     299            0 :     this_status_bar->showMessage(GetMessage());
     300              :   } else {
     301            0 :     ui->CreateObjectButton->setEnabled(false);
     302            0 :     ui->CreateOpenObjectButton->setEnabled(false);
     303            0 :     QPalette buttonAlert;
     304            0 :     buttonAlert.setColor(QPalette::Disabled, QPalette::Button, QColor("grey"));
     305            0 :     ui->CreateObjectButton->setPalette(buttonAlert);
     306            0 :     ui->CreateOpenObjectButton->setPalette(buttonAlert);
     307            0 :     this_status_bar->setPalette(StyleUtility::WarningStatusBarPalleteWindow);
     308            0 :     this_status_bar->showMessage(GetMessage());
     309            0 :   }
     310            0 : }
     311              : 
     312              : void
     313            0 : dbe::ObjectCreator::UpdateActions(QString Dummy)
     314              : {
     315            0 :   Q_UNUSED(Dummy)
     316            0 :   UpdateActions();
     317            0 : }
     318              : 
     319              : QString
     320            0 : dbe::ObjectCreator::GetMessage()
     321              : {
     322            0 :   if (this_state == editorOk)
     323            0 :     return QString("Now you can create object '%1' of class '%2'.")
     324            0 :       .arg(this_newuid)
     325            0 :       .arg(QString((this_object_class.p_name).c_str()));
     326            0 :   else if (GetState(classNotSelected | uidNotSet | fileNotSet))
     327            0 :     return QString("Select class, set unique ID, select file where to create object and set obligatory attributes and "
     328            0 :                    "relationships!");
     329            0 :   else if (GetState(classNotSelected)) {
     330            0 :     return QString("First select class!");
     331            0 :   } else if (GetState(fileNotSet))
     332            0 :     return QString("Set active file where to create new object");
     333            0 :   else if (GetState(uidNotSet)) {
     334            0 :     return QString("Set the object UID");
     335            0 :   } else if (GetState(nullNotFilled))
     336            0 :     return QString("All NOT NULL attributes or relationships must be set!");
     337              : 
     338            0 :   return QString("Problem to process Object Create operation!");
     339              : }
     340              : 
     341              : bool
     342            0 : dbe::ObjectCreator::GetState(int Flags)
     343              : {
     344            0 :   return ((this_state & Flags) == Flags);
     345              : }
     346              : 
     347              : void
     348            0 : dbe::ObjectCreator::BuildContextMenu()
     349              : {
     350            0 :   ContextMenu = new QMenu(this);
     351            0 :   ContextMenu->addAction(tr("&Edit Include Files"), this, SLOT(AddInclude()), QKeySequence(tr("Ctrl+Z")));
     352            0 : }
     353              : 
     354              : void
     355            0 : dbe::ObjectCreator::AddInclude()
     356              : {
     357            0 : }
     358              : 
     359              : void
     360            0 : dbe::ObjectCreator::FillUidComboBox()
     361              : {
     362            0 :   ui->ComboBoxForbiddenUid->clear();
     363              : 
     364            0 :   QStringList listOfUID;
     365            0 :   QString nameOfClass = QString(this_object_class.p_name.c_str());
     366              : 
     367            0 :   std::vector<tref> const& vec = dbe::config::api::info::onclass::objects(nameOfClass.toStdString(), false);
     368              : 
     369            0 :   for (size_t i = 0; i < vec.size(); ++i) {
     370            0 :     ui->ComboBoxForbiddenUid->addItem(QString(vec.at(i).UID().c_str()));
     371            0 :     listOfUID << QString(vec.at(i).UID().c_str());
     372              :   }
     373              : 
     374            0 :   if (!listOfUID.isEmpty()) {
     375            0 :     ui->ComboBoxForbiddenUid->setToolTip(QString("Already used object unique ID of class %1 ").arg(nameOfClass));
     376            0 :     ui->ComboBoxForbiddenUid->show();
     377              :   }
     378              : 
     379            0 :   QVariant varFromList(listOfUID);
     380            0 :   ValidatorAcceptNoMatch* myval = new ValidatorAcceptNoMatch(varFromList, this);
     381            0 :   ui->LineEditUID->SetValidator(myval);
     382            0 : }
     383              : 
     384              : void
     385            0 : dbe::ObjectCreator::CreateOpenObject()
     386              : {
     387            0 :   CreateObject(true);
     388            0 : }
     389              : 
     390              : void
     391            0 : dbe::ObjectCreator::CreateObject(bool openEditor)
     392              : {
     393            0 :   setCursor(Qt::WaitCursor);
     394              : 
     395            0 :   BOOST_SCOPE_EXIT(this_)
     396              :   {
     397            0 :     this_->unsetCursor();
     398            0 :   }
     399            0 :   BOOST_SCOPE_EXIT_END
     400              : 
     401            0 :   if (this_file_for_new_object.isEmpty()) {
     402            0 :     ERROR("Object creation not feasible", "Object file must be selected")
     403            0 :   } else if (this_newuid.isEmpty()) {
     404            0 :     ERROR("Object creation not feasible", "Object name (uid) cannot be an empty string");
     405            0 :   } else if (this_associated_editor) {
     406            0 :     this_associated_editor->SetUsedForCopy(true);
     407              : 
     408            0 :     bool done =
     409            0 :       this_associated_editor->ParseToCreate(this_newuid.toStdString(), this_file_for_new_object.toStdString());
     410            0 :     this_associated_editor->SetUsedForCopy(false);
     411            0 :     this_associated_editor->ResetObjectChanged();
     412            0 :     this_object_changed = false;
     413              : 
     414            0 :     if (done) {
     415            0 :       close();
     416              : 
     417            0 :       if (openEditor == true) {
     418            0 :         (new ObjectEditor(dbe::inner::dbcontroller::get({ this_newuid.toStdString(), this_object_class.p_name })))
     419            0 :           ->show();
     420              :       }
     421              :     }
     422              :   }
     423            0 : }
     424              : 
     425              : void
     426            0 : dbe::ObjectCreator::SetObjectChanged()
     427              : {
     428            0 :   this_object_changed = true;
     429            0 : }
     430              : 
     431              : void
     432            0 : dbe::ObjectCreator::ActiveFileChanged(const QString& fname)
     433              : {
     434            0 :   if (fname.isEmpty() or not confaccessor::check_file_rw(fname)) {
     435            0 :     this_file_for_new_object = QString();
     436            0 :     emit stateChanged();
     437            0 :     return;
     438              :   }
     439              : 
     440            0 :   this_file_for_new_object = fname;
     441            0 :   ui->FileView->setToolTip(QString("Activate file which will store the new object: ").append(this_file_for_new_object));
     442            0 :   QString setFilesWithPath = QString("Selected File: %1").arg(this_file_for_new_object);
     443            0 :   QString setOnlyFiles = QString("Selected File: %1").arg(QFileInfo(this_file_for_new_object).fileName());
     444            0 :   ui->FileLabel->setText(setOnlyFiles);
     445            0 :   ui->FileLabel->setToolTip(setFilesWithPath);
     446            0 :   ui->FileView->setStyleSheet("selection-background-color : rgb(190,238,158)");
     447            0 :   emit stateChanged();
     448            0 : }
     449              : 
     450              : void
     451            0 : dbe::ObjectCreator::setup_editor()
     452              : {
     453            0 :   if (ui->ComboBoxClass->IsValid()) {
     454              : 
     455            0 :     this_newuid = QString();
     456            0 :     QString cname = QString::fromStdString(this_object_class.p_name);
     457              : 
     458              :     // Create the editor for the new object to be able to modify attributes before creation
     459            0 :     this_associated_editor = new ObjectEditor(cname.toStdString(), this);
     460            0 :     this_associated_editor->setWindowModality(Qt::NonModal);
     461            0 :     this_associated_editor->HideDetailWidget(true);
     462            0 :     this_associated_editor->setDisabled(true);
     463            0 :     ui->EditorLayout->addWidget(this_associated_editor);
     464              : 
     465            0 :     {
     466              :       // Set appropriately the stretch factor such that contents are resized
     467              :       // favoring the object editor side
     468            0 :       QSizePolicy pol = ui->splitter->widget(1)->sizePolicy();
     469            0 :       pol.setHorizontalStretch(2);
     470              :       //      pol.setHorizontalPolicy(QSizePolicy::Maximum);
     471            0 :       ui->splitter->widget(1)->setSizePolicy(pol);
     472              :     }
     473              : 
     474            0 :     {
     475              :       // Set horizontal size of the editor pane to the first widget size
     476            0 :       this_associated_editor->resize(this_associated_editor->sizeHint());
     477            0 :       QList<QTableWidget*> const& editor_widgets{ this_associated_editor->findChildren<QTableWidget*>() };
     478              : 
     479            0 :       this_associated_editor->setMinimumWidth(editor_widgets[0]->width() / 2);
     480              : 
     481            0 :       QRect this_widget_geometry = this->geometry();
     482            0 :       this_widget_geometry.setWidth(editor_widgets[0]->width() + ui->ObjectCreatorWidget->width());
     483            0 :       this->setGeometry(this_widget_geometry);
     484            0 :     }
     485              : 
     486              :     // Set the labels to the class name
     487            0 :     ui->ClassLabel->setText(QString("Selected Class: %1").arg(cname));
     488            0 :     setWindowTitle(QString("Create New Object of class %1").arg(cname));
     489              : 
     490            0 :     connect(this_associated_editor, SIGNAL(WidgetUpdated()), this, SLOT(UpdateActions()), Qt::UniqueConnection);
     491              : 
     492            0 :     FillUidComboBox();
     493            0 :     ui->ComboBoxForbiddenUid
     494            0 :       ->hide(); /// To anyone wondering this is a list of all the uids that cannot be used(at some point i thought this
     495              :                 /// could be useful to show to the user) // -- that was a very stupid idea!
     496              : 
     497            0 :     QString const& linetext = ui->LineEditUID->text();
     498              : 
     499            0 :     if (!linetext.isEmpty()) {
     500            0 :       ui->LineEditUID->clear();
     501            0 :       ui->LineEditUID->setText(linetext);
     502            0 :       SetUID();
     503              :     }
     504              : 
     505            0 :     emit stateChanged();
     506            0 :     this_object_changed = false;
     507            0 :   }
     508            0 : }
     509              : 
     510              : void
     511            0 : dbe::ObjectCreator::setup_copy_editor()
     512              : {
     513            0 :   if (ui->ComboBoxClass->IsValid()) {
     514            0 :     QString cname = QString::fromStdString(this_object_class.p_name);
     515              : 
     516            0 :     ui->ClassLabel->setText(QString("Selected Class: %1").arg(cname));
     517            0 :     setWindowTitle(QString("Create New Object of Class %1").arg(cname));
     518              : 
     519            0 :     this_associated_editor = new ObjectEditor(*this_src_object, this, true);
     520            0 :     this_associated_editor->setWindowModality(Qt::NonModal);
     521            0 :     this_associated_editor->SetUsedForCopy(true);
     522            0 :     this_associated_editor->HideDetailWidget(true);
     523            0 :     this_associated_editor->setDisabled(true);
     524              : 
     525            0 :     ui->EditorLayout->addWidget(this_associated_editor);
     526            0 :     connect(this_associated_editor, SIGNAL(WidgetUpdated()), this, SLOT(UpdateActions()), Qt::UniqueConnection);
     527              : 
     528            0 :     FillUidComboBox();
     529            0 :     ui->ComboBoxForbiddenUid->hide();
     530              : 
     531            0 :     QString tmpSt = ui->LineEditUID->text();
     532              : 
     533            0 :     if (!tmpSt.isEmpty()) {
     534            0 :       ui->LineEditUID->clear();
     535            0 :       ui->LineEditUID->setText(tmpSt);
     536            0 :       SetUID();
     537              :     }
     538              : 
     539            0 :     emit stateChanged();
     540            0 :     this_object_changed = false;
     541            0 :   }
     542            0 : }
     543              : 
     544              : void
     545            0 : dbe::ObjectCreator::SetUID()
     546              : {
     547            0 :   if (this_file_for_new_object.isEmpty()) {
     548            0 :     ERROR("Object creation is not feasible", "Database file not selected");
     549            0 :     return;
     550              :   }
     551              : 
     552            0 :   if (ui->LineEditUID->IsValid()) {
     553            0 :     this_newuid = ui->LineEditUID->text();
     554              : 
     555            0 :     QString textForUser = QString("New Object ID: %1").arg(this_newuid);
     556            0 :     ui->UidLabel->setText(textForUser);
     557            0 :   } else {
     558            0 :     WARN("Object creation is not feasible", "Invalid UID provided");
     559            0 :     return;
     560              :   }
     561              : 
     562            0 :   if (!this_file_for_new_object.isEmpty()) {
     563            0 :     UidSet = true;
     564            0 :     this_associated_editor->setDisabled(false);
     565            0 :     emit stateChanged();
     566              :   } else {
     567            0 :     TLOG_DEBUG(0) << "active file empty!! check!!";
     568              :   }
     569              : }
     570              : 
     571              : void
     572            0 : dbe::ObjectCreator::MustPressReturn(const QString&)
     573              : {
     574            0 :   QPalette yellow;
     575            0 :   yellow.setColor(QPalette::Active, QPalette::Window, QColor("yellow"));
     576              : 
     577            0 :   this_status_bar->setPalette(yellow);
     578            0 :   this_status_bar->showMessage(QString("Press ENTER to set new UID!"));
     579            0 : }
     580              : 
     581              : bool
     582            0 : dbe::ObjectCreator::CanClose()
     583              : {
     584              : 
     585            0 :   if ((this_object_changed and ui->CreateObjectButton->isEnabled()) or
     586            0 :       (this_associated_editor and this_associated_editor->WasObjectChanged())) {
     587            0 :     int ret = QMessageBox::question(0,
     588            0 :                                     tr("DBE - ObjectCreate"),
     589            0 :                                     QString("There are pending actions for this dialogue"),
     590              :                                     QMessageBox::Discard | QMessageBox::Cancel,
     591              :                                     QMessageBox::Cancel);
     592              : 
     593            0 :     if (ret == QMessageBox::Discard) {
     594            0 :       this_object_changed = false;
     595            0 :       this_associated_editor->ResetObjectChanged();
     596              : 
     597            0 :       try {
     598            0 :         config::api::commands::delobj(inner::dbcontroller::get({ this_newuid.toStdString(), this_object_class.p_name }),
     599            0 :                                       uuid);
     600            0 :       } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
     601              :         // nothing specific handle needed in this , it is possible that there is no resul
     602            0 :       }
     603              : 
     604            0 :       return true;
     605            0 :     } else if (ret == QMessageBox::Cancel) {
     606              :       return false;
     607              :     }
     608              : 
     609              :     return true;
     610              :   } else {
     611            0 :     return true;
     612              :   }
     613              : }
     614              : 
     615              : void
     616            0 : dbe::ObjectCreator::closeEvent(QCloseEvent* event)
     617              : {
     618            0 :   if (CanClose()) {
     619            0 :     if (this_associated_editor) {
     620            0 :       this_associated_editor->close();
     621            0 :       this_associated_editor = nullptr;
     622              :     }
     623              : 
     624            0 :     event->accept();
     625              :   } else {
     626            0 :     event->ignore();
     627              :   }
     628            0 : }
        

Generated by: LCOV version 2.0-1