File indexing completed on 2024-04-21 04:02:44
0001 // 0002 // C++ Implementation: cstatusvarlist 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 "cstatusvarlist.h" 0024 0025 #include "cactionmanager.h" 0026 #include "cstatus.h" 0027 #include "cstatusvar.h" 0028 #include "cstatusvareditor.h" 0029 0030 struct cStatusVarList::Private { 0031 QString varName; 0032 bool updateNeeded, traversing, loaded; 0033 QString statusBar; 0034 }; 0035 0036 cStatusVarList::cStatusVarList () : 0037 cList ("statusvars") 0038 { 0039 d = new Private; 0040 0041 d->updateNeeded = false; 0042 d->traversing = false; 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 addBoolProperty ("percentage", "Show as percentage", false); 0049 } 0050 0051 cStatusVarList::~cStatusVarList() 0052 { 0053 delete d; 0054 } 0055 0056 cListObject *cStatusVarList::newObject () 0057 { 0058 return new cStatusVar (this); 0059 } 0060 0061 cListEditor *cStatusVarList::editor (QWidget *parent) 0062 { 0063 return new cStatusVarEditor (parent); 0064 } 0065 0066 void cStatusVarList::variableChanged (const QString &varname) 0067 { 0068 d->varName = varname; 0069 0070 d->updateNeeded = false; 0071 d->traversing = true; 0072 traverse (STATUSVAR_MATCH); 0073 d->traversing = false; 0074 if (d->updateNeeded) 0075 updateStatusBar (); 0076 } 0077 0078 void cStatusVarList::listLoaded () 0079 { 0080 d->loaded = true; 0081 scheduleUpdate (); 0082 } 0083 0084 void cStatusVarList::scheduleUpdate () 0085 { 0086 if (!d->loaded) return; // not loaded yet - nothing to do 0087 // if we're working, schedule a delayed update, otherwise an immediate update 0088 if (d->traversing) 0089 d->updateNeeded = true; 0090 else 0091 updateStatusBar (); 0092 } 0093 0094 void cStatusVarList::updateStatusBar () 0095 { 0096 d->statusBar.clear(); 0097 traverse (STATUSVAR_UPDATE); 0098 cStatus *status = dynamic_cast<cStatus *>(cActionManager::self()->object ("status", session())); 0099 status->displayVariables (d->statusBar); 0100 } 0101 0102 void cStatusVarList::addToStatusBar (const QString &text) 0103 { 0104 if (!text.isEmpty()) 0105 d->statusBar += text + " "; 0106 } 0107 0108 QString cStatusVarList::variableName () const 0109 { 0110 return d->varName; 0111 } 0112