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 243 of file table.cpp.

244{
245 reset ( cname );
246
248
250 cname.toStdString(),
251 false );
252
253 setheader ( classinfo );
254
255 if ( treenode * NodeClass = dbaccess_guard->getnode ( cname ) )
256 {
257 std::vector<treenode *> classnodes
258 { NodeClass };
259
260 if ( include_derived )
261 {
262
263 for ( std::string const & sbcname : classinfo.p_subclasses )
264 {
265 if ( treenode * sbcnode = dbaccess_guard->getnode ( sbcname ) )
266 {
267 classnodes.push_back ( sbcnode );
268 }
269 }
270 }
271
274
275 for ( treenode * clelement : classnodes )
276 {
278
279 for ( treenode * child : clelement->GetChildren() )
280 {
281 this_structure.append ( createrow ( child ) );
282 }
283 }
284
285 enabled = true;
286 return true;
287 }
288 else
289 {
290 return false;
291 }
292}
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:294
void reset(QString const &)
Definition table.cpp:366
void setheader(dunedaq::conffwk::class_t const &)
Definition table.cpp:380
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 405 of file table.cpp.

406{
407 reset ( BuildList.at ( 0 ).at ( 1 ) );
408
409 treenode * classnode = confaccessor::gethandler()->getnode ( this_class_name );
410
412 this_class_name.toStdString(),
413 false );
414
415 setheader ( classinfo );
416
417 confaccessor::gethandler()->FetchMore ( classnode );
418
419 for ( const QStringList & i : BuildList )
420 {
421 QString name = i.at ( 0 );
422 treenode * node = confaccessor::gethandler()->getnode ( this_class_name, name );
423 this_structure.append ( createrow ( node ) );
424 }
425
426 enabled = false;
427 return true;
428}
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 294 of file table.cpp.

296{
297
298 dref obj = rownode->GetObject();
299
300 this_objects.append ( obj );
301
303 obj.class_name(),
304 false );
305 std::vector<dunedaq::conffwk::attribute_t> const & attributes = cdef.p_attributes;
306 std::vector<dunedaq::conffwk::relationship_t> const & relations = cdef.p_relationships;
307
308 assert ( attributes.size() + relations.size() < 1025 );
309 std::bitset<1024> hindex; // maximum number of columns to display
310
311 {
312 int c = 0;
313
314 for ( dunedaq::conffwk::attribute_t const & a : attributes )
315 {
316 hindex.set ( c++, this_headers.contains ( QString::fromStdString ( a.p_name ) ) );
317 }
318
319 for ( dunedaq::conffwk::relationship_t const & r : relations )
320 {
321 hindex.set ( c++, this_headers.contains ( QString::fromStdString ( r.p_name ) ) );
322 }
323 }
324
325 // Create the row for this object
326 QList<TableNode *> Row;
327 Row.append ( new TableNode ( QStringList ( rownode->GetData ( 0 ).toString() ) ) );
328
329 {
330 // Loop over object values and add them to the row
331 // Values are represent as nodes ( attributes or relations ) and these contain
332 // the structured data associated either with a attribute / multi-attribute or a relation
333 std::size_t c = 0;
334
335 for ( treenode * valuenode : rownode->GetChildren() )
336 {
337 QStringList values;
338 // Every valuenode has its attributes and relations defined as its childs
339
340 if ( hindex[c++] )
341 {
342
343 for ( treenode * nodevalues : valuenode->GetChildren() )
344 {
345 // Here we need to filter such that only values corresponding to the header are kept
346 // Add only the first of values in a list of values
347 values.append ( nodevalues->GetData ( 0 ).toString() );
348 }
349
350 if ( AttributeNode * NodeAttribute = dynamic_cast<AttributeNode *> ( valuenode ) )
351 {
352 Row.append ( new TableAttributeNode ( NodeAttribute->attribute_t(), values ) );
353 }
354 else if ( RelationshipNode * NodeRelationship =
355 dynamic_cast<RelationshipNode *> ( valuenode ) )
356 {
357 Row.append ( new TableRelationshipNode ( NodeRelationship->relation_t(), values ) );
358 }
359 }
360 }
361 }
362
363 return Row;
364}
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

◆ 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::FontRole )
70 {
71 if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
72 return QFont ( "Helvetica", 10, -1,
73 false );
74 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
75 return QFont ( "Courier", 10,
76 QFont::Bold );
77 else
78 {
79 return QFont ( "SansSerif", 10, QFont::Bold );
80 }
81 }
82
83 if ( role == Qt::ForegroundRole )
84 {
85 if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
86 return QBrush (
88 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
89 return QBrush (
91 else
92 {
93 return QVariant();
94 }
95 }
96 }
97
98 return QVariant();
99}
static QColor TableColorAttribute
Including DBE.
static QColor TableColorRelationship
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:455
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 192 of file table.cpp.

