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

Member Typedef Documentation

◆ type_datum

Constructor & Destructor Documentation

◆ ~tree()

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

Definition at line 29 of file tree.cpp.

30{}

◆ tree()

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

Definition at line 13 of file tree.cpp.

14 : QAbstractItemModel ( parent ),
16{
17 confaccessor::gethandler()->root = new dbe::treenode ( Headers );
18
19 for ( std::string const & aclass : dbe::config::api::info::onclass::allnames <
20 std::vector<std::string >> () )
21 {
22 new ClassNode ( dbe::config::api::info::onclass::definition ( aclass, false ),
24 }
25
27}
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
bool abstract_classes_selectable
Definition tree.hpp:86
type_index parent(const type_index &child) const override
Definition tree.cpp:48

Member Function Documentation

◆ canFetchMore()

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

Definition at line 204 of file tree.cpp.

205{
206 if ( parent.isValid() )
207 {
208 treenode * ParentNode = getnode ( parent );
209 return ( !ParentNode->GetWasFetched() );
210 }
211
212 return false;
213}
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:316

◆ columnCount()

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

Definition at line 79 of file tree.cpp.

80{
81 if ( parent.isValid() )
82 {
83 dbe::treenode * DataNode = getnode ( parent );
84
85 return DataNode->ColumnCount();
86 }
87 else
88 {
89 return confaccessor::gethandler()->root->ColumnCount();
90 }
91}
int ColumnCount() const
Definition treenode.cpp:121

◆ data()

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

Definition at line 116 of file tree.cpp.

117{
118 if ( index.isValid() )
119 {
120 switch ( role )
121 {
122 case Qt::ForegroundRole:
123 if ( ObjectNode * onode = dynamic_cast<ObjectNode *> ( getnode ( index ) ) )
124 {
125 try
126 {
127 tref const & obj = onode->GetObject();
128
129 if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) )
130 {
131 return QVariant ( QColor ( Qt::blue ) );
132 }
133 else
134 {
135 return QVariant ( QColor ( Qt::darkGray ) );
136 }
137 }
138 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
139 {
140 // nothing to do the onode refers to a removed object and has not yet been removed
141 return QVariant();
142 }
143 }
144
145 break;
146
147 case Qt::ToolTipRole:
148 if ( auto cnode = dynamic_cast<ClassNode *> ( getnode ( index ) ) )
149 {
150 return cnode->GetData ( index.column(), role );
151 }
152 break;
153
154 case Qt::DisplayRole:
155 case Qt::DecorationRole:
156 return getnode ( index )->GetData ( index.column(), role );
157 }
158 }
159
160 return QVariant();
161}
static bool check_file_rw(const QString &FileName)
type_index index(int row, int column, const type_index &parent) const override
Definition tree.cpp:32
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:59
inner::configobject::tref tref
Definition tref.hpp:30

◆ fetchMore()

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

Definition at line 215 of file tree.cpp.

216{
217 if ( parent.isValid() )
218 {
219 treenode * ParentNode = getnode ( parent );
220
221 if ( !ParentNode->GetWasFetched() )
222 {
223 insertRows ( 0, 0, parent );
224 ParentNode->SetWasFetched ( true );
225 }
226 }
227}
bool insertRows(int position, int rows, const type_index &parent) override
Definition tree.cpp:174

◆ flags()

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

Definition at line 93 of file tree.cpp.

94{
95 treenode * node = getnode ( index );
96
97 if ( ClassNode * classnode = dynamic_cast<ClassNode *> ( node ) )
98 {
99 dunedaq::conffwk::class_t classinfo = classnode->GetClassInfo();
100
101 if ( classinfo.p_abstract )
102 {
103 return
105 ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) : ( Qt::ItemIsSelectable );
106 }
107 else
108 {
109 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
110 }
111 }
112
113 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
114}

◆ getindex()

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

Definition at line 286 of file tree.cpp.

