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