DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::models::table Class Reference

#include <table.hpp>

Inheritance diagram for dbe::models::table:
[legend]
Collaboration diagram for dbe::models::table:
[legend]

Public Types

typedef TableNode type_datum
 

Public Slots

void slot_data_dropped (QMimeData const &, Qt::DropAction)
 

Signals

void ResetTab ()
 

Public Member Functions

 table (QObject *parent=nullptr)
 Including QT Headers.
 
 ~table ()
 
int rowCount (type_index const &parent) const override
 
int columnCount (type_index const &parent) const override
 
QVariant data (type_index const &index, int role) const override
 
bool setData (type_index const &index, const QVariant &value, int role) override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
Qt::ItemFlags flags (type_index const &index) const override
 
TableNodegetnode (const QModelIndex &Index) const
 
QStringList mimeTypes () const override
 
Qt::DropActions supportedDropActions () const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
 
void ResetModel ()
 
bool BuildTableFromClass (const QString &ClassName, bool BuildSubClasses=false)
 
bool BuildTableFromObject (QList< QStringList > BuildList)
 
bool is_built () const
 
QString get_class_name () const
 
tref GetTableObject (int ObjectIndex) const
 
QList< dbe::dref > * GetTableObjects ()
 
void objectsUpdated (const std::vector< dbe::dref > &objects)
 
- Public Member Functions inherited from dbe::model_common_impl< table >
bool delete_objects (type_indices::iterator, type_indices::iterator) override
 
bool update_objects (type_indices::iterator, type_indices::iterator) override
 
bool create_objects (type_indices::iterator, type_indices::iterator) override
 
- Public Member Functions inherited from dbe::model_common_interface
virtual ~model_common_interface ()=default
 
- Public Member Functions inherited from dbe::model_initiate_actions_interface
virtual ~model_initiate_actions_interface ()=default
 
- Public Member Functions inherited from dbe::model_common_data_access_interface
virtual type_object_ref getobject (type_index const &index) const =0
 
virtual type_class_info getclass (type_index const &index) const =0
 
virtual QAbstractItemModel * ReturnSourceModel () const =0
 
virtual ~model_common_data_access_interface ()=default
 
- Public Member Functions inherited from dbe::model_common_async_operations< table >
MODEL_COMMON_TYPES_TOPLEVEL_DEFINITIONS model_common_async_operations ()
 
void model_common_connections ()
 

Private Slots

void slot_create_object (QString const &src, dref const &obj)
 
void slot_remove_object (QString const &src, dref const &obj)
 
void slot_update_object (QString const &src, dref const &obj)
 
void slot_rename_object (QString const &src, dref const &obj)
 

Private Member Functions

void reset (QString const &)
 
void setheader (dunedaq::conffwk::class_t const &)
 
QList< type_datum * > createrow (treenode const *)
 

Private Attributes

bool enabled
 
QString this_class_name
 
dunedaq::conffwk::class_t class_type_info
 
QStringList this_headers
 
QList< drefthis_objects
 
QList< QList< TableNode * > > this_structure
 

Additional Inherited Members

- Protected Member Functions inherited from dbe::model_common_interface
virtual void remove_deleted_object (type_index const &index)=0
 
virtual void rename_contained_object (type_index const &index, type_object_info const &obj)=0
 
virtual void update_contained_object (type_index const &index, type_object_info const &obj)=0
 
virtual void create_contained_object (type_index const &index, type_object_info const &obj)=0
 
virtual type_index lookup (type_object_info const &)=0
 
QUuid getuuid () const
 
- Protected Member Functions inherited from dbe::model_common_async_operations< table >
void remove_object (type_object_info const &)
 
void create_object (type_object_info const &)
 
void rename_object (type_object_info const &)
 
void update_object (type_object_info const &)
 
void update_multiple_objects (std::vector< type_object_info > const &)
 

Detailed Description

Definition at line 18 of file table.hpp.

Member Typedef Documentation

◆ type_datum

Constructor & Destructor Documentation

◆ table()

dbe::models::table::table ( QObject * parent = nullptr)
explicit

Including QT Headers.

Definition at line 18 of file table.cpp.

19 : QAbstractTableModel ( parent ),
20 enabled ( false )
21{
23}

◆ ~table()

dbe::models::table::~table ( )

Definition at line 25 of file table.cpp.

26{}

Member Function Documentation

◆ BuildTableFromClass()

bool dbe::models::table::BuildTableFromClass ( const QString & ClassName,
bool BuildSubClasses = false )

Looping over classes Only in the case of derived classes this will be more than one

All objects from that class

Definition at line 263 of file table.cpp.

264{
265 reset ( cname );
266
268
270 cname.toStdString(),
271 false );
272
273 setheader ( classinfo );
274
275 if ( treenode * NodeClass = dbaccess_guard->getnode ( cname ) )
276 {
277 std::vector<treenode *> classnodes
278 { NodeClass };
279
280 if ( include_derived )
281 {
282
283 for ( std::string const & sbcname : classinfo.p_subclasses )
284 {
285 if ( treenode * sbcnode = dbaccess_guard->getnode ( sbcname ) )
286 {
287 classnodes.push_back ( sbcnode );
288 }
289 }
290 }
291
294
295 for ( treenode * clelement : classnodes )
296 {
298
299 for ( treenode * child : clelement->GetChildren() )
300 {
301 this_structure.append ( createrow ( child ) );
302 }
303 }
304
305 enabled = true;
306 return true;
307 }
308 else
309 {
310 return false;
311 }
312}
Definition cptr.hpp:50
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
QList< type_datum * > createrow(treenode const *)
Definition table.cpp:314
void reset(QString const &)
Definition table.cpp:387
void setheader(dunedaq::conffwk::class_t const &)
Definition table.cpp:401
QList< QList< TableNode * > > this_structure
Definition table.hpp:76
const std::vector< std::string > p_subclasses
Definition Schema.hpp:162

◆ BuildTableFromObject()

bool dbe::models::table::BuildTableFromObject ( QList< QStringList > BuildList)

Definition at line 426 of file table.cpp.

427{
428 reset ( BuildList.at ( 0 ).at ( 1 ) );
429
430 treenode * classnode = confaccessor::gethandler()->getnode ( this_class_name );
431
433 this_class_name.toStdString(),
434 false );
435
436 setheader ( classinfo );
437
438 confaccessor::gethandler()->FetchMore ( classnode );
439
440 for ( const QStringList & i : BuildList )
441 {
442 QString name = i.at ( 0 );
443 treenode * node = confaccessor::gethandler()->getnode ( this_class_name, name );
444 this_structure.append ( createrow ( node ) );
445 }
446
447 enabled = false;
448 return true;
449}
QString this_class_name
Definition table.hpp:71

◆ columnCount()

int dbe::models::table::columnCount ( type_index const & parent) const
override

Definition at line 38 of file table.cpp.

39{
40 if( !parent.isValid() ) {
41 return this_headers.size();
42 }
43
44 return 0;
45}
QStringList this_headers
Definition table.hpp:74

◆ createrow()

QList< dbe::models::table::type_datum * > dbe::models::table::createrow ( treenode const * rownode)
private

Definition at line 314 of file table.cpp.

