#include <Legend.h>
Public Member Functions | |
void | clear () |
void | colorHSVInterpole (int imin, int imax) |
void | colorRGBInterpole (int imin, int imax) |
int | count () const |
void | defaultBW (int n=10) |
void | defaultColors (int n=10) |
int | indexOf (const QString &text) const |
const LegendItem & | item (int i) |
Legend () | |
Legend (const Legend &o) | |
Legend (int n) | |
bool | operator!= (const Legend &o) const |
Legend & | operator= (const Legend &o) |
bool | operator== (const Legend &o) const |
const Pen & | pen (int i) const |
const Pen & | pen (const QString &text) const |
void | penColorToSymbolBrush () |
void | penColorToSymbolPen () |
void | penColorToText () |
void | resize (int n) |
void | setPen (int i, Pen p) |
void | setPens (const Legend &o) |
void | setSymbol (int i, Symbol s) |
void | setSymbols (const Legend &o) |
void | setText (int i, QString t) |
void | setTextColor (int i, QColor c) |
void | setTextColors (const Legend &o) |
void | setTexts (const QStringList &texts, const Pen &defaultPen, const Symbol &defaultSymbol) |
void | setTexts (const Legend &o) |
const Symbol & | symbol (int i) const |
const Symbol & | symbol (const QString &text) const |
const QString & | text (int i) const |
const QColor & | textColor (int i) const |
QStringList | texts () const |
virtual const QString & | xml_tagName () const |
virtual | ~Legend () |
Static Public Attributes | |
static const QString | xmlLegendTag = "Legend" |
Protected Member Functions | |
virtual XMLMember | xml_member (XML_MEMBER_ARGS) |
virtual void | xml_writeChildren (XML_WRITECHILDREN_ARGS) const |
SciFigs::Legend::Legend | ( | ) | [inline] |
{_textLookup=0;}
SciFigs::Legend::Legend | ( | const Legend & | o | ) | [inline] |
SciFigs::Legend::Legend | ( | int | n | ) | [inline] |
{_textLookup=0; resize(n);}
SciFigs::Legend::~Legend | ( | ) | [virtual] |
void SciFigs::Legend::clear | ( | ) |
void SciFigs::Legend::colorHSVInterpole | ( | int | imin, |
int | imax | ||
) |
References TRACE.
{ TRACE; double h, h2, dh, s, s2, ds, v, v2, dv, a, a2, da; int n=_items.count(); if(n <= 2) return ; if(imin < 0) imin=0; if(imax > n - 1) imax=n - 1; const QColor& c1=_items[ imin ].pen().color(); h=c1.hue(); s=c1.saturation(); v=c1.value(); a=c1.alpha(); const QColor& c2=_items[ imax ].pen().color(); h2=c2.hue(); s2=c2.saturation(); v2=c2.value(); a2=c2.alpha(); dh=(h2 - h)/(double) (imax - imin + 1); ds=(s2 - s)/(double) (imax - imin + 1); dv=(v2 - v)/(double) (imax - imin + 1); da=(a2 - a)/(double) (imax - imin + 1); QColor c; for(int i=imin + 1; i < imax; i++ ) { h += dh; s += ds; v += dv; a += da; c.setHsv(( int) h, (int) s, (int) v, (int) a); _items[ i ].pen().setColor(c); } }
void SciFigs::Legend::colorRGBInterpole | ( | int | imin, |
int | imax | ||
) |
References TRACE.
{ TRACE; double r, r2, dr, g, g2, dg, b, b2, db, a, a2, da; int n=_items.count(); if(n <= 2) return ; const QColor& c1=_items[ imin ].pen().color(); r=c1.red(); g=c1.green(); b=c1.blue(); a=c1.alpha(); const QColor& c2=_items[ imax ].pen().color(); r2=c2.red(); g2=c2.green(); b2=c2.blue(); a2=c2.alpha(); dr=(r2 - r)/(double) (imax - imin + 1); dg=(g2 - g)/(double) (imax - imin + 1); db=(b2 - b)/(double) (imax - imin + 1); da=(a2 - a)/(double) (imax - imin + 1); QColor c; for(int i=imin + 1; i < imax; i++ ) { r += dr; g += dg; b += db; a += da; c.setRgb(( int) r, (int) g, (int) b, (int) a); _items[ i ].pen().setColor(c); } }
int SciFigs::Legend::count | ( | ) | const [inline] |
Referenced by SciFigs::LegendWidget::paint(), SciFigs::LegendTableItem::rowCount(), SciFigs::PaletteInterpole::setColors(), SciFigs::LegendProperties::setLegend(), setPens(), setSymbols(), setTextColors(), setTexts(), ProcessStatus::synchronize(), and ProcessStatus::updateMisfitCurve().
{return _items.size();}
void SciFigs::Legend::defaultBW | ( | int | n = 10 | ) |
void SciFigs::Legend::defaultColors | ( | int | n = 10 | ) |
References resize(), and TRACE.
Referenced by ProcessStatus::ProcessStatus().
{ TRACE; resize(n); int i; switch (n) { case 1: _items[ 0 ].pen().setColor(QColor( 0, 0, 255) ); break; case 2: _items[ 0 ].pen().setColor(QColor( 0, 0, 255) ); _items[ 1 ].pen().setColor(QColor( 255, 0, 0) ); break; case 3: _items[ 0 ].pen().setColor(QColor( 0, 0, 255) ); _items[ 1 ].pen().setColor(QColor( 0, 255, 0) ); _items[ 2 ].pen().setColor(QColor( 255, 0, 0) ); break; default: double truc, r, g, b; int n1=n/3; int n2=n1 + (n - n1)/2; for(i=0; i < n1; i++ ) { truc=(double) i/(double) n1; r=0.; g=pow(truc, 0.3); b=1. - truc * truc; _items[ i ].pen().setColor(QColor( (int) (r * 255), (int) (g * 255), (int) (b * 255) )); } for(i=n1; i < n2; i++ ) { truc=(double) (i - n1)/(double) (n2 - n1); r=pow(truc, 0.3); g=1.; b=0.; _items[ i ].pen().setColor(QColor( (int) (r * 255), (int) (g * 255), (int) (b * 255) )); } for(i=n2; i < n; i++ ) { truc=(double) (i - n2)/(double) (n - n2 - 1); r=1.; g=1. - truc * truc; b=0.; _items[ i ].pen().setColor(QColor( (int) (r * 255), (int) (g * 255), (int) (b * 255) )); } break; } }
int SciFigs::Legend::indexOf | ( | const QString & | text | ) | const |
Returns the index of item with text. This is a fast lookup with a map. The lookup map is initialized at first call. Once called, the lookup map is maintained by other operations. If there are various items with the same name, the returned index may be random (depends upon lookup initialization and maintenance).
Referenced by pen(), MonoStation::AbstractSummary::setBubbleValues(), setTexts(), and symbol().
const LegendItem & SciFigs::Legend::item | ( | int | i | ) |
References TRACE.
Referenced by ProcessStatusDelegate::paint(), and ProcessStatusDelegate::sizeHint().
{ TRACE; if(i >= _items.count()) i=_items.count() - 1; return _items.at(i); }
bool SciFigs::Legend::operator!= | ( | const Legend & | o | ) | const [inline] |
{return !operator==(o);}
bool SciFigs::Legend::operator== | ( | const Legend & | o | ) | const |
const Pen & SciFigs::Legend::pen | ( | int | i | ) | const |
References SciFigs::Pen::null, and TRACE.
Referenced by Seismic1DThread::addModel(), MagnetoTelluricThread::addModel(), createCurve(), createCurveName(), createCurveNamePlot(), createCurvePlot(), SciFigs::LegendTableItem::data(), SciFigs::LegendWidget::paint(), penColorToSymbolBrush(), penColorToSymbolPen(), penColorToText(), SciFigs::PaletteInterpole::setColors(), SciFigs::LegendTableItem::setData(), SciFigs::NameLineLayer::setLegend(), SciFigs::LineLayer::setLegend(), setPens(), and ProcessStatus::updateMisfitCurve().
const Pen & SciFigs::Legend::pen | ( | const QString & | text | ) | const |
void SciFigs::Legend::penColorToSymbolPen | ( | ) |
References pen(), SciFigs::Pen::setColor(), and TRACE.
void SciFigs::Legend::penColorToText | ( | ) |
void SciFigs::Legend::resize | ( | int | n | ) |
References TRACE.
Referenced by defaultBW(), defaultColors(), setPen(), setSymbol(), setText(), setTextColor(), setTexts(), ProcessStatus::synchronize(), ProcessStatus::updateMisfitCurve(), and xml_member().
{ TRACE; _items.resize(n); resetTextLookup(); }
void SciFigs::Legend::setPen | ( | int | i, |
Pen | p | ||
) |
References resize(), and TRACE.
Referenced by SciFigs::NameLineLayer::legend(), SciFigs::LineLayer::legend(), SciFigs::LegendTableItem::setData(), and setTexts().
void SciFigs::Legend::setPens | ( | const Legend & | o | ) |
void SciFigs::Legend::setSymbol | ( | int | i, |
Symbol | s | ||
) |
References resize(), and TRACE.
Referenced by SciFigs::NameLineLayer::legend(), SciFigs::LineLayer::legend(), SciFigs::LegendTableItem::setData(), and setTexts().
void SciFigs::Legend::setSymbols | ( | const Legend & | o | ) |
void SciFigs::Legend::setText | ( | int | i, |
QString | t | ||
) |
References resize(), and TRACE.
Referenced by SciFigs::NameLineLayer::legend(), SciFigs::LineLayer::legend(), SciFigs::LegendTableItem::setData(), setTexts(), and ProcessStatus::updateMisfitCurve().
void SciFigs::Legend::setTextColor | ( | int | i, |
QColor | c | ||
) |
References resize(), and TRACE.
Referenced by SciFigs::NameLineLayer::legend(), and SciFigs::LegendTableItem::setData().
void SciFigs::Legend::setTextColors | ( | const Legend & | o | ) |
References count(), textColor(), and TRACE.
void SciFigs::Legend::setTexts | ( | const QStringList & | texts, |
const Pen & | defaultPen, | ||
const Symbol & | defaultSymbol | ||
) |
Sets legend items to match tests list. All items not in texts are removed and all texts not available in items are added at the end with the defaultPen and the defaultSymbol.
References count(), indexOf(), resize(), setPen(), setSymbol(), setText(), text(), and TRACE.
Referenced by MonoStation::AbstractSummary::setStations().
{ TRACE; foreach(QString text, texts) { int index=indexOf(text); if(index==-1) { index=count(); resize(index+1); setText(index, text); setPen(index, defaultPen); setSymbol(index, defaultSymbol); } } // Eventually remove unsused items, do not use erase() which is likely to // be unefficient if there are many entries to remove. if(texts.count()<count()) { QSet<QString> textSet; foreach(QString text, texts) { textSet.insert(text); } QVector<LegendItem> newItems; int n=count(); newItems.reserve(n); for(int i=0; i<n; i++) { if(textSet.contains(text(i))) { newItems.append(_items.at(i)); } } _items=newItems; resetTextLookup(); } }
void SciFigs::Legend::setTexts | ( | const Legend & | o | ) |
const Symbol & SciFigs::Legend::symbol | ( | int | i | ) | const |
References SciFigs::Symbol::null, and TRACE.
Referenced by Seismic1DThread::addModel(), MagnetoTelluricThread::addModel(), createCurve(), createCurveName(), createCurveNamePlot(), createCurvePlot(), SciFigs::LegendTableItem::data(), SciFigs::LegendWidget::paint(), MonoStation::AbstractSummary::setBubbleValues(), SciFigs::LegendTableItem::setData(), SciFigs::NameLineLayer::setLegend(), SciFigs::LineLayer::setLegend(), setSymbols(), and ProcessStatus::updateMisfitCurve().
{ TRACE; if(i >= _items.count()) i=_items.count() - 1; if(_items.count() > 0) { return _items[ i ].symbol(); } else { return Symbol::null; } }
const Symbol & SciFigs::Legend::symbol | ( | const QString & | text | ) | const |
References indexOf(), SciFigs::Symbol::null, and TRACE.
{ TRACE; int i=indexOf(text); if(i > -1) { return _items[ i ].symbol(); } else { return Symbol::null; } }
const QString & SciFigs::Legend::text | ( | int | i | ) | const |
References TRACE.
Referenced by SciFigs::LegendTableItem::data(), indexOf(), SciFigs::LegendWidget::paint(), SciFigs::PaletteInterpole::setColors(), and setTexts().
{ TRACE; if(i >= _items.count()) i=_items.count() - 1; return _items[ i ].text(); }
const QColor & SciFigs::Legend::textColor | ( | int | i | ) | const |
References TRACE.
Referenced by SciFigs::LegendTableItem::data(), SciFigs::LegendWidget::paint(), MonoStation::AbstractSummary::setBubbleValues(), SciFigs::NameLineLayer::setLegend(), and setTextColors().
{ TRACE; if(i >= _items.count()) i=_items.count() - 1; return _items[ i ].textColor(); }
QStringList SciFigs::Legend::texts | ( | ) | const |
XMLMember SciFigs::Legend::xml_member | ( | XML_MEMBER_ARGS | ) | [protected, virtual] |
Re-implement this function to offer XML restore (children and properties) support to your class.
From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:
Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):
static const QString tmp("childrenName"); XMLRestoreAttributeIterator it=map.find(tmp); if(it!=map.end()) { // found attribute "childrenName" }
If the map of attributes is not used:
Q_UNUSED(attributes); if(tag=="x1") return XMLMember(0); else if(tag=="y1") return XMLMember(1); else if(tag=="x2") return XMLMember(2); else if(tag=="y2") return XMLMember(3); else return XMLMember(XMLMember::Unknown);
Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.
if(tag=="anInteger") return XMLMember(0); else if(tag=="aString") return XMLMember(1); else if(tag=="aDouble") return XMLMember(2); return AbstractLine::xml_member(tag, attributes, context)+3;
For the arguments of this function use Macro XML_MEMBER_ARGS.
Reimplemented from QGpCoreTools::XMLClass.
virtual const QString& SciFigs::Legend::xml_tagName | ( | ) | const [inline, virtual] |
Implements QGpCoreTools::XMLClass.
{return xmlLegendTag;}
void SciFigs::Legend::xml_writeChildren | ( | XML_WRITECHILDREN_ARGS | ) | const [protected, virtual] |
Reimplemented from QGpCoreTools::XMLClass.
References TRACE, and QGpCoreTools::XMLClass::xml_save().
const QString SciFigs::Legend::xmlLegendTag = "Legend" [static] |