288{
289 for ( int i = 0; i < rowCount ( RootIndex ); ++i )
290 {
291 QModelIndex ChildIndex = index ( i, 0, RootIndex );
292 treenode * ChildNode = getnode ( ChildIndex );
293
294 if ( NodeItem == ChildNode )
295 {
296 return ChildIndex;
297 }
298
299 QModelIndex ChildChildIndex = getindex ( NodeItem, ChildIndex );
300
301 if ( ChildChildIndex.isValid() )
302 {
303 return ChildChildIndex;
304 }
305 }
306
307 return QModelIndex();
308}
type_index getindex(treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
Definition tree.cpp:286
int rowCount(const type_index &parent) const override
Definition tree.cpp:63

◆ getnode()

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

Definition at line 316 of file tree.cpp.

318{
319 if ( index.isValid() )
320 {
321 return static_cast<treenode *> ( index.internalPointer() );
322 }
323
324 return confaccessor::gethandler()->root;
325}

◆ hasChildren()

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

Definition at line 229 of file tree.cpp.

230{
231 if ( parent.isValid() )
232 {
233 treenode * ParentNode = getnode ( parent );
234 return ( ParentNode->GetHasStructure() );
235 }
236
237 return true;
238}

◆ headerData()

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

Definition at line 163 of file tree.cpp.

165{
166 if ( ( orientation == Qt::Horizontal ) && ( role == Qt::DisplayRole ) )
167 {
168 return confaccessor::gethandler()->root->GetData ( section );
169 }
170
171 return QVariant();
172}

◆ index()

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

Definition at line 32 of file tree.cpp.

34{
35 // This is standard qt implementation for a tree mode;
36 dbe::treenode * up{parent.isValid() ? getnode ( parent ) : confaccessor::gethandler()->root};
37
38 if ( dbe::treenode * down = up->GetChild ( row ) )
39 {
40 return createIndex ( row, column, down );
41 }
42 else
43 {
44 return QModelIndex();
45 }
46}
treenode * GetChild(const int Row) const
Definition treenode.cpp:101

◆ insertRows()

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

Definition at line 174 of file tree.cpp.

175{
176 if ( ClassNode * onode = dynamic_cast<ClassNode *> ( getnode ( parent ) ) )
177 {
178 rows = onode->ChildCount();
179
180 beginInsertRows ( parent, position, position + rows - 1 );
181
182 std::string const & classname = onode->GetData (
183 static_cast<int> ( tablepositions::classname ) ).toString().toStdString();
184
185 std::vector<tref> const & objects = config::api::info::onclass::objects ( classname,
186 false );
187
188 for ( auto const & i : objects )
189 {
190 new ObjectNode ( i, false, onode );
191 emit ObjectFile(QString::fromStdString(i.contained_in()));
192 }
193
194 endInsertRows();
195
196 return true;
197 }
198 else
199 {
200 return false;
201 }
202}
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 43 of file tree.hpp.

44 {
45 return i;
46 }

◆ mimeData()

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

Definition at line 257 of file tree.cpp.

258{
259 QMimeData * mimeData = new QMimeData();
260 QByteArray encodedData;
261
262 QDataStream stream ( &encodedData, QIODevice::WriteOnly );
263
264 foreach ( QModelIndex index, indexes )
265 {
266 if ( index.isValid() && index.column() == 0 )
267 {
268 QStringList Text;
269 treenode * NodeObject = getnode ( index );
270
271 tref Object = NodeObject->GetObject();
272 QString ObjectUid = QString::fromStdString ( Object.UID() );
273 QString ObjectClassName = QString::fromStdString ( Object.class_name() );
274
275 Text.append ( ObjectUid );
276 Text.append ( ObjectClassName );
277
278 stream << Text;
279 }
280 }
281
282 mimeData->setData ( "application/vnd.text.list", encodedData );
283 return mimeData;
284}
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition tree.cpp:257

◆ mimeTypes()

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

Definition at line 250 of file tree.cpp.

251{
252 QStringList types;
253 types << "application/vnd.text.list";
254 return types;
255}

◆ ObjectFile

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

◆ objectsUpdated()

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

Definition at line 386 of file tree.cpp.

386 {
388}
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 48 of file tree.cpp.

49{
50 if ( child.isValid() )
51 {
52 dbe::treenode * up = getnode ( child )->GetParent();
53
54 if ( up != confaccessor::gethandler()->root )
55 {
56 return createIndex ( up->GetRow(), 0, up );
57 }
58 }
59
60 return QModelIndex();
61}
treenode * GetParent() const
Definition treenode.cpp:111
int GetRow() const
Definition treenode.cpp:81

◆ ResetModel()

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

Definition at line 310 of file tree.cpp.

311{
312 beginResetModel();
313 endResetModel();
314}

◆ rowCount()

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

Definition at line 63 of file tree.cpp.

64{
65 dbe::treenode * ParentNode;
66
67 if ( !parent.isValid() )
68 {
69 ParentNode = confaccessor::gethandler()->getnode();
70 }
71 else
72 {
73 ParentNode = getnode ( parent );
74 }
75
76 return ParentNode->ChildCount();
77}
int ChildCount() const
Definition treenode.cpp:116

◆ setData()

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

Definition at line 240 of file tree.cpp.

242{
243 Q_UNUSED ( index )
244 Q_UNUSED ( value )
245 Q_UNUSED ( role )
246
247 return true;
248}

◆ 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 380 of file tree.cpp.

381{
383 ResetModel();
384}
void ResetModel()
Definition tree.cpp:310

Member Data Documentation

◆ abstract_classes_selectable

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

Definition at line 86 of file tree.hpp.


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