316{
317
318 dref obj = rownode->GetObject();
319
320 this_objects.append ( obj );
321
323 obj.class_name(),
324 false );
325 std::vector<dunedaq::conffwk::attribute_t> const & attributes = cdef.p_attributes;
326 std::vector<dunedaq::conffwk::relationship_t> const & relations = cdef.p_relationships;
327
328 assert ( attributes.size() + relations.size() < 1025 );
329 std::bitset<1024> hindex; // maximum number of columns to display
330
331 {
332 int column = 0;
333
334 for ( dunedaq::conffwk::attribute_t const & attr : attributes )
335 {
336 hindex.set ( column++, this_headers.contains ( QString::fromStdString ( attr.p_name ) ) );
337 }
338
339 for ( dunedaq::conffwk::relationship_t const & rel : relations )
340 {
341 hindex.set ( column++, this_headers.contains ( QString::fromStdString ( rel.p_name ) ) );
342 }
343 }
344
345 // Create the row for this object
346 QList<TableNode *> Row;
347 Row.append ( new TableNode (
348 QStringList {rownode->GetData ( 0 ).toString()},
349 QVariant(QString::fromStdString(cdef.p_description))));
350 {
351 // Loop over object values and add them to the row
352 // Values are represent as nodes ( attributes or relations ) and these contain
353 // the structured data associated either with a attribute / multi-attribute or a relation
354 std::size_t column = 0;
355
356 for ( treenode * valuenode : rownode->GetChildren() )
357 {
358 QStringList values;
359 // Every valuenode has its attributes and relations defined as its childs
360
361 if ( hindex[column++] )
362 {
363
364 for ( treenode * nodevalues : valuenode->GetChildren() )
365 {
366 // Here we need to filter such that only values corresponding to the header are kept
367 // Add only the first of values in a list of values
368 values.append ( nodevalues->GetData ( 0 ).toString() );
369 }
370
371 if ( AttributeNode * NodeAttribute = dynamic_cast<AttributeNode *> ( valuenode ) )
372 {
373 Row.append ( new TableAttributeNode ( NodeAttribute->attribute_t(), values ) );
374 }
375 else if ( RelationshipNode * NodeRelationship =
376 dynamic_cast<RelationshipNode *> ( valuenode ) )
377 {
378 Row.append ( new TableRelationshipNode ( NodeRelationship->relation_t(), values ) );
379 }
380 }
381 }
382 }
383
384 return Row;
385}
QList< dref > this_objects
Definition table.hpp:75
std::vector< T > attributes(tref const &item)
std::vector< T > relations(tref const &item)
config_object_description dref
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:163
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:164
std::string p_description
Definition Schema.hpp:158

◆ data()

QVariant dbe::models::table::data ( type_index const & index,
int role ) const
override

Definition at line 47 of file table.cpp.

