Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RElement.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT7_Browsable_RElement
10#define ROOT7_Browsable_RElement
11
13
14#include <string>
15#include <vector>
16
17namespace ROOT {
18namespace Browsable {
19
20using RElementPath_t = std::vector<std::string>;
21
22class RLevelIter;
23
24class RItem;
25
26/** \class RElement
27\ingroup rbrowser
28\brief Basic element of browsable hierarchy. Provides access to data, creates iterator if any
29\author Sergey Linev <S.Linev@gsi.de>
30\date 2019-10-14
31*/
32
33class RElement {
34public:
35
37 kNone, ///< not recognized
38 kText, ///< "text" - plain text for code editor
39 kImage, ///< "image64" - base64 for supported image formats (png/gif/gpeg)
40 kPng, ///< "png" - plain png binary code, returned inside std::string
41 kJpeg, ///< "jpg" or "jpeg" - plain jpg binary code, returned inside std::string
42 kJson, ///< "json" representation of object, can be used in code editor
43 kFileName ///< "filename" - file name if applicable
44 };
45
46 static EContentKind GetContentKind(const std::string &kind);
47
48 /** Possible actions on double-click */
50 kActNone, ///< do nothing
51 kActBrowse, ///< just browse (expand) item
52 kActEdit, ///< can provide data for text editor
53 kActImage, ///< can be shown in image viewer, can provide image
54 kActDraw6, ///< can be drawn inside ROOT6 canvas
55 kActDraw7, ///< can be drawn inside ROOT7 canvas
56 kActCanvas, ///< indicate that it is canvas and should be drawn directly
57 kActTree, ///< can be shown in tree viewer
58 kActGeom ///< can be shown in geometry viewer
59 };
60
61 virtual ~RElement() = default;
62
63 /** Name of browsable, must be provided in derived classes */
64 virtual std::string GetName() const = 0;
65
66 /** Checks if element name match to provided value */
67 virtual bool MatchName(const std::string &name) const { return name == GetName(); }
68
69 /** Title of browsable (optional) */
70 virtual std::string GetTitle() const { return ""; }
71
72 /** Create iterator for childs elements if any */
73 virtual std::unique_ptr<RLevelIter> GetChildsIter();
74
75 /** Returns element content, depends from kind. Can be "text" or "image64" or "json" */
76 virtual std::string GetContent(const std::string & = "text");
77
78 /** Access object */
79 virtual std::unique_ptr<RHolder> GetObject() { return nullptr; }
80
81 /** Check if element contains provided pointer */
82 virtual bool IsObject(void *) { return false; }
83
84 /** Check if element can have childs */
85 virtual bool IsFolder() const { return false; }
86
87 virtual int GetNumChilds();
88
89 /** Check if element still contains valid content */
90 virtual bool CheckValid() { return true; }
91
92 /** Get default action */
93 virtual EActionKind GetDefaultAction() const { return kActNone; }
94
95 /** Check if want to perform action */
96 virtual bool IsCapable(EActionKind action) const { return action == GetDefaultAction(); }
97
98 /** Should item representing element be expand by default */
99 virtual bool IsExpandByDefault() const { return false; }
100
101 /** Select element as active */
102 virtual bool cd() { return false; }
103
104 virtual std::unique_ptr<RItem> CreateItem() const;
105
106 static std::shared_ptr<RElement> GetSubElement(std::shared_ptr<RElement> &elem, const RElementPath_t &path);
107
108 static RElementPath_t ParsePath(const std::string &str);
109
110 static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2);
111
112 static std::string GetPathAsString(const RElementPath_t &path);
113
114 static int ExtractItemIndex(std::string &name);
115
116 static bool IsLastKeyCycle();
117
118 static void SetLastKeyCycle(bool on = true);
119};
120
121} // namespace Browsable
122} // namespace ROOT
123
124#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition TGX11.cxx:148
Basic element of browsable hierarchy.
Definition RElement.hxx:33
virtual bool IsExpandByDefault() const
Should item representing element be expand by default.
Definition RElement.hxx:99
virtual std::string GetName() const =0
Name of browsable, must be provided in derived classes.
static bool IsLastKeyCycle()
Is only last cycle from the list of keys is shown.
Definition RElement.cxx:195
static EContentKind GetContentKind(const std::string &kind)
Find item with specified name Default implementation, should work for all.
Definition RElement.cxx:54
virtual bool IsFolder() const
Check if element can have childs.
Definition RElement.hxx:85
virtual bool MatchName(const std::string &name) const
Checks if element name match to provided value.
Definition RElement.hxx:67
static void SetLastKeyCycle(bool on=true)
Set flag to show only last cycle from the list of keys.
Definition RElement.cxx:203
virtual bool cd()
Select element as active.
Definition RElement.hxx:102
virtual std::string GetContent(const std::string &="text")
Returns element content, depends from kind.
Definition RElement.cxx:92
@ kFileName
"filename" - file name if applicable
Definition RElement.hxx:43
@ kNone
not recognized
Definition RElement.hxx:37
@ kJpeg
"jpg" or "jpeg" - plain jpg binary code, returned inside std::string
Definition RElement.hxx:41
@ kPng
"png" - plain png binary code, returned inside std::string
Definition RElement.hxx:40
@ kJson
"json" representation of object, can be used in code editor
Definition RElement.hxx:42
@ kText
"text" - plain text for code editor
Definition RElement.hxx:38
@ kImage
"image64" - base64 for supported image formats (png/gif/gpeg)
Definition RElement.hxx:39
virtual std::unique_ptr< RHolder > GetObject()
Access object.
Definition RElement.hxx:79
virtual std::unique_ptr< RLevelIter > GetChildsIter()
Create iterator for childs elements if any.
Definition RElement.cxx:32
virtual EActionKind GetDefaultAction() const
Get default action.
Definition RElement.hxx:93
virtual int GetNumChilds()
Returns number of childs By default creates iterator and iterates over all items.
Definition RElement.cxx:41
virtual ~RElement()=default
static int ExtractItemIndex(std::string &name)
Extract index from name Index coded by client with ###<indx>$$$ suffix Such coding used by browser to...
Definition RElement.cxx:180
EActionKind
Possible actions on double-click.
Definition RElement.hxx:49
@ kActImage
can be shown in image viewer, can provide image
Definition RElement.hxx:53
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:54
@ kActCanvas
indicate that it is canvas and should be drawn directly
Definition RElement.hxx:56
@ kActTree
can be shown in tree viewer
Definition RElement.hxx:57
@ kActGeom
can be shown in geometry viewer
Definition RElement.hxx:58
@ kActBrowse
just browse (expand) item
Definition RElement.hxx:51
@ kActEdit
can provide data for text editor
Definition RElement.hxx:52
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:55
virtual bool IsObject(void *)
Check if element contains provided pointer.
Definition RElement.hxx:82
virtual std::string GetTitle() const
Title of browsable (optional)
Definition RElement.hxx:70
static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2)
Compare two paths, Returns number of elements matches in both paths.
Definition RElement.cxx:147
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
Definition RElement.cxx:162
static std::shared_ptr< RElement > GetSubElement(std::shared_ptr< RElement > &elem, const RElementPath_t &path)
Returns sub element.
Definition RElement.cxx:71
virtual std::unique_ptr< RItem > CreateItem() const
Returns item with element description.
Definition RElement.cxx:107
static RElementPath_t ParsePath(const std::string &str)
Parse string path to produce RElementPath_t One should avoid to use string pathes as much as possible...
Definition RElement.cxx:118
virtual bool IsCapable(EActionKind action) const
Check if want to perform action.
Definition RElement.hxx:96
virtual bool CheckValid()
Check if element still contains valid content.
Definition RElement.hxx:90
Representation of single item in the browser.
Definition RItem.hxx:23
Iterator over single level hierarchy like any array, keys list, ...
std::vector< std::string > RElementPath_t
Definition RElement.hxx:20