File indexing completed on 2024-04-21 04:02:43
0001 // 0002 // C++ Implementation: cgaugelist 0003 // 0004 // Description: 0005 // 0006 /* 0007 Copyright 2004-2011 Tomas Mecir <kmuddy@kmuddy.com> 0008 0009 This program is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU General Public License as 0011 published by the Free Software Foundation; either version 2 of 0012 the License, or (at your option) any later version. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "cgaugelist.h" 0024 0025 #include "cgauge.h" 0026 #include "cgaugebar.h" 0027 #include "cgaugeeditor.h" 0028 #include "kmuddy.h" 0029 0030 #include <list> 0031 0032 struct cGaugeList::Private { 0033 QString varName; 0034 bool loaded; 0035 std::list<cGauge *> gauges; // a list of all existing gauges 0036 }; 0037 0038 cGaugeList::cGaugeList () : 0039 cList ("gauges") 0040 { 0041 d = new Private; 0042 0043 d->loaded = false; 0044 0045 addStringProperty ("variable", "Variable to react on"); 0046 addStringProperty ("max-variable", "Max variable to react on"); 0047 addStringProperty ("caption", "Caption of the gauge item"); 0048 addIntProperty ("color", "Color to use", 0); 0049 } 0050 0051 cGaugeList::~cGaugeList() 0052 { 0053 delete d; 0054 } 0055 0056 void cGaugeList::addGauge (cGauge *g) 0057 { 0058 d->gauges.push_back (g); 0059 } 0060 0061 void cGaugeList::removeGauge (cGauge *g) 0062 { 0063 d->gauges.remove (g); 0064 } 0065 0066 cListObject *cGaugeList::newObject () 0067 { 0068 return new cGauge (this); 0069 } 0070 0071 cListEditor *cGaugeList::editor (QWidget *parent) 0072 { 0073 return new cGaugeEditor (parent); 0074 } 0075 0076 void cGaugeList::variableChanged (const QString &varname) 0077 { 0078 d->varName = varname; 0079 traverse (GAUGE_MATCH); 0080 } 0081 0082 void cGaugeList::listLoaded () 0083 { 0084 d->loaded = true; 0085 updateGauges (); 0086 } 0087 0088 void cGaugeList::updateGauges () 0089 { 0090 if (!d->loaded) return; // not loaded yet - nothing to do 0091 cGaugeBar *bar = dynamic_cast<cGaugeBar *>(cActionManager::self()->object ("gaugebar", session())); 0092 if (!bar) return; 0093 0094 // first hide everything 0095 std::list<cGauge *>::iterator it; 0096 for (it = d->gauges.begin(); it != d->gauges.end(); ++it) 0097 bar->removeGauge (*it); 0098 0099 // then update/show what has to be shown 0100 // doing it this way ensures that disabling a group hides all child elements 0101 traverse (GAUGE_UPDATE); 0102 0103 //show the gaugebar if we have some unhidden item 0104 if (bar->gauges()) 0105 KMuddy::self()->showGauges (true); 0106 } 0107 0108 QString cGaugeList::variableName () const 0109 { 0110 return d->varName; 0111 } 0112