48{
49
50 if ( index.isValid() )
51 {
52 TableNode * TableItem = getnode ( index );
53
54 if ( role == Qt::DisplayRole )
55 {
56 QString Data;
57
58 for ( QString const & i : TableItem->GetData() )
59 {
60 static QString space
61 { ", " };
62 Data.append(i).append(space);
63 }
64 Data.remove(Data.length() - 2, 2);
65
66 return QVariant ( Data );
67 }
68
69 if ( role == Qt::ToolTipRole )
70 {
71 return TableItem->get_tooltip();
72 }
73 if ( role == Qt::FontRole )
74 {
75 if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
76 return QFont ( "Helvetica", 10, -1,
77 false );
78 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
79 return QFont ( "Courier", 10,
80 QFont::Bold );
81 else
82 {
83 return QFont ( "SansSerif", 10, QFont::Bold );
84 }
85 }
86
87 if ( role == Qt::ForegroundRole )
88 {
89 if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
90 return QBrush (
92 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
93 return QBrush (
95 else
96 {
97 return QVariant();
98 }
99 }
100
101 if ( role == Qt::BackgroundRole )
102 {
103 auto attr_node = dynamic_cast<TableAttributeNode *> ( TableItem );
104 if ( attr_node != nullptr ) {
105 auto val = attr_node->GetData();
106 if (val.size() == 1 &&
107 val[0].toStdString() == attr_node->GetAttribute().p_default_value) {
108 return QBrush (
110 }
111 }
112 return QBrush (
114 }
115 }
116
117 return QVariant();
118}
static QColor TableAttributeHighlightBackground
static QColor TableColorAttribute
Including DBE.
static QColor TableAttributeBackground
static QColor TableColorRelationship
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:476
nlohmann::json Data
Definition Structs.hpp:24

◆ dropMimeData()

bool dbe::models::table::dropMimeData ( const QMimeData * data,
Qt::DropAction action,
int row,
int column,
type_index const & parent )
override

Here if parent is valid it indicates that the drop ocurred on an item otherwise it ocurred on a top level item

Definition at line 212 of file table.cpp.

215{
216 Q_UNUSED ( row )
217 Q_UNUSED ( column )
218 Q_UNUSED ( parent )
219
220 bool Accept = true;
221
222 if ( action == Qt::IgnoreAction )
223 {
224 return true;
225 }
226
227 if ( !data->hasFormat ( "application/vnd.text.list" ) )
228 {
229 return false;
230 }
231
233 QByteArray encodedData = data->data ( "application/vnd.text.list" );
234
235 QDataStream stream ( &encodedData, QIODevice::ReadOnly );
236
237 QList<QStringList> newItems;
238
239 while ( !stream.atEnd() )
240 {
241 QStringList text;
242 stream >> text;
243 newItems << text;
244 }
245
246 for ( int i = 0; i < newItems.size(); ++i )
247 {
248 if ( newItems.at ( 0 ).at ( 1 ) != newItems.at ( i ).at ( 1 ) )
249 {
250 Accept = false;
251 }
252 }
253
254 if ( Accept )
255 {
256 BuildTableFromObject ( newItems );
257 emit ResetTab();
258 }
259
260 return Accept;
261}
QVariant data(type_index const &index, int role) const override
Definition table.cpp:47
bool BuildTableFromObject(QList< QStringList > BuildList)
Definition table.cpp:426

◆ flags()

Qt::ItemFlags dbe::models::table::flags ( type_index const & index) const
override

Definition at line 184 of file table.cpp.

185{
186 if(index.isValid()) {
187 dref obj_desc = this_objects[index.row()];
188 tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } );
189
190 if ( confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) )
191 {
192 return ( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable |
193 Qt::ItemIsDropEnabled );
194 }
195 }
196
197 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
198}
static bool check_file_rw(const QString &FileName)
static configobject::tref get(dbe::cokey const &desc)
inner::configobject::tref tref
Definition tref.hpp:30

◆ get_class_name()

QString dbe::models::table::get_class_name ( ) const

Definition at line 461 of file table.cpp.

462{
463 return this_class_name;
464}

◆ getnode()

dbe::TableNode * dbe::models::table::getnode ( const QModelIndex & Index) const

Definition at line 476 of file table.cpp.

477{
478 if ( Index.isValid() )
479 {
480 return this_structure.at ( Index.row() ).at ( Index.column() );
481 }
482
483 return nullptr;
484}

◆ GetTableObject()

dbe::tref dbe::models::table::GetTableObject ( int ObjectIndex) const

Definition at line 451 of file table.cpp.

452{
453 return this_objects.at ( ObjectIndex ).ref();
454}

◆ GetTableObjects()

QList< dbe::dref > * dbe::models::table::GetTableObjects ( )

Definition at line 471 of file table.cpp.

472{
473 return &this_objects;
474}

◆ headerData()

QVariant dbe::models::table::headerData ( int section,
Qt::Orientation orientation,
int role ) const
override

Definition at line 161 of file table.cpp.

163{
164 if ( role == Qt::DisplayRole )
165 {
166 if ( orientation == Qt::Horizontal )
167 {
168 return this_headers.at ( section );
169 }
170 if ( orientation == Qt::Vertical )
171 {
172 return section + 1;
173 }
174 }
175
176 if ( role == Qt::FontRole )
177 {
178 return QFont ( "Helvetica [Cronyx]", 10 );
179 }
180
181 return QVariant();
182}
Missing configuration section
Message.

◆ is_built()

bool dbe::models::table::is_built ( ) const

Definition at line 456 of file table.cpp.

457{
458 return enabled;
459}

◆ mimeTypes()

QStringList dbe::models::table::mimeTypes ( ) const
override

Definition at line 205 of file table.cpp.

206{
207 QStringList types;
208 types << "application/vnd.text.list";
209 return types;
210}

◆ objectsUpdated()

void dbe::models::table::objectsUpdated ( const std::vector< dbe::dref > & objects)

Definition at line 518 of file table.cpp.

518 {
520}
void update_multiple_objects(std::vector< type_object_info > const &)

◆ reset()

void dbe::models::table::reset ( QString const & cname)
private

Clear internal structure and set the name to the given class

Parameters
theclass name to set

Definition at line 387 of file table.cpp.

388{
389
390 for ( auto & List : this_structure )
391 {
392 qDeleteAll ( List );
393 }
394
395 this_objects.clear();
396 this_structure.clear();
397 this_headers.clear();
398 this_class_name = cname;
399}

◆ ResetModel()

void dbe::models::table::ResetModel ( )

Definition at line 486 of file table.cpp.

487{
488 beginResetModel();
489 endResetModel();
490}

◆ ResetTab

void dbe::models::table::ResetTab ( )
signal

◆ rowCount()

int dbe::models::table::rowCount ( type_index const & parent) const
override

Definition at line 28 of file table.cpp.

29{
30 if ( !parent.isValid() )
31 {
32 return this_structure.size();
33 }
34
35 return 0;
36}

◆ setData()

bool dbe::models::table::setData ( type_index const & index,
const QVariant & value,
int role )
override

Definition at line 120 of file table.cpp.

122{
123 if ( !index.isValid() || role != Qt::EditRole )
124 {
125 return false;
126 }
127
128 TableNode * TableItem = getnode ( index );
129
130 QStringList OldDataList = TableItem->GetData();
131
132 QStringList NewDataList = value.toStringList();
133
134 if ( NewDataList == OldDataList )
135 {
136 return false;
137 }
138
139 dref obj_desc = this_objects[index.row()];
140
142 { obj_desc.UID(), obj_desc.class_name() } );
143
144 if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
145 {
146 TableRelationshipNode * RelationshipNode =
147 dynamic_cast<TableRelationshipNode *> ( TableItem );
148 dunedaq::conffwk::relationship_t RelationshipData = RelationshipNode->GetRelationship();
149 dbe::config::api::set::relation ( Object, RelationshipData, NewDataList );
150 }
151 else if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
152 {
153 TableAttributeNode * AttributeNode = dynamic_cast<TableAttributeNode *> ( TableItem );
154 dunedaq::conffwk::attribute_t AttributeData = AttributeNode->GetAttribute();
155 dbe::config::api::set::attribute ( Object, AttributeData, NewDataList );
156 }
157
158 return true;
159}
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, QStringList const &targets)
void attribute(dbe::inner::configobject::tref objectref, dunedaq::conffwk::attribute_t const &attribute_info, QStringList const &attribute_values)

