All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
util::ROOT::TStyleChanger Class Reference

A class restoring the previous TStyle on destruction. More...

#include <ROOTutils.h>

Public Member Functions

 TStyleChanger ()
 
 TStyleChanger (TStyle *newStyle)
 
 ~TStyleChanger ()
 
void save ()
 Stores the current style as the one to be saved. More...
 
void restore () const
 
void forget ()
 Do not restore the old style on destruction. More...
 
void cd () const
 Make the stored new style as current again. More...
 
void cd (TStyle *newStyle)
 Make the specified style as current. More...
 
TStyle * saved () const
 Returns a pointer to the style that will be restored on destruction. More...
 
bool hasSaved () const
 Returns whether there is a style to be restored on destruction. More...
 

Private Attributes

TStyle * pSaved = nullptr
 
TStyle * pNew = nullptr
 

Detailed Description

A class restoring the previous TStyle on destruction.

When an instance of this object is created, the existing current style is saved, and it is then restored on destruction.

Additional methods allow finer control on the restoration feature.

Example:

{
TStyleChanger StyleGuard
(static_cast<TStyle*>(gDirectory->Get("newStyle")));
// everything here happens in the new style
}
// whatever follows happens under the previous style

Definition at line 127 of file ROOTutils.h.

Constructor & Destructor Documentation

util::ROOT::TStyleChanger::TStyleChanger ( )
inline

Definition at line 134 of file ROOTutils.h.

134 { save(); }
void save()
Stores the current style as the one to be saved.
Definition: ROOTutils.h:140
util::ROOT::TStyleChanger::TStyleChanger ( TStyle *  newStyle)
inline

Definition at line 135 of file ROOTutils.h.

135 { save(); cd(newStyle); }
void save()
Stores the current style as the one to be saved.
Definition: ROOTutils.h:140
void cd() const
Make the stored new style as current again.
Definition: ROOTutils.h:150
util::ROOT::TStyleChanger::~TStyleChanger ( )
inline

Definition at line 137 of file ROOTutils.h.

137 { restore(); }
void restore() const
Definition: ROOTutils.h:144

Member Function Documentation

void util::ROOT::TStyleChanger::cd ( ) const
inline

Make the stored new style as current again.

Definition at line 150 of file ROOTutils.h.

150 { if (pNew) pNew->cd(); }
void util::ROOT::TStyleChanger::cd ( TStyle *  newStyle)
inline

Make the specified style as current.

Definition at line 153 of file ROOTutils.h.

153 { pNew = newStyle; cd(); }
void cd() const
Make the stored new style as current again.
Definition: ROOTutils.h:150
void util::ROOT::TStyleChanger::forget ( )
inline

Do not restore the old style on destruction.

Definition at line 147 of file ROOTutils.h.

147 { pSaved = nullptr; }
bool util::ROOT::TStyleChanger::hasSaved ( ) const
inline

Returns whether there is a style to be restored on destruction.

Definition at line 159 of file ROOTutils.h.

159 { return saved() != nullptr; }
TStyle * saved() const
Returns a pointer to the style that will be restored on destruction.
Definition: ROOTutils.h:156
void util::ROOT::TStyleChanger::restore ( ) const
inline

Immediately restores the old style. It will still restored on destruction too.

Definition at line 144 of file ROOTutils.h.

144 { if (pSaved) pSaved->cd(); }
void util::ROOT::TStyleChanger::save ( )
inline

Stores the current style as the one to be saved.

Definition at line 140 of file ROOTutils.h.

140 { pSaved = gStyle; }
TStyle* util::ROOT::TStyleChanger::saved ( ) const
inline

Returns a pointer to the style that will be restored on destruction.

Definition at line 156 of file ROOTutils.h.

156 { return pSaved; }

Member Data Documentation

TStyle* util::ROOT::TStyleChanger::pNew = nullptr
private

Definition at line 130 of file ROOTutils.h.

TStyle* util::ROOT::TStyleChanger::pSaved = nullptr
private

Definition at line 129 of file ROOTutils.h.


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