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

#include <tree.hpp>

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

Public Types

typedef dbe::treenode type_datum

Signals

void ObjectFile (QString)

Public Member Functions

 ~tree ()
 tree (const QStringList &Headers, QObject *parent=nullptr)
type_index index (int row, int column, const type_index &parent) const override
type_index parent (const type_index &child) const override
type_index mapToSource (type_index const &i)
int rowCount (const type_index &parent) const override
int columnCount (const type_index &parent) const override
Qt::ItemFlags flags (const type_index &index) const override
QVariant data (const type_index &index, int role=Qt::DisplayRole) const override
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
bool insertRows (int position, int rows, const type_index &parent) override
void fetchMore (const type_index &parent) override
bool canFetchMore (const type_index &parent) const override
bool hasChildren (const type_index &parent) const override
bool setData (const type_index &index, const QVariant &value, int role) override
QStringList mimeTypes () const override
QMimeData * mimeData (const QModelIndexList &indexes) const override
type_datumgetnode (const type_index &index) const override
type_index getindex (treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
void ResetModel ()
void objectsUpdated (const std::vector< dbe::dref > &objects)
Public Member Functions inherited from dbe::TreeModelInterface
virtual treenodegetnode (const QModelIndex &index) const =0
virtual ~TreeModelInterface ()=default
Public Member Functions inherited from dbe::model_common_impl< tree >
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< tree >
MODEL_COMMON_TYPES_TOPLEVEL_DEFINITIONS model_common_async_operations ()
void model_common_connections ()

Private Slots

void ToggleAbstractClassesSelectable (bool)
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 Attributes

bool abstract_classes_selectable

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< tree >
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 26 of file tree.hpp.

Member Typedef Documentation

◆ type_datum

Definition at line 37 of file tree.hpp.

Constructor & Destructor Documentation

◆ ~tree()

dbe::models::tree::~tree ( )

Definition at line 35 of file tree.cpp.

36{}

◆ tree()

dbe::models::tree::tree ( const QStringList & Headers,
QObject * parent = nullptr )
explicit

Definition at line 19 of file tree.cpp.

20 : QAbstractItemModel ( parent ),
22{
23 confaccessor::gethandler()->root = new dbe::treenode ( Headers );
24
25 for ( std::string const & aclass : dbe::config::api::info::onclass::allnames <
26 std::vector<std::string >> () )
27 {
28 new ClassNode ( dbe::config::api::info::onclass::definition ( aclass, false ),
30 }
31
33}
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
bool abstract_classes_selectable
Definition tree.hpp:91
type_index parent(const type_index &child) const override
Definition tree.cpp:54

Member Function Documentation

◆ canFetchMore()

bool dbe::models::tree::canFetchMore ( const type_index & parent) const
override

Definition at line 235 of file tree.cpp.

236{
237 if ( parent.isValid() )
238 {
239 treenode * ParentNode = getnode ( parent );
240 return ( !ParentNode->GetWasFetched() );
241 }
242
243 return false;
244}
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:347

◆ columnCount()

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

Definition at line 85 of file tree.cpp.

86{
87 if ( parent.isValid() )
88 {
89 dbe::treenode * DataNode = getnode ( parent );
90
91 return DataNode->ColumnCount();
92 }
93 else
94 {
95 return confaccessor::gethandler()->root->ColumnCount();
96 }
97}
int ColumnCount() const
Definition treenode.cpp:126

◆ data()

QVariant dbe::models::tree::data ( const type_index & index,
int role = Qt::DisplayRole ) const
override

Definition at line 122 of file tree.cpp.

123{
124 if ( index.isValid() )
125 {
126 switch ( role )
127 {
128 case Qt::ForegroundRole:
129 if ( ObjectNode * onode = dynamic_cast<ObjectNode *> ( getnode ( index ) ) )
130 {
131 try
132 {
133 tref const & obj = onode->GetObject();
134
135 if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) )
136 {
137 return QVariant ( StyleUtility::ObjectForeground );
138 }
139 else
140 {
141 return QVariant ( StyleUtility::FileReadOnlyForeground );
142 }
143 }
144 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
145 {
146 // nothing to do the onode refers to a removed object and has not yet been removed
147 return QVariant();
148 }
149 }
150
151 break;
152
153 case Qt::BackgroundRole:
154 if ( ObjectNode * onode = dynamic_cast<ObjectNode *> ( getnode ( index ) ) )
155 {
156 try
157 {
158 tref const & obj = onode->GetObject();
159
160 if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) )
161 {
162 return QVariant ( StyleUtility::ObjectBackground );
163 }
164 else
165 {
166 return QVariant ( StyleUtility::FileReadOnlyBackground );
167 }
168 }
169 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
170 {
171 // nothing to do the onode refers to a removed object and has not yet been removed
172 return QVariant();
173 }
174 }
175
176 break;
177
178 case Qt::ToolTipRole:
179 if ( auto cnode = dynamic_cast<ClassNode *> ( getnode ( index ) ) )
180 {
181 return cnode->GetData ( index.column(), role );
182 }
183 break;
184
185 case Qt::DisplayRole:
186 case Qt::DecorationRole:
187 return getnode ( index )->GetData ( index.column(), role );
188 }
189 }
190
191 return QVariant();
192}
static QColor ObjectForeground
static QColor FileReadOnlyForeground
static QColor ObjectBackground
static QColor FileReadOnlyBackground
static bool check_file_rw(const QString &FileName)
type_index index(int row, int column, const type_index &parent) const override
Definition tree.cpp:38
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:64
inner::configobject::tref tref
Definition tref.hpp:35