195{
196 Q_UNUSED ( row )
197 Q_UNUSED ( column )
198 Q_UNUSED ( parent )
199
200 bool Accept = true;
201
202 if ( action == Qt::IgnoreAction )
203 {
204 return true;
205 }
206
207 if ( !data->hasFormat ( "application/vnd.text.list" ) )
208 {
209 return false;
210 }
211
213 QByteArray encodedData = data->data ( "application/vnd.text.list" );
214
215 QDataStream stream ( &encodedData, QIODevice::ReadOnly );
216
217 QList<QStringList> newItems;
218
219 while ( !stream.atEnd() )
220 {
221 QStringList text;
222 stream >> text;
223 newItems << text;
224 }
225
226 for ( int i = 0; i < newItems.size(); ++i )
227 {
228 if ( newItems.at ( 0 ).at ( 1 ) != newItems.at ( i ).at ( 1 ) )
229 {
230 Accept = false;
231 }
232 }
233
234 if ( Accept )
235 {
236 BuildTableFromObject ( newItems );
237 emit ResetTab();
238 }
239
240 return Accept;
241}
QVariant data(type_index const &index, int role) const override
Definition table.cpp:47
bool BuildTableFromObject(QList< QStringList > BuildList)
Definition table.cpp:405

◆ flags()

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

Definition at line 164 of file table.cpp.

165{
166 if(index.isValid()) {
167 dref obj_desc = this_objects[index.row()];
168 tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } );
169
170 if ( confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) )
171 {
172 return ( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable |
173 Qt::ItemIsDropEnabled );
174 }
175 }
176
177 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
178}
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 440 of file table.cpp.

441{
442 return this_class_name;
443}

◆ getnode()

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

Definition at line 455 of file table.cpp.

456{
457 if ( Index.isValid() )
458 {
459 return this_structure.at ( Index.row() ).at ( Index.column() );
460 }
461
462 return nullptr;
463}

◆ GetTableObject()

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

Definition at line 430 of file table.cpp.

431{
432 return this_objects.at ( ObjectIndex ).ref();
433}

◆ GetTableObjects()

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

Definition at line 450 of file table.cpp.

451{
452 return &this_objects;
453}

◆ headerData()

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

Definition at line 142 of file table.cpp.

144{
145 if ( role == Qt::DisplayRole )
146 {
147 if ( orientation == Qt::Horizontal )
148 {
149 return this_headers.at ( section );
150 }
151 else if ( orientation == Qt::Vertical) {
152 return QString::fromStdString(this_objects.at(section).UID());
153 }
154 }
155
156 if ( role == Qt::FontRole )
157 {
158 return QFont ( "Helvetica [Cronyx]", 10 );
159 }
160
161 return QVariant();
162}

◆ is_built()

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

Definition at line 435 of file table.cpp.

436{
437 return enabled;
438}

◆ mimeTypes()

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

Definition at line 185 of file table.cpp.

186{
187 QStringList types;
188 types << "application/vnd.text.list";
189 return types;
190}

◆ objectsUpdated()

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

Definition at line 497 of file table.cpp.

497 {
499}
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 366 of file table.cpp.

367{
368
369 for ( auto & List : this_structure )
370 {
371 qDeleteAll ( List );
372 }
373
374 this_objects.clear();
375 this_structure.clear();
376 this_headers.clear();
377 this_class_name = cname;
378}

◆ ResetModel()

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

Definition at line 465 of file table.cpp.

466{
467 beginResetModel();
468 endResetModel();
469}

◆ 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 101 of file table.cpp.

103{
104 if ( !index.isValid() || role != Qt::EditRole )
105 {
106 return false;
107 }
108
109 TableNode * TableItem = getnode ( index );
110
111 QStringList OldDataList = TableItem->GetData();
112
113 QStringList NewDataList = value.toStringList();
114
115 if ( NewDataList == OldDataList )
116 {
117 return false;
118 }
119
120 dref obj_desc = this_objects[index.row()];
121
123 { obj_desc.UID(), obj_desc.class_name() } );
124
125 if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
126 {
127 TableRelationshipNode * RelationshipNode =
128 dynamic_cast<TableRelationshipNode *> ( TableItem );
129 dunedaq::conffwk::relationship_t RelationshipData = RelationshipNode->GetRelationship();
130 dbe::config::api::set::relation ( Object, RelationshipData, NewDataList );
131 }
132 else if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
133 {
134 TableAttributeNode * AttributeNode = dynamic_cast<TableAttributeNode *> ( TableItem );
135 dunedaq::conffwk::attribute_t AttributeData = AttributeNode->GetAttribute();
136 dbe::config::api::set::attribute ( Object, AttributeData, NewDataList );
137 }
138
139 return true;
140}
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 380 of file table.cpp.

381{
382 if ( !this_headers.contains ( "Object Name" ) )
383 {
384 this_headers.append ( "Object Name" );
385 }
386
387 for ( auto & i : cinfo.p_attributes )
388 {
389 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
390 {
391 this_headers.append ( QString::fromStdString ( i.p_name ) );
392 }
393 }
394
395 for ( auto & i : cinfo.p_relationships )
396 {
397 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
398 {
399 this_headers.append ( QString::fromStdString ( i.p_name ) );
400 }
401 }
402
403}

◆ 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 471 of file table.cpp.

472{
473 QModelIndex dum;
474 this->dropMimeData ( &data, action, 0, 0, dum );
475}
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
Definition table.cpp:192

◆ 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 180 of file table.cpp.

181{
182 return Qt::CopyAction;
183}

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: