build: update parfait spec with a parfait-agent package
[pcp.git] / src / pmview / defaultobj.cpp
blob908aac602c45231c710290ff85eaf865d0215ceb
1 /*
2 * Copyright (c) 1997 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (c) 2009 Aconex. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
15 #include "defaultobj.h"
16 #include "colorlist.h"
17 #include <QSettings>
19 #include <iostream>
20 using namespace std;
22 DefaultObj *DefaultObj::theDefaultObj;
24 DefaultObj::DefaultObj()
25 : _baseBorderX(8),
26 _baseBorderZ(8),
27 _baseHeight(6),
28 _barSpaceX(8),
29 _barSpaceZ(8),
30 _barSpaceLabel(6),
31 _barLength(28),
32 _barHeight(80),
33 _labelMargin(5),
34 _gridMinWidth(20),
35 _gridMinDepth(20)
37 _baseColor[0] = _baseColor[1] = _baseColor[2] = 0.15;
38 _labelColor[0] = _labelColor[1] = _labelColor[2] = 1.0;
39 _pipeLength = _barHeight;
42 const DefaultObj &
43 DefaultObj::defObj()
45 if (!theDefaultObj) {
46 theDefaultObj = new DefaultObj;
47 theDefaultObj->getResources();
49 return *theDefaultObj;
52 DefaultObj &
53 DefaultObj::changeDefObj()
55 if (!theDefaultObj) {
56 theDefaultObj = new DefaultObj;
57 theDefaultObj->getResources();
59 return *theDefaultObj;
62 DefaultObj::DefaultObj(const DefaultObj &rhs)
63 : _baseBorderX(rhs._baseBorderX),
64 _baseBorderZ(rhs._baseBorderZ),
65 _baseHeight(rhs._baseHeight),
66 _barSpaceX(rhs._barSpaceX),
67 _barSpaceZ(rhs._barSpaceZ),
68 _barSpaceLabel(rhs._barSpaceLabel),
69 _barLength(rhs._barLength),
70 _barHeight(rhs._barHeight),
71 _labelMargin(rhs._labelMargin),
72 _gridMinWidth(rhs._gridMinWidth),
73 _gridMinDepth(rhs._gridMinDepth),
74 _pipeLength(rhs._pipeLength)
76 int i;
78 for (i = 0; i < 3; i++) {
79 _baseColor[i] = rhs._baseColor[i];
80 _labelColor[i] = rhs._labelColor[i];
84 const DefaultObj &
85 DefaultObj::operator=(const DefaultObj &rhs)
87 int i;
89 if (this != &rhs) {
90 _baseBorderX = rhs._baseBorderX;
91 _baseBorderZ = rhs._baseBorderZ;
92 _baseHeight = rhs._baseHeight;
93 _barSpaceX = rhs._barSpaceX;
94 _barSpaceZ = rhs._barSpaceZ;
95 _barSpaceLabel = rhs._barSpaceLabel;
96 _barLength = rhs._barLength;
97 _barHeight = rhs._barHeight;
98 _labelMargin = rhs._labelMargin;
99 _gridMinWidth = rhs._gridMinWidth;
100 _gridMinDepth = rhs._gridMinDepth;
102 for (i = 0; i < 3; i++) {
103 _baseColor[i] = rhs._baseColor[i];
104 _labelColor[i] = rhs._labelColor[i];
107 return *this;
110 QTextStream&
111 operator<<(QTextStream &os, const DefaultObj &rhs)
113 os << "baseBorderX=" << rhs._baseBorderX;
114 os << ", baseBorderZ=" << rhs._baseBorderZ;
115 os << ", baseHeight=" << rhs._baseHeight;
116 os << ", baseColor=" << rhs._baseColor[0] << ',' << rhs._baseColor[1]
117 << ',' << rhs._baseColor[2] << endl;
118 os << ", barSpaceX=" << rhs._barSpaceX;
119 os << ", barSpaceZ=" << rhs._barSpaceZ;
120 os << ", barSpaceLabel=" << rhs._barSpaceLabel;
121 os << ", barLength=" << rhs._barLength;
122 os << ", barHeight=" << rhs._barHeight;
123 os << ", labelMargin=" << rhs._labelMargin;
124 os << ", labelColor=" << rhs._labelColor[0] << ',' << rhs._labelColor[1]
125 << ',' << rhs._labelColor[2] << endl;
126 os << ", gridMinWidth=" << rhs._gridMinWidth;
127 os << ", gridMinDepth=" << rhs._gridMinDepth;
128 return os;
131 static void
132 getColorResource(const char *name, QString label, float &r, float &g, float &b)
134 if (label != QString::null && label.compare("default") != 0) {
135 const char *str = (const char *)label.toLatin1();
136 if (ColorList::findColor(str, r, g, b) == false) {
137 pmprintf("%s: Unable to map color resource \"%s\" to \"%s\", "
138 "using default color rgbi:%f/%f/%f\n",
139 pmProgname, name, str, r, g, b);
144 void
145 DefaultObj::getResources()
147 QString color;
148 QSettings resources;
149 resources.beginGroup(pmProgname);
151 _baseBorderX = resources.value("baseBorderWidth", 8).toInt();
152 _baseBorderZ = resources.value("baseBorderDepth", 8).toInt();
153 _baseHeight = resources.value("baseHeight", 2).toInt();
154 color = resources.value("baseColor", QString("default")).toString();
155 getColorResource("baseColor", color,
156 _baseColor[0], _baseColor[1], _baseColor[2]);
157 _barSpaceX = resources.value("barSpaceWidth", 8).toInt();
158 _barSpaceZ = resources.value("barSpaceDepth", 8).toInt();
159 _barSpaceLabel = resources.value("barSpaceLabel", 6).toInt();
160 _barLength = resources.value("barLength", 28).toInt();
161 _barHeight = resources.value("barHeight", 80).toInt();
162 _labelMargin = resources.value("labelMargin", 5).toInt();
163 color = resources.value("labelColor", QString("default")).toString();
164 getColorResource("labelColor", color,
165 _labelColor[0], _labelColor[1], _labelColor[2]);
166 _gridMinWidth = resources.value("gridMinWidth", 20).toInt();
167 _gridMinDepth = resources.value("gridMinDepth", 20).toInt();
169 resources.endGroup();
171 #ifdef PCP_DEBUG
172 if (pmDebug & DBG_TRACE_APPL0)
173 cerr << "DefaultObj::getResources: " << *this << endl;
174 #endif