◆ fetchMore()

void dbe::models::tree::fetchMore ( const type_index & parent)
override

Definition at line 246 of file tree.cpp.

247{
248 if ( parent.isValid() )
249 {
250 treenode * ParentNode = getnode ( parent );
251
252 if ( !ParentNode->GetWasFetched() )
253 {
254 insertRows ( 0, 0, parent );
255 ParentNode->SetWasFetched ( true );
256 }
257 }
258}
bool insertRows(int position, int rows, const type_index &parent) override
Definition tree.cpp:205

◆ flags()

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

Definition at line 99 of file tree.cpp.

100{
101 treenode * node = getnode ( index );
102
103 if ( ClassNode * classnode = dynamic_cast<ClassNode *> ( node ) )
104 {
105 dunedaq::conffwk::class_t classinfo = classnode->GetClassInfo();
106
107 if ( classinfo.p_abstract )
108 {
109 return
111 ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) : ( Qt::ItemIsSelectable );
112 }
113 else
114 {
115 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
116 }
117 }
118
119 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
120}

◆ getindex()

QModelIndex dbe::models::tree::getindex ( treenode * NodeItem,
type_index const & RootIndex = QModelIndex() ) const

Definition at line 317 of file tree.cpp.

319{
320 for ( int i = 0; i < rowCount ( RootIndex ); ++i )
321 {
322 QModelIndex ChildIndex = index ( i, 0, RootIndex );
323 treenode * ChildNode = getnode ( ChildIndex );
324
325 if ( NodeItem == ChildNode )
326 {
327 return ChildIndex;
328 }
329
330 QModelIndex ChildChildIndex = getindex ( NodeItem, ChildIndex );
331
332 if ( ChildChildIndex.isValid() )
333 {
334 return ChildChildIndex;
335 }
336 }
337
338 return QModelIndex();
339}
type_index getindex(treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
Definition tree.cpp:317
int rowCount(const type_index &parent) const override
Definition tree.cpp:69

◆ getnode()

dbe::models::tree::type_datum * dbe::models::tree::getnode ( const type_index & index) const
override

Definition at line 347 of file tree.cpp.

349{
350 if ( index.isValid() )
351 {
352 return static_cast<treenode *> ( index.internalPointer() );
353 }
354
355 return confaccessor::gethandler()->root;
356}

◆ hasChildren()

bool dbe::models::tree::hasChildren ( const type_index & parent) const
override

Definition at line 260 of file tree.cpp.

261{
262 if ( parent.isValid() )
263 {
264 treenode * ParentNode = getnode ( parent );
265 return ( ParentNode->GetHasStructure() );
266 }
267
268 return true;
269}

◆ headerData()

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

Definition at line 194 of file tree.cpp.

196{
197 if ( ( orientation == Qt::Horizontal ) && ( role == Qt::DisplayRole ) )
198 {
199 return confaccessor::gethandler()->root->GetData ( section );
200 }
201
202 return QVariant();
203}

◆ index()

dbe::models::tree::type_index dbe::models::tree::index ( int row,
int column,
const type_index & parent ) const
override

Definition at line 38 of file tree.cpp.

40{
41 // This is standard qt implementation for a tree mode;
42 dbe::treenode * up{parent.isValid() ? getnode ( parent ) : confaccessor::gethandler()->root};
43
44 if ( dbe::treenode * down = up->GetChild ( row ) )
45 {
46 return createIndex ( row, column, down );
47 }
48 else
49 {
50 return QModelIndex();
51 }
52}
treenode * GetChild(const int Row) const
Definition treenode.cpp:106

◆ insertRows()

bool dbe::models::tree::insertRows ( int position,
int rows,
const type_index & parent )
override

Definition at line 205 of file tree.cpp.

206{
207 if ( ClassNode * onode = dynamic_cast<ClassNode *> ( getnode ( parent ) ) )
208 {
209 rows = onode->ChildCount();
210
211 beginInsertRows ( parent, position, position + rows - 1 );
212
213 std::string const & classname = onode->GetData (
214 static_cast<int> ( tablepositions::classname ) ).toString().toStdString();
215
216 std::vector<tref> const & objects = config::api::info::onclass::objects ( classname,
217 false );
218
219 for ( auto const & i : objects )
220 {
221 new ObjectNode ( i, false, onode );
222 emit ObjectFile(QString::fromStdString(i.contained_in()));
223 }
224
225 endInsertRows();
226
227 return true;
228 }
229 else
230 {
231 return false;
232 }
233}
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
void ObjectFile(QString)

◆ mapToSource()

type_index dbe::models::tree::mapToSource ( type_index const & i)
inline

Definition at line 48 of file tree.hpp.

49 {
50 return i;
51 }

◆ mimeData()

QMimeData * dbe::models::tree::mimeData ( const QModelIndexList & indexes) const
override

Definition at line 288 of file tree.cpp.

289{
290 QMimeData * mimeData = new QMimeData();
291 QByteArray encodedData;
292
293 QDataStream stream ( &encodedData, QIODevice::WriteOnly );
294
295 foreach ( QModelIndex index, indexes )
296 {
297 if ( index.isValid() && index.column() == 0 )
298 {
299 QStringList Text;
300 treenode * NodeObject = getnode ( index );
301
302 tref Object = NodeObject->GetObject();
303 QString ObjectUid = QString::fromStdString ( Object.UID() );
304 QString ObjectClassName = QString::fromStdString ( Object.class_name() );
305
306 Text.append ( ObjectUid );
307 Text.append ( ObjectClassName );
308
309 stream << Text;
310 }
311 }
312
313 mimeData->setData ( "application/vnd.text.list", encodedData );
314 return mimeData;
315}
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition tree.cpp:288

◆ mimeTypes()

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

Definition at line 281 of file tree.cpp.

282{
283 QStringList types;
284 types << "application/vnd.text.list";
285 return types;
286}

◆ ObjectFile

void dbe::models::tree::ObjectFile ( QString )
signal

◆ objectsUpdated()

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

Definition at line 417 of file tree.cpp.

417 {
419}
void update_multiple_objects(std::vector< type_object_info > const &)

◆ parent()

dbe::models::tree::type_index dbe::models::tree::parent ( const type_index & child) const
override

Definition at line 54 of file tree.cpp.

55{
56 if ( child.isValid() )
57 {
58 dbe::treenode * up = getnode ( child )->GetParent();
59
60 if ( up != confaccessor::gethandler()->root )
61 {
62 return createIndex ( up->GetRow(), 0, up );
63 }
64 }
65
66 return QModelIndex();
67}
treenode * GetParent() const
Definition treenode.cpp:116
int GetRow() const
Definition treenode.cpp:86

◆ ResetModel()

void dbe::models::tree::ResetModel ( )

Definition at line 341 of file tree.cpp.

342{
343 beginResetModel();
344 endResetModel();
345}

◆ rowCount()

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

Definition at line 69 of file tree.cpp.

70{
71 dbe::treenode * ParentNode;
72
73 if ( !parent.isValid() )
74 {
75 ParentNode = confaccessor::gethandler()->getnode();
76 }
77 else
78 {
79 ParentNode = getnode ( parent );
80 }
81
82 return ParentNode->ChildCount();
83}
int ChildCount() const
Definition treenode.cpp:121

◆ setData()

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

Definition at line 271 of file tree.cpp.

273{
274 Q_UNUSED ( index )
275 Q_UNUSED ( value )
276 Q_UNUSED ( role )
277
278 return true;
279}

◆ slot_create_object

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

◆ slot_remove_object

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

◆ slot_rename_object

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

◆ slot_update_object

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

◆ ToggleAbstractClassesSelectable

void dbe::models::tree::ToggleAbstractClassesSelectable ( bool val)
privateslot

Definition at line 411 of file tree.cpp.

412{
414 ResetModel();
415}
void ResetModel()
Definition tree.cpp:341

Member Data Documentation

◆ abstract_classes_selectable

bool dbe::models::tree::abstract_classes_selectable
private

Definition at line 91 of file tree.hpp.


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