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