◆ setheader()

void dbe::models::table::setheader ( dunedaq::conffwk::class_t const & cinfo)
private

Set headers as designate by the given class

Parameters
thedunedaq::conffwk::class_t information for the class

Definition at line 401 of file table.cpp.

402{
403 if ( !this_headers.contains ( "Object Name" ) )
404 {
405 this_headers.append ( "Object Name" );
406 }
407
408 for ( auto & i : cinfo.p_attributes )
409 {
410 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
411 {
412 this_headers.append ( QString::fromStdString ( i.p_name ) );
413 }
414 }
415
416 for ( auto & i : cinfo.p_relationships )
417 {
418 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
419 {
420 this_headers.append ( QString::fromStdString ( i.p_name ) );
421 }
422 }
423
424}

◆ slot_create_object

void dbe::models::table::slot_create_object ( QString const & src,
dref const & obj )
privateslot

◆ slot_data_dropped

void dbe::models::table::slot_data_dropped ( QMimeData const & data,
Qt::DropAction action )
slot

Definition at line 492 of file table.cpp.

493{
494 QModelIndex dum;
495 this->dropMimeData ( &data, action, 0, 0, dum );
496}
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
Definition table.cpp:212

◆ slot_remove_object

void dbe::models::table::slot_remove_object ( QString const & src,
dref const & obj )
privateslot

◆ slot_rename_object

void dbe::models::table::slot_rename_object ( QString const & src,
dref const & obj )
privateslot

◆ slot_update_object

void dbe::models::table::slot_update_object ( QString const & src,
dref const & obj )
privateslot

◆ supportedDropActions()

Qt::DropActions dbe::models::table::supportedDropActions ( ) const
override

Definition at line 200 of file table.cpp.

201{
202 return Qt::CopyAction;
203}

Member Data Documentation

◆ class_type_info

dunedaq::conffwk::class_t dbe::models::table::class_type_info
private

Definition at line 72 of file table.hpp.

◆ enabled

bool dbe::models::table::enabled
private

Definition at line 70 of file table.hpp.

◆ this_class_name

QString dbe::models::table::this_class_name
private

Definition at line 71 of file table.hpp.

◆ this_headers

QStringList dbe::models::table::this_headers
private

Definition at line 74 of file table.hpp.

◆ this_objects

QList<dref> dbe::models::table::this_objects
private

Definition at line 75 of file table.hpp.

◆ this_structure

QList<QList<TableNode * > > dbe::models::table::this_structure
private

Definition at line 76 of file table.hpp.


The documentation for this class was generated from the following files: