DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
BuildingBlockEditors.cpp
Go to the documentation of this file.
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/config_api.hpp"
9#include "dbe/Validator.hpp"
10#include "dbe/StyleUtility.hpp"
11#include "dbe/ObjectEditor.hpp"
13
14#include <QStringListModel>
15#include <QMessageBox>
16#include <QCompleter>
17#include <QLineEdit>
18#include <QListWidget>
19#include <QPair>
20#include <QMimeData>
21#include <QByteArray>
22#include <QDataStream>
23#include <QEvent>
24#include <QWidget>
25
26#include <boost/scope_exit.hpp>
27
28#include <functional>
29#include <memory>
30
31namespace dbe
32{
34
35
36template<>
43
44template<typename T> editor_data<T>::~editor_data() = default;
45
46namespace widgets
47{
48
49namespace editors
50{
51//------------------------------------------------------------------------------------------------
52base::base ( std::shared_ptr<editor_data_state> editordata,
53 QWidget * parent, bool owned )
54 :
55 QWidget ( parent ),
56 p_data_editor ( editordata ),
57 this_is_owned ( owned ),
58 this_value_changed ( false ),
59 this_initial_load ( false )
60{}
61
62
63template<>
64std::shared_ptr<editor_data_state> base::dataeditor<editor_data_state>()
65{
66 return p_data_editor;
67}
68
69QStringList base::getdata()
70{
71 return this_data;
72}
73
74void base::setdata ( QStringList const & ValueList )
75{
76 this_data = ValueList;
77}
78
79void base::setdefaults ( QString const & ValueDefault )
80{
81 this_defaults = ValueDefault;
82}
83
84void base::setchanged ( bool const val )
85{
87}
88
89bool base::ischanged() const
90{
91 return this_value_changed;
92}
93
98
99void base::closeEvent ( QCloseEvent * Event )
100{
101 Q_UNUSED ( Event )
102}
103
104//------------------------------------------------------------------------------------------------
105
106
107//------------------------------------------------------------------------------------------------
108relation::relation ( t_virtue const & relation, QWidget * parent,
109 bool owned )
110 :
111 base (
112 std::make_shared<t_build_block_editor> ( relation ), parent, owned ),
113 p_base_data_editor ( std::static_pointer_cast<t_build_block_editor> ( p_data_editor ) ),
114 IsMultiValue ( false ),
115 StatusBar ( nullptr ),
116 ContextMenu ( nullptr ),
117 RemoveAction ( nullptr ),
118 MoveTop ( nullptr ),
119 MoveBottom ( nullptr ),
120 MoveUp ( nullptr ),
121 MoveDown ( nullptr ),
122 EditAction ( nullptr ),
123 CurrentItem ( nullptr )
124{
125 setupUi ( this );
126
127 t_virtue const & Virtue = p_base_data_editor->get();
128
129 setWindowTitle ( QString ( "Edit Relationship: %1" ).arg ( Virtue.p_name.c_str() ) );
130 ListWidget->setContextMenuPolicy ( Qt::CustomContextMenu );
131 ComboBox->setHidden ( true );
132
133 // if it is X_ and many then set multivalue
134
137 {
138 IsMultiValue = true;
139 }
140
141 // Check if this relation can be left unset
142 if ( ( Virtue.p_cardinality == dunedaq::conffwk::one_or_many ) ||
144 {
145 p_base_data_editor->set_not_null ( true );
146 p_base_data_editor->set_valid ( false );
147 }
148
151
152 if ( this_is_owned )
153 {
154 SaveButton->setHidden ( true );
155 RemoveButton->setHidden ( true );
156 }
157
158 buildtooltip();
159}
160
161bool relation::eventFilter ( QObject * Target, QEvent * Event )
162{
163 if(dynamic_cast<QListWidget*>(Target)) {
164 auto decode = [this] (const QMimeData * const data) -> QPair<bool, QStringList>
165 {
166 bool allGood = true;
167 QStringList newItems;
168
169 if(data->hasFormat("application/vnd.text.list") == true) {
170 QByteArray encodedData = data->data("application/vnd.text.list");
171 QDataStream stream(&encodedData, QIODevice::ReadOnly);
172
173 const std::string& referenceClass = p_base_data_editor->get().p_type;
174
175 while(!stream.atEnd()) {
176 QStringList text;
177 stream >> text;
178
179 const QString& obj_id = text.at(0);
180 const QString& obj_class = text.at(1);
181
182 if((obj_class.toStdString() == referenceClass) ||
183 (dbe::config::api::info::onclass::derived(referenceClass, obj_class.toStdString()) == true))
184 {
185 newItems.append(obj_id);
186 } else {
187 allGood = false;
188 }
189 }
190 } else {
191 allGood = false;
192 }
193
194 return qMakePair(allGood, newItems);
195 };
196
197 if(Event->type() == QEvent::DragEnter) {
198 QDragEnterEvent *tDropEvent = static_cast<QDragEnterEvent *>(Event);
199
200 const QMimeData * const data = tDropEvent->mimeData();
201 const auto& decodedData = decode(data);
202 if((decodedData.first == true) && (decodedData.second.size() > 0)) {
203 tDropEvent->acceptProposedAction();
204 }
205
206 return true;
207 }
208
209 if(Event->type() == QEvent::Drop) {
210 QDropEvent *tDropEvent = static_cast<QDropEvent *>(Event);
211
212 const QMimeData * const data = tDropEvent->mimeData();
213 for(const QString& o : decode(data).second) {
214 // TODO: this is not very efficient for large lists
215 AddToDataList(o);
216 }
217
218 tDropEvent->acceptProposedAction();
219
220 return true;
221 }
222 } else if(QComboBox * Box = dynamic_cast<QComboBox *>(Target)) {
223 if(Event->type() == QEvent::Wheel) {
224 return true;
225 }
226
227 if(Event->type() == QEvent::KeyPress) {
228 QKeyEvent * KeyEvent = dynamic_cast<QKeyEvent *>(Event);
229
230 if(KeyEvent->key() == Qt::Key_Up || KeyEvent->key() == Qt::Key_Down) {
231 return true;
232 } else {
233 return false;
234 }
235 }
236
237 if(Event->type() == QEvent::FocusOut) {
238 QWidget * popup = Box->findChild<QFrame *>();
239 QWidget * popup1 = Box->lineEdit()->findChild<QFrame *>();
240
241 if(popup != popup1 and not popup->isHidden()) {
242 return true;
243 }
244
245 if(FirstItem == nullptr) {
246 if(IsMultiValue) {
247 FirstItem = new QListWidgetItem("Type here");
248 } else {
249 if(this_data.isEmpty()) {
250 FirstItem = new QListWidgetItem("No Object");
251 } else {
252 FirstItem = new QListWidgetItem(this_data.at(0));
253 }
254 }
255
256 ListWidget->addItem(FirstItem);
257
258 if(IsMultiValue) {
259 FirstItem->setBackground(Qt::GlobalColor::lightGray);
260 FirstItem->setForeground(QColor(0, 0, 0, 127));
261 }
262
263 FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25));
264 } else if(FirstItem->listWidget() == ListWidget && ListWidget->itemWidget(FirstItem) != 0) {
265 ListWidget->takeItem(ListWidget->row(FirstItem));
266 ListWidget->setItemWidget(FirstItem, nullptr);
267 delete FirstItem;
268
269 if(IsMultiValue) {
270 FirstItem = new QListWidgetItem("Type here");
271 } else {
272 if(this_data.isEmpty()) {
273 FirstItem = new QListWidgetItem("No Object");
274 } else {
275 FirstItem = new QListWidgetItem(this_data.at(0));
276 }
277 }
278
279 ListWidget->addItem(FirstItem);
280
281 if(IsMultiValue) {
282 FirstItem->setBackground(Qt::GlobalColor::lightGray);
283 FirstItem->setForeground(QColor(0, 0, 0, 127));
284 }
285
286 FirstItem->setSizeHint(FirstItem->sizeHint() + QSize(0, 25));
287 }
288
289 return false;
290 }
291 } else if(QLineEdit* le = dynamic_cast<QLineEdit *>(Target)) {
292 if(Event->type() == QEvent::MouseButtonDblClick) {
293 const QString& value = le->text();
294
295 // This string checking is very very bad...
296 if((value.isEmpty() == false) && (value != "Type here") && (value != "No Object")) {
297 CreateObjectEditor(le->text().toStdString());
298 return false;
299 }
300 }
301 }
302
303 return false;
304}
305
307{
308 ListWidget->clear();
309
310 if ( IsMultiValue )
311 {
312 ListWidget->addItems ( this_data );
313
314 // Enable drops only for multi-value
315 // This allows to drop several objects in a relationship (e.g., several computers in a rack)
316 // Not really needed for single-value relationship (the item can be selected from the list)
317 ListWidget->setAcceptDrops ( true );
318 ListWidget->installEventFilter ( this );
319 }
320
321 SetFirstItem();
322
323 ListWidget->setSelectionMode ( QAbstractItemView::ExtendedSelection );
324 ListWidget->setEditTriggers ( QAbstractItemView::DoubleClicked );
325 ListWidget->setDragDropMode ( QAbstractItemView::InternalMove );
326
328
330 ComboBox->clear();
331
332 FetchData();
333}
334
336{
337 QStringList result;
338 t_virtue const & Virtue = p_base_data_editor->get();
339
340 std::vector<tref> const & related
341 {
343 };
344
345 for ( tref const & o : related )
346 {
347 result.append ( QString::fromStdString ( o.UID() ) );
348 }
349
350 emit FetchDataDone ( result );
351}
352
354{
355 return IsMultiValue;
356}
357
358void relation::DataWasFetched ( QStringList ListOfObjects )
359{
360 ComboBox->clear();
361 ComboBox->addItems ( ListOfObjects );
362
364
365 if ( this_initial_load )
366 {
367 emit LoadedInitials();
368 }
369}
370
372{
373 connect ( SaveButton, SIGNAL ( clicked() ), this, SLOT ( EndSignal() ) );
374 connect ( RemoveButton, SIGNAL ( clicked() ), this, SLOT ( RemoveFromDataList() ) );
375 connect ( this, SIGNAL ( signal_internal_value_change() ), this, SLOT ( UpdateActions() ) );
376 connect (
377 this, SIGNAL ( FetchDataDone ( QStringList ) ), this,
378 SLOT ( DataWasFetched ( QStringList ) ) );
380 connect ( ListWidget, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
381 SLOT ( CustomContextMenuRequested ( QPoint ) ) );
382 connect ( ListWidget, SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ), this,
383 SLOT ( CreateObjectEditor ( QListWidgetItem * ) ), Qt::UniqueConnection );
384 connect ( ListWidget->model(), SIGNAL ( layoutChanged() ), this, SLOT ( DummyMovement() ) );
385 connect ( ListWidget, SIGNAL ( itemPressed ( QListWidgetItem * ) ), this,
386 SLOT ( EditItemEntered ( QListWidgetItem * ) ) );
387 connect ( &confaccessor::ref(), SIGNAL ( object_created ( QString, dref ) ), this,
388 SLOT ( FetchData () ) );
389 connect ( &confaccessor::ref(), SIGNAL ( object_deleted ( QString, dref ) ), this,
390 SLOT ( FetchData () ) );
391}
392
394{
395 if ( IsMultiValue )
396 {
397 FirstItem = new QListWidgetItem ( "Type here" );
398 }
399 else
400 {
401 if ( this_data.isEmpty() )
402 {
403 FirstItem = new QListWidgetItem ( "No Object" );
404 }
405
406 else
407 {
408 FirstItem = new QListWidgetItem ( this_data.at ( 0 ) );
409 }
410 }
411
412 ListWidget->addItem ( FirstItem );
413
414 if ( IsMultiValue )
415 {
416 FirstItem->setBackground ( Qt::GlobalColor::lightGray );
417 FirstItem->setForeground ( QColor ( 0, 0, 0, 127 ) );
418 }
419
420 FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) );
421}
422
424{
425 t_virtue const & Virtue = p_base_data_editor->get();
426 setToolTip (
427 QString ( "Relationship Name: %1 \n" ).arg ( Virtue.p_name.c_str() ) + QString (
428 " Type: %1 \n" ).arg ( Virtue.p_type.c_str() )
429 + QString ( " Cardinality: %1 \n" ).arg (
431 + QString ( " Is Aggregation: %1 \n" ).arg ( Virtue.p_is_aggregation )
432 + QString ( " Description: %1 \n" ).arg ( Virtue.p_description.c_str() ) );
433}
434void relation::CreateObjectEditor ( const std::string& objectID )
435{
436 t_virtue const & virt = p_base_data_editor->get();
437 tref const & obj = inner::dbcontroller::get( {objectID, virt.p_type} );
438
439 QString oname = QString::fromStdString ( obj.full_name() );
440
441 for ( QWidget * editor : QApplication::allWidgets() )
442 {
443 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
444 {
445 if ( ( w->objectName() ).compare ( oname ) == 0 )
446 {
447 w->raise();
448 w->setVisible ( true );
449 return;
450 }
451 }
452 }
453
454 ( new ObjectEditor ( obj ) )->show();
455}
456
457void relation::CreateObjectEditor ( QListWidgetItem * Item )
458{
459 if ( Item == FirstItem )
460 {
462 return;
463 }
464
465 std::string const & ouid = Item->data ( Qt::DisplayRole ).toString().toStdString();
466 CreateObjectEditor(ouid);
467}
468
469void relation::CustomContextMenuRequested ( const QPoint & pos )
470{
471 if ( ContextMenu == nullptr )
472 {
473 ContextMenu = new QMenu ( ListWidget );
474
475 MoveTop = new QAction ( tr ( "Move Top" ), this );
476 MoveTop->setShortcutContext ( Qt::WidgetShortcut );
477 connect ( MoveTop, SIGNAL ( triggered() ), this, SLOT ( MoveTopSlot() ) );
478 ContextMenu->addAction ( MoveTop );
479
480 MoveBottom = new QAction ( tr ( "Move Bottom" ), this );
481 MoveBottom->setShortcutContext ( Qt::WidgetShortcut );
482 connect ( MoveBottom, SIGNAL ( triggered() ), this, SLOT ( MoveBottomSlot() ) );
483 ContextMenu->addAction ( MoveBottom );
484
485 MoveUp = new QAction ( tr ( "Move Up" ), this );
486 MoveUp->setShortcutContext ( Qt::WidgetShortcut );
487 connect ( MoveUp, SIGNAL ( triggered() ), this, SLOT ( MoveUpSlot() ) );
488 ContextMenu->addAction ( MoveUp );
489
490 MoveDown = new QAction ( tr ( "Move Down" ), this );
491 MoveDown->setShortcutContext ( Qt::WidgetShortcut );
492 connect ( MoveDown, SIGNAL ( triggered() ), this, SLOT ( MoveDownSlot() ) );
493 ContextMenu->addAction ( MoveDown );
494
495 ContextMenu->addSeparator();
496
497 EditAction = new QAction ( tr ( "Edit" ), this );
498 EditAction->setShortcutContext ( Qt::WidgetShortcut );
499 connect ( EditAction, SIGNAL ( triggered() ), this, SLOT ( EditSlot() ) );
500 ContextMenu->addAction ( EditAction );
501
502 RemoveAction = new QAction ( tr ( "Remove" ), this );
503 RemoveAction->setShortcutContext ( Qt::WidgetShortcut );
504 connect ( RemoveAction, SIGNAL ( triggered() ), this, SLOT ( RemoveSlot() ) );
505 ContextMenu->addAction ( RemoveAction );
506 }
507
508 if ( ( CurrentItem = ListWidget->itemAt ( pos ) ) )
509 {
510 if ( CurrentItem != FirstItem )
511 {
512 ( ContextMenu->actions() ).at ( 0 )->setVisible ( true );
513 ( ContextMenu->actions() ).at ( 1 )->setVisible ( true );
514 ( ContextMenu->actions() ).at ( 2 )->setVisible ( true );
515 ( ContextMenu->actions() ).at ( 3 )->setVisible ( true );
516 ( ContextMenu->actions() ).at ( 4 )->setVisible ( true );
517 ( ContextMenu->actions() ).at ( 5 )->setVisible ( false );
518 ( ContextMenu->actions() ).at ( 6 )->setVisible ( true );
519
520 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
521 }
522
523 else if ( CurrentItem == FirstItem and not IsMultiValue )
524 {
525 ( ContextMenu->actions() ).at ( 0 )->setVisible ( false );
526 ( ContextMenu->actions() ).at ( 1 )->setVisible ( false );
527 ( ContextMenu->actions() ).at ( 2 )->setVisible ( false );
528 ( ContextMenu->actions() ).at ( 3 )->setVisible ( false );
529 ( ContextMenu->actions() ).at ( 4 )->setVisible ( true );
530 ( ContextMenu->actions() ).at ( 5 )->setVisible ( true );
531 ( ContextMenu->actions() ).at ( 6 )->setVisible ( true );
532
533 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
534 }
535 }
536}
537
542
544{
545 int ItemPosition = ListWidget->row ( CurrentItem );
546 QString Item = this_data.at ( ItemPosition );
547
548 this_data.removeAt ( ItemPosition );
549 this_data.push_front ( Item );
550
551 FirstItem = ListWidget->takeItem ( this_data.size() );
552 ListWidget->clear();
553 ListWidget->addItems ( this_data );
554 ListWidget->addItem ( FirstItem );
555
556 int index = this_data.indexOf ( Item );
557 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
558 ListWidget->setCurrentRow ( index );
559
561}
562
564{
565 int ItemPosition = ListWidget->row ( CurrentItem );
566 QString Item = this_data.at ( ItemPosition );
567
568 this_data.removeAt ( ItemPosition );
569 this_data.push_back ( Item );
570
571 FirstItem = ListWidget->takeItem ( this_data.size() );
572 ListWidget->clear();
573 ListWidget->addItems ( this_data );
574 ListWidget->addItem ( FirstItem );
575
576 int index = this_data.indexOf ( Item );
577 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
578 ListWidget->setCurrentRow ( index );
579
581}
582
584{
585 int ItemPosition = ListWidget->row ( CurrentItem );
586 QString Item = this_data.at ( ItemPosition );
587
588 if ( ItemPosition != 0 )
589 {
590 this_data.swapItemsAt ( ItemPosition, ItemPosition - 1 );
591
592 FirstItem = ListWidget->takeItem ( this_data.size() );
593 ListWidget->clear();
594 ListWidget->addItems ( this_data );
595 ListWidget->addItem ( FirstItem );
596
597 int index = this_data.indexOf ( Item );
598 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
599 ListWidget->setCurrentRow ( index );
600
602 }
603}
604
606{
607 int ItemPosition = ListWidget->row ( CurrentItem );
608 QString Item = this_data.at ( ItemPosition );
609
610 if ( ItemPosition != ( this_data.size() - 1 ) )
611 {
612 this_data.swapItemsAt ( ItemPosition, ItemPosition + 1 );
613
614 FirstItem = ListWidget->takeItem ( this_data.size() );
615 ListWidget->clear();
616 ListWidget->addItems ( this_data );
617 ListWidget->addItem ( FirstItem );
618
619 int index = this_data.indexOf ( Item );
620 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
621 ListWidget->setCurrentRow ( index );
622
624 }
625}
626
628{
629 if ( QComboBox * ComboBox = dynamic_cast<QComboBox *> ( ListWidget->itemWidget (
630 FirstItem ) )
631 )
632 {
633 ComboBox->lineEdit()->setFocus();
634 }
635
636 t_virtue const & virt = p_base_data_editor->get();
637 tref const & obj = inner::dbcontroller::get (
638 {
639 FirstItem->text().toStdString(), virt.p_type
640 }
641
642 );
643 QString const & editorname = QString::fromStdString ( obj.full_name() );
644
645 for ( QWidget * editor :
646 QApplication::allWidgets()
647 )
648 {
649 if ( ObjectEditor * w = dynamic_cast<ObjectEditor *> ( editor ) )
650 {
651 if ( ( w->objectName() ).compare ( editorname ) == 0 )
652 {
653 w->raise();
654 w->setVisible ( true );
655 return;
656 }
657 }
658 }
659
660 ( new ObjectEditor ( obj ) )->show();
661}
662
664{
665 if ( this_is_owned )
666 {
668 }
669}
670
671void relation::EditItemEntered ( QListWidgetItem * Item )
672{
673 if ( Item != FirstItem )
674 {
675 return;
676 }
677
678 QStringList ListOfObjects;
679
680 for ( int i = 0; i < ComboBox->count(); ++i )
681 {
682 ListOfObjects.append ( ComboBox->itemText ( i ) );
683 }
684
685 QComboBox * NewComboBox = new QComboBox ( this );
686
687 NewComboBox->setLineEdit ( new QLineEdit() );
688
689 NewComboBox->addItems ( ListOfObjects );
690
691 QCompleter * Completer = new QCompleter ( ListOfObjects );
692 Completer->setCaseSensitivity ( Qt::CaseInsensitive );
693 Completer->setFilterMode(Qt::MatchContains);
694
695 NewComboBox->lineEdit()->setCompleter ( Completer );
696
697 NewComboBox->setEditable ( true );
698
699 NewComboBox->setEditText ( Item->text() );
700
701 if ( ListOfObjects.size() > 0 )
702 {
703 NewComboBox->lineEdit()->selectAll();
704 }
705
706 else
707 {
708 NewComboBox->setEnabled ( false );
709 }
710
711 QVariant VariantFromList ( ListOfObjects );
712 ValidatorAcceptMatch * MyCustomValidator = new ValidatorAcceptMatch ( VariantFromList );
713 NewComboBox->setValidator ( MyCustomValidator );
714 NewComboBox->installEventFilter ( this );
715
716 connect ( NewComboBox, SIGNAL ( activated ( const QString & ) ), this,
717 SLOT ( AddToDataList ( const QString & ) ) );
718
719 NewComboBox->lineEdit()->installEventFilter(this);
720
721 ListWidget->setItemWidget ( FirstItem, NewComboBox );
722}
723
725{
726 if ( IsMultiValue and ListWidget->item ( 0 )->text() == "Type here"
727 and not this_value_changed )
728 {
729 return;
730 }
731
732 if ( not this_data.isEmpty() )
733 {
734 this_data.clear();
735 }
736
737 for ( int i = 0; i != ListWidget->count(); ++i )
738 {
739 QListWidgetItem * Item = ListWidget->item ( i );
740 QString const & val = Item->text();
741
742 if ( val != "Type here" and val != "No Object" )
743 {
744 this_data.append ( val );
745 }
746 }
747
748 if ( not this_is_owned )
749 {
750 p_base_data_editor->set_valid ( true );
751 emit signal_edit_end();
752 }
753 else
754 {
755 emit signal_value_change();
756 }
757}
758
759void relation::AddToDataList ( const QString & DataValue )
760{
761 if ( IsMultiValue )
762 {
763 this_data.append ( DataValue );
764 }
765 else
766 {
767 this_data = QStringList ( DataValue );
768 }
769
770 ListWidget->clear();
771
772 if ( IsMultiValue )
773 {
774 ListWidget->addItems ( this_data );
775 }
776
777 int index = this_data.indexOf ( DataValue );
778 ListWidget->scrollTo ( ListWidget->model()->index ( index, 0 ) );
779 ListWidget->setCurrentRow ( index );
780
781 if ( IsMultiValue )
782 {
783 FirstItem = new QListWidgetItem ( "Type here" );
784 }
785 else
786 {
787 FirstItem = new QListWidgetItem ( DataValue.toStdString().c_str() );
788 }
789
790 ListWidget->addItem ( FirstItem );
791
792 if ( IsMultiValue )
793 {
794 FirstItem->setBackground ( Qt::GlobalColor::lightGray );
795 FirstItem->setForeground ( QColor ( 0, 0, 0, 127 ) );
796 }
797
798 FirstItem->setSizeHint ( FirstItem->sizeHint() + QSize ( 0, 25 ) );
799
800 if ( this_is_owned )
801 {
803 }
804}
805
807{
808 QList<QListWidgetItem *> items;
809
810 if ( IsMultiValue )
811 {
812 items = ListWidget->selectedItems();
813 }
814
815 else
816 {
817 items.append ( FirstItem );
818 }
819
820 if ( items.size() > 0 )
821 {
822
823 for ( QListWidgetItem * item : items )
824 {
825 QString text = item->text();
826
827 if ( text != "Type here" )
828 {
829 if ( IsMultiValue )
830 {
831 if ( QListWidgetItem * toremove = ListWidget->takeItem ( ListWidget->row ( item ) ) )
832 {
833 delete toremove;
834 }
835 }
836 else
837 {
838
839 if ( QComboBox * editbox = dynamic_cast<QComboBox *> ( ListWidget->itemWidget (
840 FirstItem ) )
841 )
842 {
843 editbox->lineEdit()->clear();
844 editbox->lineEdit()->clearFocus();
845 FirstItem->setText ( "No Object" );
846 }
847 }
848
849 this_data.removeOne ( text );
850 }
851 }
852
854 }
855}
856
858{
859 QStringList values;
860
861 for ( int i = 0; i < ListWidget->count(); ++i )
862 {
863 QString const & value = ListWidget->item ( i )->text();
864
865 if ( value != "No Object" and value != "Type here" )
866 {
867 values.append ( value );
868 }
869 }
870
871 if ( p_base_data_editor->must_not_be_null() )
872 {
873 if ( values.size() > 0 )
874 {
875 p_base_data_editor->set_valid ( true );
876 ListWidget->setPalette ( QApplication::palette ( this ) );
877 }
878 else
879 {
880 p_base_data_editor->set_valid ( false );
881 ListWidget->setPalette ( StyleUtility::WarningStatusBarPallete );
882 }
883 }
884 else
885 {
886 p_base_data_editor->set_valid ( true );
887 }
888
889 if ( values != CurrentDataList )
890 {
891 this_value_changed = true;
892 }
893
894 if ( this_is_owned )
895 {
896 EndSignal();
897 }
898}
899
900void relation::closeEvent ( QCloseEvent * Event )
901{
902 Q_UNUSED ( Event )
903 emit signal_force_close();
904}
905
906//------------------------------------------------------------------------------------------------
907
908//------------------------------------------------------------------------------------------------
909stringattr::stringattr ( t_virtue const & attr, QWidget * parent,
910 bool owned )
911 :
912 base ( std::make_shared<t_build_block_editor> ( attr ), parent, owned ),
913 m_base_data_editor ( std::static_pointer_cast<t_build_block_editor> ( p_data_editor ) ),
914 DefaultValue ( "" ),
915 PopUpButton ( nullptr ),
916 Dialog ( nullptr ),
917 OkButtonDialog ( nullptr ),
918 TextEditDialog ( nullptr )
919{
920 setupUi ( this );
921 t_virtue const & virtue = m_base_data_editor->get();
922
923 StringLineEdit->installEventFilter(this);
924 StringLineEdit->setTabChangesFocus(true);
925
926 setWindowTitle ( QString ( "Edit Attr : %1" ).arg ( virtue.p_name.c_str() ) );
927 AttributeNameLabel->setText ( QString ( virtue.p_name.c_str() ) + " : " );
929 AttributeNameLabel->setHidden ( true );
930
931 UpdateActions ( );
932
933 if ( m_base_data_editor->must_not_be_null() )
934 {
935 m_base_data_editor->set_valid ( true );
936 StringLineEdit->setPalette ( StyleUtility::WarningStatusBarPallete );
937 OkButton->setDisabled ( true );
938 SetNullCheck ( true );
939 }
940 else
941 {
942 SetNullCheck ( false );
943 }
944
945 if ( virtue.p_is_multi_value )
946 {
947 StringLineEdit->setPalette ( QApplication::palette ( this ) );
948 }
949
950 OkButton->setHidden ( true );
951
952 if ( this_is_owned )
953 {
954 connect ( StringLineEdit, SIGNAL ( StringValidated() ), this, SLOT ( AddToDataList() ),
955 Qt::UniqueConnection );
956 OkButton->setHidden ( true );
957 }
958
960
961 buildtooltip();
962 UpdateActions ( );
963
964 AttributeNameLabel->setFocus();
965}
966
968{
969 delete Dialog;
970 delete PopUpButton;
971}
972
974{
975 if ( this_data.isEmpty() )
976 {
977 return;
978 }
979
980 StringLineEdit->setText ( this_data.value ( 0 ) );
981
983}
984
985QTextEdit * stringattr::GetLineEdit() const
986{
987 return StringLineEdit;
988}
989
990void stringattr::SetNullCheck ( bool Check )
991{
992 StringLineEdit->SetNullCheck ( Check );
993}
994
995void stringattr::SetMultiCheck ( bool Multi )
996{
997 StringLineEdit->SetMultiCheck ( Multi );
998}
999
1000void stringattr::SetCheckDefaults ( bool Default )
1001{
1002 StringLineEdit->SetCheckDefault ( Default );
1003}
1004
1006{
1007 StringLineEdit->selectAll();
1008}
1009
1010bool stringattr::eventFilter(QObject * target, QEvent * evt)
1011{
1012 if (target == StringLineEdit)
1013 {
1014 if (evt->type() == QEvent::FocusIn)
1015 {
1017 }
1018 else if (evt->type() == QEvent::KeyPress)
1019 {
1020 QKeyEvent *kevt = static_cast<QKeyEvent*>(evt);
1021 switch (kevt->key())
1022 {
1023 case Qt::Key_Enter:
1024 case Qt::Key_Return:
1025
1026 if ( kevt->modifiers() == Qt::AltModifier)
1027 {
1028 kevt->setModifiers(Qt::NoModifier);
1029 return false;
1030 }else
1031 {
1032 StringLineEdit->parentWidget()->setFocus(Qt::FocusReason::TabFocusReason);
1034 return true;
1035 }
1036
1037 break;
1038 default:
1039 break;
1040 }
1041 }
1042 }
1043 return false;
1044}
1045
1047{
1048 GetLineEdit()->clear();
1049}
1050
1052{
1053 t_virtue const & Virtue = m_base_data_editor->get();
1054
1055 setToolTip (
1056 QString ( "Attribute Name: %1 \n" ).arg ( Virtue.p_name.c_str() ) + QString (
1057 " Type: %1 \n" ).arg (
1059 + QString ( " Range: %1 \n" ).arg ( Virtue.p_range.c_str() )
1060 + QString ( " Format: %1 \n" ).arg (
1062 + QString ( " Not Null: %1 \n" ).arg ( Virtue.p_is_not_null )
1063 + QString ( " Is Multi Value: %1 \n" ).arg ( Virtue.p_is_multi_value )
1064 + QString ( " Default Value: %1 \n" ).arg ( Virtue.p_default_value.c_str() )
1065 + QString ( " Description: %1 \n" ).arg ( Virtue.p_description.c_str() ) );
1066}
1067
1068void stringattr::closeEvent ( QCloseEvent * Event )
1069{
1070 Q_UNUSED ( Event )
1071 emit signal_force_close();
1072}
1073
1075{
1076 connect ( StringLineEdit, SIGNAL ( textChanged ( ) ), this, SLOT ( UpdateActions ( ) ), Qt::UniqueConnection );
1077 connect ( this, SIGNAL ( signal_data_input_complete() ), this, SLOT ( AddToDataList() ) );
1078 connect ( OkButton, SIGNAL ( clicked() ), this, SLOT ( AddToDataList() ), Qt::UniqueConnection );
1079}
1080
1081void stringattr::setdefaults ( const QString & ValueDefault )
1082{
1083 this_defaults = ValueDefault;
1084 StringLineEdit->SetDefaultValue ( ValueDefault );
1085}
1086
1088{
1089 if ( PopUpButton == nullptr )
1090 {
1091 PopUpButton = new QPushButton ( "..." );
1092 PopUpButton->setMaximumWidth (
1093 PopUpButton->fontMetrics().boundingRect ( "..." ).width() + 15 );
1094 connect ( PopUpButton, SIGNAL ( clicked() ), this, SLOT ( ShowDialog() ),
1095 Qt::UniqueConnection );
1096 horizontalLayout->addWidget ( PopUpButton );
1097 }
1098
1099 PopUpButton->show();
1100}
1101
1103{
1104 if ( PopUpButton != nullptr )
1105 {
1106 PopUpButton->hide();
1107 }
1108}
1109
1111{
1112 t_virtue const & Virtue = m_base_data_editor->get();
1113
1114 if ( Virtue.p_is_not_null && ( this_data.size() == 0 ) )
1115 {
1116 OkButton->setEnabled ( true );
1117 m_base_data_editor->set_valid ( false );
1118 }
1119
1120 else
1121 {
1122 OkButton->setEnabled ( true );
1123 m_base_data_editor->set_valid ( true );
1124 }
1125}
1126
1128{
1129 QString NewValue = StringLineEdit->toPlainText();
1130
1131 if ( !this_data.contains ( NewValue ) )
1132 {
1133 StringLineEdit->setToolTip ( QString ( "The set value is : %1" ).arg ( NewValue ) );
1134 this_data.clear();
1135 this_data.append ( NewValue );
1136
1137 UpdateActions ( );
1138 this_value_changed = true;
1139
1140 if ( !this_is_owned )
1141 {
1142 emit signal_value_change();
1143 emit signal_edit_end();
1144 }
1145 else
1146 {
1147 emit signal_value_change();
1148 }
1149 }
1150}
1151
1153{
1154
1155 if ( Dialog == nullptr )
1156 {
1157 QVBoxLayout * Layout = new QVBoxLayout();
1158 Dialog = new QDialog();
1159 t_virtue const & Virtue = m_base_data_editor->get();
1160 Dialog->setWindowTitle ( QString ( "Edit Attr : %1" ).arg ( Virtue.p_name.c_str() ) );
1161 TextEditDialog = new QPlainTextEdit ( Dialog );
1162 OkButtonDialog = new QPushButton ( "OK", Dialog );
1163 Layout->addWidget ( TextEditDialog );
1164 Layout->addWidget ( OkButtonDialog );
1165 Dialog->setLayout ( Layout );
1166 Dialog->setModal ( true );
1167
1168 connect ( TextEditDialog, SIGNAL ( textChanged() ), this, SLOT ( ToogleTextEditOkButton() ),
1169 Qt::UniqueConnection );
1170 connect ( OkButtonDialog, SIGNAL ( clicked() ), this, SLOT ( UpdateFromTextEdit() ),
1171 Qt::UniqueConnection );
1172 }
1173
1174 TextEditDialog->clear();
1175 TextEditDialog->insertPlainText ( StringLineEdit->toPlainText() );
1176 Dialog->show();
1177}
1178
1180{
1181 StringLineEdit->clear();
1182 StringLineEdit->setText ( TextEditDialog->toPlainText() );
1183 AddToDataList();
1184 Dialog->close();
1185}
1186
1188{
1189 t_virtue const & Virtue = m_base_data_editor->get();
1190
1191 if ( TextEditDialog->toPlainText().isEmpty() && Virtue.p_is_not_null )
1193 ->setEnabled (
1194 false );
1195 else
1196 {
1197 OkButtonDialog->setEnabled ( true );
1198 }
1199}
1200
1201//------------------------------------------------------------------------------------------------
1202
1203//------------------------------------------------------------------------------------------------
1204numericattr::numericattr ( t_virtue const & attr, QWidget * parent,
1205 bool owned )
1206 :
1207 base ( std::make_shared<t_build_block_editor> ( attr ), parent, owned ),
1208 this_base_data_editor ( std::static_pointer_cast<t_build_block_editor> ( p_data_editor ) ),
1209 this_native_base ( -1 )
1210{
1211 setupUi ( this );
1212 t_virtue const & Virtue = this_base_data_editor->get();
1213
1214 setWindowTitle ( QString ( "Edit Attribute: %1" ).arg ( Virtue.p_name.c_str() ) );
1215 LineEdit->SetPopupMenu();
1216
1217 if ( Virtue.p_is_not_null )
1218 {
1219 this_base_data_editor->set_valid ( false );
1220 LineEdit->setPalette ( StyleUtility::WarningStatusBarPallete );
1221 }
1222 else
1223 {
1224 LineEdit->SetNullCheck ( false );
1225 }
1226
1227 if ( ! ( Virtue.p_type == dunedaq::conffwk::float_type
1228 || Virtue.p_type == dunedaq::conffwk::double_type ) )
1229 {
1231 {
1232 FormatBox->setCurrentIndex ( 2 );
1233 this_base = 8;
1234 this_native_base = 8;
1235 }
1237 {
1238 FormatBox->setCurrentIndex ( 0 );
1239 this_base = 10;
1240 this_native_base = 10;
1241 }
1243 {
1244 FormatBox->setCurrentIndex ( 1 );
1245 this_base = 16;
1246 this_native_base = 16;
1247 }
1248
1249 FormatBox->hide();
1250 }
1251 else
1252 {
1253 FormatBox->hide();
1254 }
1255
1256 SetController();
1257
1258 AttributeName->setText ( QString ( Virtue.p_name.c_str() ) + " : " );
1259 AttributeName->setHidden ( true );
1260 buildtooltip();
1261
1262 QString Dummy ( "Dummy" );
1263 UpdateActions ( Dummy );
1264}
1265
1266void numericattr::setdefaults ( const QString & ValueDefault )
1267{
1268 this_defaults = ValueDefault;
1269 LineEdit->SetDefaultValue ( this_defaults );
1270}
1271
1272QLineEdit * numericattr::GetLineEdit() const
1273{
1274 return LineEdit;
1275}
1276
1278{
1279 if ( this_data.isEmpty() )
1280 {
1281 return;
1282 }
1283
1284 LineEdit->clear();
1285
1287 if ( this_base == 16 )
1288 {
1289 if ( not this_data.value ( 0 ).startsWith ( "0x" ) )
1290 {
1291 LineEdit->setText ( "0x" + this_data.value ( 0 ) );
1292 }
1293 else
1294 {
1295 LineEdit->setText ( this_data.value ( 0 ) );
1296 }
1297 }
1298 else if ( this_base == 8 )
1299 {
1300 if ( not this_data.value ( 0 ).startsWith ( "0" ) and this_data.value ( 0 ) != 0 )
1301 {
1302 LineEdit->setText ( "0" + this_data.value ( 0 ) );
1303 }
1304 else
1305 {
1306 LineEdit->setText ( this_data.value ( 0 ) );
1307 }
1308 }
1309 else
1310 {
1311 LineEdit->setText ( this_data.value ( 0 ) );
1312 }
1313}
1314
1316{
1317 t_virtue const & Virtue = this_base_data_editor->get();
1318
1319 setToolTip (
1320 QString ( "Attribute Name: %1 \n" ).arg ( Virtue.p_name.c_str() ) + QString (
1321 " Type: %1 \n" ).arg (
1323 + QString ( " Range: %1 \n" ).arg ( Virtue.p_range.c_str() )
1324 + QString ( " Format: %1 \n" ).arg (
1326 + QString ( " Not Null: %1 \n" ).arg ( Virtue.p_is_not_null )
1327 + QString ( " Is Multi Value: %1 \n" ).arg ( Virtue.p_is_multi_value )
1328 + QString ( " Default Value: %1 \n" ).arg ( Virtue.p_default_value.c_str() )
1329 + QString ( " Description: %1 \n" ).arg ( Virtue.p_description.c_str() ) );
1330}
1331
1332void numericattr::closeEvent ( QCloseEvent * Event )
1333{
1334 Q_UNUSED ( Event )
1335 emit signal_force_close();
1336}
1337
1339{
1340 connect ( LineEdit, SIGNAL ( DecChange() ), this, SLOT ( ChangeFormatDec() ) );
1341 connect ( LineEdit, SIGNAL ( OctChange() ), this, SLOT ( ChangeFormatOct() ) );
1342 connect ( LineEdit, SIGNAL ( HexChange() ), this, SLOT ( ChangeFormatHex() ) );
1343
1344 connect ( FormatBox, SIGNAL ( currentIndexChanged ( int ) ),
1345 this, SLOT ( ChangeFormat ( int ) ), Qt::UniqueConnection );
1346
1347 connect ( LineEdit, SIGNAL ( editingFinished() ),
1348 this, SLOT ( AddToList() ), Qt::UniqueConnection );
1349 connect ( LineEdit, SIGNAL ( textChanged ( QString ) ),
1350 this, SLOT ( UpdateActions ( QString ) ), Qt::UniqueConnection );
1351 connect ( LineEdit, SIGNAL ( returnPressed () ),
1352 this, SLOT ( checkIfDuplicated () ), Qt::UniqueConnection );
1353
1354}
1355
1356void numericattr::ShowWarning ( QString Format, QString Range )
1357{
1358 LineEdit->setPalette ( StyleUtility::AlertStatusBarPallete );
1359
1360 t_virtue const & Virtue = this_base_data_editor->get();
1361
1362 QString Message = QString ( "The value for attribute %1 is in the wrong format" ).arg (
1363 Virtue.p_name.c_str() );
1364
1365 if ( Range != "" )
1366 {
1367 QString RangeMex = QString ( " - The value should be in the range : %1" ).arg ( Range );
1368 Message.append ( "\n\n" + RangeMex );
1369 }
1370
1371 if ( Format != "" )
1372 {
1373 Message.append ( QString ( "\n\n - The value should be formatted as a %1." ).arg (
1374 Format ) );
1375 }
1376
1377 QMessageBox::warning ( this, tr ( "Wrong value" ), Message );
1378 return;
1379}
1380
1381bool numericattr::ValidateIntegerValue ( QString const & text )
1382{
1383 auto checkInteger = [this, text]()
1384 {
1385 t_virtue const & input = this_base_data_editor->get();
1386
1387 bool convert_to_defined_base;
1388
1389 qlonglong NewLongLong{0};
1390 qulonglong NewULongLong{0};
1391
1392 auto check_convert = [this, &convert_to_defined_base]()
1393 {
1394 // If input cannot be converted to any base then show a warning and invalidate
1395
1396 if ( not convert_to_defined_base )
1397 {
1398 if ( this_native_base == 10 )
1399 {
1400 ShowWarning ( "DECIMAL" );
1401 }
1402 else if ( this_native_base == 16 )
1403 {
1404 ShowWarning ( "HEX-DECIMAL" );
1405 }
1406 else if ( this_native_base == 8 )
1407 {
1408 ShowWarning ( "OCT-DECIMAL" );
1409 }
1410
1411 return false;
1412 }
1413
1414 return true;
1415 };
1416
1417 if ( input.p_type == dunedaq::conffwk::u8_type
1421 {
1422 NewULongLong = text.toULongLong ( &convert_to_defined_base, this_base );
1423
1424 if ( not check_convert() )
1425 {
1426 return false;
1427 }
1428
1429 qulonglong min_u;
1430 qulonglong max_u;
1431
1432 if ( input.p_type == dunedaq::conffwk::u8_type )
1433 {
1434 min_u = 0;
1435 max_u = UCHAR_MAX;
1436 }
1437 else if ( input.p_type == dunedaq::conffwk::u16_type )
1438 {
1439 min_u = 0;
1440 max_u = USHRT_MAX;
1441 }
1442 else if ( input.p_type == dunedaq::conffwk::u32_type )
1443 {
1444 min_u = 0;
1445 max_u = ULONG_MAX;
1446 }
1447 else if ( input.p_type == dunedaq::conffwk::u64_type )
1448 {
1449 min_u = 0;
1450 max_u = ULONG_LONG_MAX;
1451 }
1452 else
1453 {
1454 return true;
1455 }
1456
1457 if ( min_u <= NewULongLong and NewULongLong <= max_u )
1458 {
1459 return true;
1460 }
1461
1462 ShowWarning ( "", QString ( "[%1 - %2]" ).arg ( min_u ).arg ( max_u ) );
1463 }
1464 else
1465 {
1466 NewLongLong = text.toLongLong ( &convert_to_defined_base, this_base );
1467
1468 if ( not check_convert() )
1469 {
1470 return false;
1471 }
1472
1473 qlonglong min_s;
1474 qlonglong max_s;
1475
1476 if ( input.p_type == dunedaq::conffwk::s8_type )
1477 {
1478 min_s = SCHAR_MIN;
1479 max_s = SCHAR_MAX;
1480 }
1481 else if ( input.p_type == dunedaq::conffwk::s16_type )
1482 {
1483 min_s = SHRT_MIN;
1484 max_s = SHRT_MAX;
1485 }
1486 else if ( input.p_type == dunedaq::conffwk::s32_type )
1487 {
1488 min_s = LONG_MIN;
1489 max_s = LONG_MAX;
1490 }
1491 else if ( input.p_type == dunedaq::conffwk::s64_type )
1492 {
1493 min_s = - ( LONG_LONG_MAX ) - 1;
1494 max_s = LONG_LONG_MAX;
1495 }
1496 else
1497 {
1498 return true;
1499 }
1500
1501 if ( min_s <= NewLongLong and NewLongLong <= max_s )
1502 {
1503 return true;
1504 }
1505
1506 ShowWarning ( "", QString ( "[%1 - %2]" ).arg ( min_s ).arg ( max_s ) );
1507 }
1508
1509 return false;
1510 };
1511
1512 return (checkInteger() && checkRange(text));
1513}
1514
1515bool numericattr::checkRange (QString const & Value)
1516{
1517 t_virtue const & Virtue = this_base_data_editor->get();
1518
1519 QString Range = QString::fromStdString ( Virtue.p_range );
1520
1521 if ( Range.isEmpty() )
1522 {
1523 return true;
1524 }
1525
1526 QStringList ValueList = Range.split ( "," );
1527
1528 QList<QPair<QString, QString>> RangeList;
1529
1530 for ( QString & RangeValue : ValueList )
1531 {
1532 if ( RangeValue.contains ( ".." ) )
1533 {
1534 QStringList Ranges = RangeValue.split ( ".." );
1535 RangeList.append ( QPair<QString, QString> ( Ranges.at ( 0 ), Ranges.at ( 1 ) ) );
1536 ValueList.removeOne ( RangeValue );
1537 }
1538 }
1539
1540 if ( ValueList.contains ( Value ) )
1541 {
1542 return true;
1543 }
1544
1545 for ( QPair<QString, QString> & ValuePair : RangeList )
1546 {
1547 if ( ValuePair.first == "*" )
1548 {
1549 if ( Value.toDouble() <= ValuePair.second.toDouble() )
1550 {
1551 return true;
1552 }
1553
1554 ShowWarning("", Range);
1555
1556 return false;
1557 }
1558
1559 else if ( ValuePair.second == "*" )
1560 {
1561 if ( Value.toDouble() >= ValuePair.first.toDouble() )
1562 {
1563 return true;
1564 }
1565
1566 ShowWarning("", Range);
1567
1568 return false;
1569 }
1570
1571 else
1572 {
1573 if ( ( Value.toDouble() >= ValuePair.first.toDouble() ) &&
1574 ( Value.toDouble() <= ValuePair.second.toDouble() ) )
1575 {
1576 return true;
1577 }
1578
1579 ShowWarning("", Range);
1580
1581 return false;
1582 }
1583 }
1584
1585 ShowWarning("", Range);
1586
1587 return false;
1588}
1589
1590bool numericattr::ValidateFloatValue ( QString const & Value )
1591{
1592 bool validValue = true;
1593
1594 t_virtue const & Virtue = this_base_data_editor->get();
1595
1596 if(Virtue.p_type == dunedaq::conffwk::float_type) {
1597 bool ok;
1598 Value.toFloat(&ok);
1599
1600 if(ok == false) {
1601 ShowWarning("FLOAT");
1602 validValue = false;
1603 }
1604 } else {
1605 bool ok;
1606 Value.toDouble(&ok);
1607
1608 if(ok == false) {
1609 ShowWarning("DOUBLE");
1610 validValue = false;
1611 }
1612 }
1613
1614 return (validValue && checkRange(Value));
1615}
1616
1618 // Emit a special signal when the Enter/Return key is pressed
1619 // and the data have not been changed
1620 // That is useful, for instance, for the multi-attribute
1621 // widget in order to add multiple times the same attribute
1622 // (you do not want to add the same value multiple times just
1623 // when the focus is lost)
1624 if ( this_data.contains(LineEdit->text()) ) {
1626 }
1627}
1628
1630{
1631 // No change in data, do nothing
1632 // It avoids some unwanted loops when focus is acquired/lost
1633 if ( this_data.contains(LineEdit->text()) ) {
1634 return;
1635 }
1636
1637 auto convert_to_proper_base = [this] (const QString& value) -> QString {
1638 if((value.isEmpty() == false) && (this_native_base != -1) && (this_native_base != this_base)) {
1639 QString cnvrtd;
1640
1641 t_virtue const & virtue = this_base_data_editor->get();
1642 bool Unsigned = ( virtue.p_type == dunedaq::conffwk::u8_type
1645 || virtue.p_type == dunedaq::conffwk::u64_type );
1646
1647 if(Unsigned == true) {
1648 cnvrtd.setNum(LineEdit->text().toULongLong(0, this_base), this_native_base);
1649 } else {
1650 cnvrtd.setNum(LineEdit->text().toLongLong(0, this_base), this_native_base);
1651 }
1652
1653 // Be careful to set the contextaul menu properly
1654 if(this_native_base == 8) {
1655 if(cnvrtd.startsWith("0") == false) {
1656 cnvrtd.insert(0, "0");
1657 }
1658 LineEdit->EmitOctSlot();
1659 } else if(this_native_base == 10) {
1660 LineEdit->EmitDecSlot();
1661 } else if(this_native_base == 16) {
1662 if(cnvrtd.startsWith("0x", Qt::CaseInsensitive) == false) {
1663 cnvrtd.insert(0, "0x");
1664 }
1665 LineEdit->EmitHexSlot();
1666 }
1667
1668 // The current and native bases are now the same
1670
1671 return cnvrtd;
1672 }
1673
1674 return value;
1675 };
1676
1677 LineEdit->blockSignals ( true );
1678
1679 BOOST_SCOPE_EXIT(this_)
1680 {
1681 this_->LineEdit->blockSignals ( false );
1682 }
1683 BOOST_SCOPE_EXIT_END
1684
1685 bool isValid = true;
1686
1687 QString input = LineEdit->text();
1688
1689 t_virtue const & virtue = this_base_data_editor->get();
1690 if ( ( virtue.p_type == dunedaq::conffwk::float_type
1692 {
1693 if (not ValidateFloatValue ( input )) {
1694 isValid = false;
1695 }
1696 } else if ( not ValidateIntegerValue ( input ) )
1697 {
1698 isValid = false;
1699 }
1700
1701 // ShowWarning("FLOAT", QString::fromStdString(virtue.p_name));
1702
1703 this_data.clear();
1704
1705 // We better save data in the proper format, in order to avoid issues
1706 // with conversions (and having data saved in a bad format)
1707 this_data.append ( convert_to_proper_base(input) );
1708
1709 this_value_changed = true;
1710
1711 if(isValid == true) {
1712 QString Dummy ( "Dummy" );
1713 UpdateActions ( Dummy );
1714 } else {
1715 this_base_data_editor->set_valid ( false );
1716 }
1717
1718 if ( not this_is_owned )
1719 {
1720 // Not owned: multiattr (connected to signal_value_change) and
1721 // CustomDelegate (connected to signal_edit_end and signal_force_close)
1722 if(isValid == true) {
1723 // Do not emit the signal in this case
1724 // The table will try t write data and get back an exception
1725 emit signal_edit_end();
1726 }
1727
1728 emit signal_value_change();
1729 }
1730 else
1731 {
1732 // Owned: ObjectEditor (connected to signal_value_change)
1733 emit signal_value_change();
1734 }
1735}
1736
1738{
1739 QString CurrentString = LineEdit->text();
1740
1741 if ( CurrentString.isEmpty() )
1742 {
1743 //if(DecButton->isChecked())
1744
1745 if ( i == 0 )
1746 {
1747 this_base = 10;
1748 }
1749
1750 //else if(OctButton->isChecked())
1751 else if ( i == 2 )
1752 {
1753 this_base = 8;
1754 }
1755
1756 //else if(HexButton->isChecked())
1757 else if ( i == 1 )
1758 {
1759 this_base = 16;
1760 }
1761
1762 return;
1763 }
1764
1765 QString ConvertedString;
1766 t_virtue const & Virtue = this_base_data_editor->get();
1767
1768 bool Unsigned = ( Virtue.p_type == dunedaq::conffwk::u8_type
1770 || Virtue.p_type == dunedaq::conffwk::u64_type );
1771 bool OkConversion = false;
1772
1773 //if(DecButton->isChecked())
1774
1775 if ( i == 0 )
1776 {
1777 if ( Unsigned )
1778 {
1779 ConvertedString.setNum ( CurrentString.toULongLong ( &OkConversion, 0 ), 10 );
1780 }
1781 else
1782 {
1783 ConvertedString.setNum ( CurrentString.toLongLong ( &OkConversion, 0 ), 10 );
1784 }
1785
1786 this_base = 10;
1787 }
1788
1789 //else if(OctButton->isChecked())
1790 else if ( i == 2 )
1791 {
1792 if ( Unsigned )
1793 {
1794 ConvertedString.setNum ( CurrentString.toULongLong ( &OkConversion, 0 ), 8 );
1795 }
1796 else
1797 {
1798 ConvertedString.setNum ( CurrentString.toLongLong ( &OkConversion, 0 ), 8 );
1799 }
1800
1801 ConvertedString.insert(0, "0");
1802 this_base = 8;
1803 }
1804
1805 //else if(HexButton->isChecked())
1806 else if ( i == 1 )
1807 {
1808 if ( Unsigned )
1809 {
1810 ConvertedString.setNum ( CurrentString.toULongLong ( &OkConversion, 0 ), 16 );
1811 }
1812 else
1813 {
1814 ConvertedString.setNum ( CurrentString.toLongLong ( &OkConversion, 0 ), 16 );
1815 }
1816
1817 ConvertedString.insert(0, "0x");
1818 this_base = 16;
1819 }
1820
1821 if ( !OkConversion )
1822 {
1823 QString Format;
1824
1825 if ( this_native_base == 10 )
1826 {
1827 Format = "DECIMAL";
1828 }
1829 else if ( this_native_base == 16 )
1830 {
1831 Format = "HEX-DECIMAL";
1832 }
1833 else if ( this_native_base == 8 )
1834 {
1835 Format = "OCT-DECIMAL";
1836 }
1837
1838 ShowWarning ( Format );
1839
1840 return;
1841 }
1842
1843 if ( !ConvertedString.isEmpty() )
1844 {
1845 LineEdit->clear();
1846 LineEdit->setText ( ConvertedString );
1847 }
1848}
1849
1850void numericattr::UpdateActions ( QString Dummy )
1851{
1852 Q_UNUSED ( Dummy )
1853
1854 if ( this_base_data_editor->must_not_be_null() and ( LineEdit->text().isEmpty() ) )
1855 {
1856 this_base_data_editor->set_valid ( false );
1857 }
1858 else if ( this_base_data_editor->must_not_be_null() and ( this_data.size() == 0 ) )
1859 {
1860 this_base_data_editor->set_valid ( false );
1861 }
1862 else
1863 {
1864 this_base_data_editor->set_valid ( true );
1865 }
1866}
1867
1869{
1870 ChangeFormat ( 0 );
1871}
1872
1874{
1875 ChangeFormat ( 1 );
1876}
1877
1879{
1880 ChangeFormat ( 2 );
1881}
1882
1883//------------------------------------------------------------------------------------------------
1884
1885//------------------------------------------------------------------------------------------------
1886combo::combo ( t_virtue const & attr, QWidget * parent,
1887 bool owned )
1888 :
1889 base ( std::make_shared<t_build_block_editor> ( attr ), parent, owned ),
1890 m_base_data_editor ( std::static_pointer_cast<t_build_block_editor> ( p_data_editor ) )
1891{
1892 setupUi ( this );
1893 SetController();
1895 Combo->setFocusPolicy ( Qt::ClickFocus );
1896 Combo->installEventFilter ( this );
1897
1898 if ( Combo->lineEdit() != nullptr )
1899 {
1900 Combo->lineEdit()->installEventFilter ( this );
1901 }
1902
1903 t_virtue const & Virtue = m_base_data_editor->get();
1904
1905 if ( Virtue.p_type == dunedaq::conffwk::class_type )
1906 {
1907 Combo->setEditable ( true );
1908 }
1909}
1910
1911void combo::SetData ( QStringList const & Data )
1912{
1913 if ( Data.isEmpty() )
1914 {
1915 return;
1916 }
1917
1918 int Index = Combo->findText ( Data.value ( 0 ) );
1919
1920 if ( Index != -1 )
1921 {
1922 Combo->setCurrentIndex ( Index );
1923 Combo->setEditText ( Data.value ( 0 ) );
1924 }
1925}
1926
1927void combo::SetValidatorData ( QStringList const & Data, bool AcceptNoMatch )
1928{
1929 Combo->clear();
1930 Combo->addItems ( Data );
1931
1932 QCompleter * Completer = new QCompleter ( Combo->model(), Combo );
1933 Completer->setCaseSensitivity ( Qt::CaseInsensitive );
1934 Completer->setCompletionMode ( QCompleter::PopupCompletion );
1935 Completer->setFilterMode(Qt::MatchContains);
1936
1937 Combo->setCompleter ( Completer );
1938
1939 m_base_data_editor->set_obligatory ( false );
1940
1941 QVariant VarFromList ( Data );
1942
1943 if ( AcceptNoMatch )
1944 {
1945 ValidatorAcceptNoMatch * TmpValidator = new ValidatorAcceptNoMatch ( VarFromList, this );
1946 Combo->setValidator ( TmpValidator );
1947 }
1948
1949 else
1950 {
1951 ValidatorAcceptMatch * TmpValidator = new ValidatorAcceptMatch ( VarFromList, this );
1952 Combo->setValidator ( TmpValidator );
1953 }
1954}
1955
1956QStringList combo::getdata()
1957{
1958 this_data.clear();
1959 this_data << Combo->currentText();
1960 return this_data;
1961}
1962
1964{
1965 t_virtue const & virt = m_base_data_editor->get();
1966
1967 if ( virt.p_type == dunedaq::conffwk::bool_type )
1968 {
1969 QStringList tmp
1970 { "true", "false" };
1971 SetValidatorData ( tmp );
1972 }
1973 else if ( virt.p_type == dunedaq::conffwk::enum_type )
1974 {
1975 QString rangename = virt.p_range.c_str();
1976 QStringList range = rangename.split ( "," );
1977 range.sort();
1978 SetValidatorData ( range );
1979 }
1980 else if ( virt.p_type == dunedaq::conffwk::class_type )
1981 {
1983 classes.sort();
1984 SetValidatorData ( classes );
1985 }
1986
1987 SetData ( this_data );
1988}
1989
1990void combo::setdata ( QStringList const & v )
1991{
1992 this_data = v;
1993}
1994
1995bool combo::eventFilter ( QObject * Target, QEvent * Event )
1996{
1997 if ( Target == Combo->lineEdit() && Event->type() == QEvent::MouseButtonRelease )
1998 {
1999 if ( !Combo->lineEdit()->hasSelectedText() )
2000 {
2001 Combo->lineEdit()->selectAll();
2002 return true;
2003 }
2004 }
2005
2006 if ( Event->type() == QEvent::Wheel )
2007 {
2008 return true;
2009 }
2010
2011 return false;
2012}
2013
2014void combo::wheelEvent ( QWheelEvent * Event )
2015{
2016 Q_UNUSED ( Event )
2017 return;
2018}
2019
2021{
2022 connect ( Combo, SIGNAL ( editTextChanged ( const QString & ) ), this,
2023 SLOT ( TryValidate ( const QString & ) ), Qt::UniqueConnection );
2024 connect ( Combo, SIGNAL ( activated ( const QString & ) ), this,
2025 SLOT ( ChangeDetected ( const QString & ) ), Qt::UniqueConnection );
2026 connect ( Combo, SIGNAL ( currentIndexChanged ( int ) ), this,
2027 SLOT ( CheckDefaults ( int ) ),
2028 Qt::UniqueConnection );
2029}
2030
2031void combo::TryValidate ( QString tmp )
2032{
2033 int index = 0;
2034
2035 if ( Combo->validator() != nullptr )
2036 {
2037 if ( Combo->validator()->validate ( tmp, index ) == QValidator::Acceptable )
2038 {
2039 m_base_data_editor->set_valid ( true );
2040
2041 if ( CompareDefaults() )
2042 {
2043 Combo->setPalette ( StyleUtility::LoadedDefault );
2044 }
2045
2046 else
2047 {
2048 Combo->setPalette ( QApplication::palette ( this ) );
2049 }
2050 }
2051
2052 else if ( Combo->validator()->validate ( tmp, index ) == QValidator::Intermediate )
2053 {
2054 m_base_data_editor->set_not_null ( false );
2055 Combo->setPalette ( StyleUtility::WarningStatusBarPallete );
2056 }
2057 }
2058
2059 else
2060 {
2061 if ( CompareDefaults() )
2062 {
2063 Combo->setPalette ( StyleUtility::LoadedDefault );
2064 }
2065 else
2066 {
2067 Combo->setPalette ( QApplication::palette ( this ) );
2068 }
2069 }
2070}
2071
2072void combo::ChangeDetected ( const QString & StringChange )
2073{
2074 Q_UNUSED ( StringChange )
2075 this_value_changed = true;
2076 emit signal_value_change();
2077}
2078
2079void combo::CheckDefaults ( int DefaultIndex )
2080{
2081 Q_UNUSED ( DefaultIndex )
2082
2083 if ( !this_defaults.isEmpty() )
2084 {
2085 TryValidate ( Combo->currentText() );
2086 }
2087}
2088
2090{
2091 if ( this_defaults.isEmpty() )
2092 {
2093 return false;
2094 }
2095
2096 if ( this_defaults == Combo->currentText() )
2097 {
2098 return true;
2099 }
2100
2101 return false;
2102}
2103
2106
2107//------------------------------------------------------------------------------------------------
2108
2109//------------------------------------------------------------------------------------------------
2110multiattr::multiattr ( t_virtue const & attr, QWidget * parent,
2111 bool owned )
2112 :
2113 base ( std::make_shared<t_build_block_editor> ( attr ), parent, owned ),
2114 m_base_data_editor ( std::static_pointer_cast<t_build_block_editor> ( p_data_editor ) ),
2115 StatusBar ( nullptr ),
2116 OkButton ( nullptr ),
2117 RemoveButton ( nullptr ),
2118 ListWidget ( nullptr ),
2119 ContextMenu ( nullptr ),
2120 RemoveAction ( nullptr )
2121{
2122 t_virtue const & Virtue = m_base_data_editor->get();
2123
2124 setWindowTitle ( QString ( "Edit Attribute : %1" ).arg ( Virtue.p_name.c_str() ) );
2125 QVBoxLayout * MainLayout = new QVBoxLayout ( this );
2126 MainLayout->setSpacing ( 0 );
2127 MainLayout->setMargin ( 0 );
2128 MainLayout->setContentsMargins ( 0, 0, 0, 0 );
2129 QHBoxLayout * ButtonLayout = new QHBoxLayout();
2130 ListWidget = new QListWidget ( this );
2131 ListWidget->setContextMenuPolicy ( Qt::CustomContextMenu );
2132
2133 switch ( Virtue.p_type )
2134 {
2135 // Bool and enums have the same widget
2136
2140 {
2141 combo * Combo = new combo ( attr, this );
2142 MainLayout->addWidget ( Combo );
2143 connect ( Combo->Combo, SIGNAL ( activated ( const QString & ) ), this,
2144 SLOT ( AddToDataList ( const QString & ) ), Qt::UniqueConnection );
2145 BaseWidget = Combo;
2146
2147 break;
2148 }
2149
2150 // All numeric types are treated as uint64
2151
2162 {
2163 numericattr * Numeric = new numericattr ( Virtue, this );
2164 MainLayout->addWidget ( Numeric );
2165 connect ( Numeric, SIGNAL ( signal_value_change() ), this, SLOT ( LineValueChanged() ),
2166 Qt::UniqueConnection );
2167 connect ( Numeric, SIGNAL ( signal_value_duplicated() ), this, SLOT ( LineValueChanged() ),
2168 Qt::UniqueConnection );
2169 BaseWidget = Numeric;
2171 Numeric->GetLineEdit()->setFrame ( false );
2172 Numeric->GetLineEdit()->setPlaceholderText ( "Type Here" );
2173 Numeric->setStyleSheet (
2174 "QLineEdit { background: #c0c0c0;} QLineEdit:focus {background: white;}" );
2175 Numeric->GetLineEdit()->setFixedHeight ( 24 );
2176 ListWidget->setFrameStyle ( QFrame::NoFrame );
2177 break;
2178 }
2179
2180 // Types below are all treated as string types
2181
2185 {
2186 stringattr * String = new stringattr ( Virtue, this );
2187 String->SetMultiCheck ( true );
2188 MainLayout->addWidget ( String );
2189 connect ( String, SIGNAL ( signal_value_change() ), this, SLOT ( LineValueChanged() ),
2190 Qt::UniqueConnection );
2191 BaseWidget = String;
2193 String->GetLineEdit()->setFrameStyle(QFrame::NoFrame);
2194// String->GetLineEdit()->setPlaceholderText ( "Type here" );
2195 String->setStyleSheet ( "QLineEdit { background: #c0c0c0;} "
2196 "QLineEdit:focus {background: white;}" );
2197// String->GetLineEdit()->setFixedHeight ( 24 );
2198
2199 ListWidget->setFrameStyle ( QFrame::NoFrame );
2200 break;
2201 }
2202
2203 default:
2204 break;
2205 }
2206
2207 OkButton = new QPushButton ( tr ( "Apply" ) );
2208 //RemoveButton = new QPushButton(tr("Remove"));
2209 ButtonLayout->addWidget ( OkButton );
2210 //ButtonLayout->addWidget(RemoveButton);
2211 connect ( OkButton, SIGNAL ( clicked() ), this, SLOT ( EndSignal() ) );
2212 //connect(RemoveButton,SIGNAL(clicked()),this,SLOT(RemoveFromDataList()));
2213 connect ( this, SIGNAL ( signal_internal_value_change() ), this, SLOT ( UpdateActions() ) );
2214 connect ( ListWidget, SIGNAL ( customContextMenuRequested ( QPoint ) ), this,
2215 SLOT ( CustomContextMenuRequested ( QPoint ) ) );
2216
2217 MainLayout->addWidget ( ListWidget );
2218 MainLayout->addLayout ( ButtonLayout );
2219 SetStatusBar();
2220 MainLayout->addWidget ( StatusBar );
2221
2222 setLayout ( MainLayout );
2223
2224 if ( Virtue.p_is_not_null )
2225 {
2226 m_base_data_editor->set_valid ( false );
2227 OkButton->setDisabled ( true );
2228 }
2229
2230 if ( this_is_owned )
2231 {
2232 OkButton->setHidden ( true );
2233 }
2234
2235 else
2236 {
2237 QFont Font;
2238 QFontMetrics FontMetrics ( Font );
2239 setMinimumWidth (
2240 2 * FontMetrics.horizontalAdvance ( QString ( "Edit Relationship: %1" ).arg ( Virtue.p_name.c_str() ) )
2241 - 15 );
2242 setMinimumHeight ( 100 );
2243 }
2244
2245 buildtooltip();
2246 UpdateActions();
2247}
2248
2250{
2251 BaseWidget->SetEditor();
2252
2253 ListWidget->clear();
2254 ListWidget->addItems ( this_data );
2255 ListWidget->setSelectionMode ( QAbstractItemView::ExtendedSelection );
2256 ListWidget->setDragEnabled ( true );
2257 ListWidget->setAcceptDrops ( true );
2258 ListWidget->setEditTriggers ( QAbstractItemView::DoubleClicked );
2259 ListWidget->setDragDropMode ( QAbstractItemView::InternalMove );
2260
2261 for ( int i = 0; i < ListWidget->count(); ++i )
2262 {
2263 QListWidgetItem * widget = ListWidget->item ( i );
2264 widget->setFlags (
2265 Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled
2266 | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled );
2267
2268 }
2269
2270 connect ( ListWidget, SIGNAL ( itemChanged ( QListWidgetItem * ) ), this,
2271 SLOT ( LineValueChanged ( QListWidgetItem * ) ) );
2273}
2274
2276{
2277 t_virtue const & Virtue = m_base_data_editor->get();
2278
2279 setToolTip (
2280 QString ( "Attribute Name: %1 \n" ).arg ( Virtue.p_name.c_str() ) + QString (
2281 " Type: %1 \n" ).arg (
2283 + QString ( " Range: %1 \n" ).arg ( Virtue.p_range.c_str() )
2284 + QString ( " Format: %1 \n" ).arg (
2286 + QString ( " Not Null: %1 \n" ).arg ( Virtue.p_is_not_null )
2287 + QString ( " Is Multi Value: %1 \n" ).arg ( Virtue.p_is_multi_value )
2288 + QString ( " Default Value: %1 \n" ).arg ( Virtue.p_default_value.c_str() )
2289 + QString ( " Description: %1 \n" ).arg ( Virtue.p_description.c_str() ) );
2290}
2291
2292void multiattr::closeEvent ( QCloseEvent * Event )
2293{
2294 Q_UNUSED ( Event )
2295 emit signal_force_close();
2296}
2297
2299{
2300 StatusBar = new QStatusBar ( this );
2301 StatusBar->setSizeGripEnabled ( false );
2303 StatusBar->setAutoFillBackground ( true );
2305 StatusBar->setHidden ( true );
2306}
2307
2308bool multiattr::eventFilter ( QObject * Target, QEvent * Event )
2309{
2310 ( void ) Target;
2311 ( void ) Event;
2312 return false;
2313}
2314
2315void multiattr::AddToDataList ( const QString & Data )
2316{
2317 if ( Data.isEmpty() )
2318 {
2319 return;
2320 }
2321
2322 this_data.append ( Data );
2323
2324 ListWidget->clear();
2325 ListWidget->addItems ( this_data );
2326 StatusBar->showMessage ( QString ( "Item %1 was added." ).arg ( Data ) );
2327
2328 this_value_changed = true;
2330}
2331
2333{
2334 QList<QListWidgetItem *> widgets = ListWidget->selectedItems();
2335 this_value_changed = true;
2336
2337 for ( QListWidgetItem * widget : widgets )
2338 {
2339 int index = this_data.indexOf ( widget->text() );
2340
2341 if ( index != -1 )
2342 {
2343 this_data.takeAt ( index );
2344 }
2345
2346 int r = ListWidget->row ( widget );
2347
2348 if ( QListWidgetItem * w = ListWidget->takeItem ( r ) )
2349 {
2350 delete w;
2351 }
2352
2353 }
2354
2355 if ( this_is_owned )
2356 {
2357 StatusBar->showMessage ( "The selected items were removed." );
2358 }
2359
2360 if ( dynamic_cast<stringattr *> ( BaseWidget ) )
2361 {
2363 stringattr * StringWidget = dynamic_cast<stringattr *> ( BaseWidget );
2364 StringWidget->GetLineEdit()->selectAll();
2365 StringWidget->GetLineEdit()->clear();
2366 StringWidget->SetCheckDefaults ( false );
2367 StringWidget->SetNullCheck ( true );
2368 }
2369
2371 emit signal_value_change();
2372}
2373
2375{
2376 t_virtue const & Virtue = m_base_data_editor->get();
2377
2378 if ( Virtue.p_is_not_null and this_data.size() == 0 )
2379 {
2380 OkButton->setDisabled ( true );
2381 StatusBar->showMessage ( "Attribute can not be null." );
2382 m_base_data_editor->set_valid ( false );
2385 }
2386
2387 else if ( Virtue.p_is_not_null and this_data.size() > 0 )
2388 {
2390
2391 StatusBar->showMessage ( "Attribute is set." );
2392 ListWidget->setPalette ( QApplication::palette ( this ) );
2393 OkButton->setEnabled ( true );
2394 m_base_data_editor->set_valid ( true );
2395
2396 if ( this_is_owned )
2397 {
2398 EndSignal();
2399 }
2400 }
2401 else if ( not Virtue.p_is_not_null and this_is_owned )
2402 {
2403 m_base_data_editor->set_valid ( true );
2404 EndSignal();
2405 }
2406}
2407
2409{
2410 QStringList Data = BaseWidget->getdata();
2411
2412 if ( (!Data.isEmpty()) && BaseWidget->dataeditor()->is_valid())
2413 {
2414 AddToDataList ( Data.at ( 0 ) );
2415 }
2416}
2417
2418void multiattr::LineValueChanged ( QListWidgetItem * changed )
2419{
2420 int r = ListWidget->row ( changed );
2421 QString newtext = changed->text();
2422 QString oldtext = this_data.at ( r );
2423 this_data.replace ( r, newtext );
2424 this_value_changed = true;
2425
2426 StatusBar->showMessage ( QString ( "Item %1 was modified." ).arg ( oldtext ) );
2427
2429}
2430
2431void multiattr::ListOrderChange ( const QModelIndexList & IndexList )
2432{
2433 Q_UNUSED ( IndexList )
2434
2435 this_data.clear();
2436
2437 for ( int i = 0; i < ListWidget->count(); ++i )
2438 {
2439 this_data.append ( ListWidget->item ( i )->text() );
2440 }
2441}
2442
2444{
2445 this_data.clear();
2446
2447 for ( int i = 0; i < ListWidget->count(); ++i )
2448 {
2449 this_data.append ( ListWidget->item ( i )->text() );
2450 }
2451
2452 if ( !this_is_owned )
2453 {
2454 m_base_data_editor->set_valid ( true );
2455 emit signal_edit_end();
2456 }
2457
2458 else
2459 {
2460 emit signal_value_change();
2461 }
2462}
2463
2464void multiattr::CustomContextMenuRequested ( const QPoint & pos )
2465{
2466 if ( ContextMenu == nullptr )
2467 {
2468 ContextMenu = new QMenu ( ListWidget );
2469
2470 RemoveAction = new QAction ( tr ( "Remove" ), this );
2471 RemoveAction->setShortcutContext ( Qt::WidgetShortcut );
2472 connect ( RemoveAction, SIGNAL ( triggered() ), this, SLOT ( RemoveSlot() ),
2473 Qt::UniqueConnection );
2474 ContextMenu->addAction ( RemoveAction );
2475 }
2476
2477 ContextMenu->exec ( ListWidget->mapToGlobal ( pos ) );
2478}
2479
2484
2485//------------------------------------------------------------------------------------------------
2486
2487} // end namespace editors
2488} // end namespace widgets
2489} // end namespace dbe
2490
2491//------------------------------------------------------------------------------------------------
static QPalette AlertStatusBarPallete
static QPalette LoadedDefault
static QPalette WarningStatusBarPallete
static confaccessor & ref()
static bool derived(std::string const &fromclass, std::string const &aclass)
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
virtual ~editor_data_state()
editor_data_state(bool isvalid, bool isnotnull, bool isobligatory)
virtual ~editor_data()
editor_data(T const &virtue)
static configobject::tref get(dbe::cokey const &desc)
virtual void setdata(QStringList const &)
base(std::shared_ptr< editor_data_state > editordata, QWidget *parent=nullptr, bool owned=false)
std::shared_ptr< editor_data_state > p_data_editor
virtual void closeEvent(QCloseEvent *Event)
virtual void setdefaults(QString const &)
dunedaq::conffwk::attribute_t t_virtue
void SetValidatorData(QStringList const &Data, bool AcceptNoMatch=false)
std::shared_ptr< t_build_block_editor > m_base_data_editor
editor_data< t_virtue > t_build_block_editor
combo(t_virtue const &attr, QWidget *parent=nullptr, bool owned=false)
void setdata(QStringList const &)
bool eventFilter(QObject *, QEvent *)
void SetData(QStringList const &)
void CustomContextMenuRequested(const QPoint &pos)
multiattr(t_virtue const &attr, QWidget *parent=nullptr, bool owned=false)
editor_data< t_virtue > t_build_block_editor
std::shared_ptr< t_build_block_editor > m_base_data_editor
bool eventFilter(QObject *Target, QEvent *Event)
void ListOrderChange(const QModelIndexList &IndexList)
dunedaq::conffwk::attribute_t t_virtue
numericattr(t_virtue const &attr, QWidget *parent=nullptr, bool owned=false)
virtual void setdefaults(const QString &ValueDefault)
std::shared_ptr< t_build_block_editor > this_base_data_editor
void ShowWarning(QString Format="", QString Range="")
dunedaq::conffwk::attribute_t t_virtue
void DataWasFetched(QStringList ListOfObjects)
dunedaq::conffwk::relationship_t t_virtue
relation(t_virtue const &relation, QWidget *parent=nullptr, bool owned=false)
editor_data< t_virtue > t_build_block_editor
void AddToDataList(const QString &DataValue)
void CustomContextMenuRequested(const QPoint &pos)
void FetchDataDone(QStringList Data)
std::shared_ptr< t_build_block_editor > p_base_data_editor
void CreateObjectEditor(const std::string &objectID)
void EditItemEntered(QListWidgetItem *Item)
bool eventFilter(QObject *Target, QEvent *Event)
stringattr(t_virtue const &attr, QWidget *parent=nullptr, bool owned=false)
std::shared_ptr< t_build_block_editor > m_base_data_editor
dunedaq::conffwk::attribute_t t_virtue
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:35
config_object_description dref
static const char * type2str(type_t type)
static const char * format2str(int_format_t format)
static const char * card2str(cardinality_t cardinality)