File indexing completed on 2024-12-22 04:17:31
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "eventmonitordialog.h" 0014 0015 #include "dialogpage.h" 0016 #include "editmultiplewidget.h" 0017 0018 #include "datacollection.h" 0019 #include "document.h" 0020 #include "objectstore.h" 0021 0022 #include "eventmonitorentry.h" 0023 #include "updatemanager.h" 0024 0025 namespace Kst { 0026 0027 EventMonitorTab::EventMonitorTab(QWidget *parent) 0028 : DataTab(parent), _logLevelDirty(false) { 0029 0030 setupUi(this); 0031 setTabTitle(tr("Event Monitor")); 0032 0033 connect(_equation, SIGNAL(textChanged(QString)), this, SLOT(selectionChanged())); 0034 connect(_equationOperator, SIGNAL(currentIndexChanged(QString)), this, SLOT(equationOperatorUpdate(QString))); 0035 connect(_vectorSelector, SIGNAL(selectionChanged(QString)), this, SLOT(equationUpdate(QString))); 0036 connect(_scalarSelector, SIGNAL(selectionChanged(QString)), this, SLOT(equationUpdate(QString))); 0037 0038 connect(_debugLog, SIGNAL(toggled(bool)), this, SIGNAL(modified())); 0039 connect(_emailNotify, SIGNAL(toggled(bool)), this, SIGNAL(modified())); 0040 connect(_ELOGNotify, SIGNAL(toggled(bool)), this, SIGNAL(modified())); 0041 connect(_executeScript, SIGNAL(toggled(bool)), this, SIGNAL(modified())); 0042 0043 connect(_equation, SIGNAL(textChanged(QString)), this, SIGNAL(modified())); 0044 connect(_description, SIGNAL(textChanged(QString)), this, SIGNAL(modified())); 0045 connect(_emailRecipients, SIGNAL(textChanged(QString)), this, SIGNAL(modified())); 0046 connect(_script, SIGNAL(textChanged()), this, SIGNAL(modified())); 0047 0048 connect(_debugLogNotice, SIGNAL(clicked()), this, SIGNAL(modified())); 0049 connect(_debugLogWarning, SIGNAL(clicked()), this, SIGNAL(modified())); 0050 connect(_debugLogError, SIGNAL(clicked()), this, SIGNAL(modified())); 0051 0052 connect(_debugLogNotice, SIGNAL(clicked()), this, SLOT(logLevelChanged())); 0053 connect(_debugLogWarning, SIGNAL(clicked()), this, SLOT(logLevelChanged())); 0054 connect(_debugLogError, SIGNAL(clicked()), this, SLOT(logLevelChanged())); 0055 } 0056 0057 0058 EventMonitorTab::~EventMonitorTab() { 0059 } 0060 0061 0062 void EventMonitorTab::selectionChanged() { 0063 emit optionsChanged(); 0064 } 0065 0066 void EventMonitorTab::equationUpdate(const QString& string) { 0067 QString equation = _equation->text(); 0068 equation += '[' + string + ']'; 0069 _equation->setText(equation); 0070 } 0071 0072 void EventMonitorTab::equationOperatorUpdate(const QString& string) { 0073 QString equation = _equation->text(); 0074 equation += string; 0075 _equation->setText(equation); 0076 } 0077 0078 void EventMonitorTab::logLevelChanged() { 0079 _logLevelDirty = true; 0080 } 0081 0082 0083 void EventMonitorTab::resetLogLevelDirty() { 0084 _logLevelDirty = false; 0085 } 0086 0087 0088 QString EventMonitorTab::script() const { 0089 return _script->toPlainText(); 0090 } 0091 0092 0093 bool EventMonitorTab::scriptDirty() const { 0094 return !_script->toPlainText().isEmpty(); 0095 } 0096 0097 0098 void EventMonitorTab::setScript(const QString script) { 0099 return _script->setText(script); 0100 } 0101 0102 0103 QString EventMonitorTab::kstEvent() const { 0104 return _equation->text(); 0105 } 0106 0107 0108 bool EventMonitorTab::eventDirty() const { 0109 return !_equation->text().isEmpty(); 0110 } 0111 0112 0113 void EventMonitorTab::setEvent(const QString event) { 0114 return _equation->setText(event); 0115 } 0116 0117 0118 QString EventMonitorTab::description() const { 0119 return _description->text(); 0120 } 0121 0122 0123 bool EventMonitorTab::descriptionDirty() const { 0124 return !_description->text().isEmpty(); 0125 } 0126 0127 0128 void EventMonitorTab::setDescription(const QString description) { 0129 return _description->setText(description); 0130 } 0131 0132 0133 QString EventMonitorTab::emailRecipients() const { 0134 return _emailRecipients->text(); 0135 } 0136 0137 0138 bool EventMonitorTab::emailRecipientsDirty() const { 0139 return !_emailRecipients->text().isEmpty(); 0140 } 0141 0142 0143 void EventMonitorTab::setEmailRecipients(const QString emailRecipients) { 0144 return _emailRecipients->setText(emailRecipients); 0145 } 0146 0147 0148 Debug::LogLevel EventMonitorTab::logLevel() const { 0149 if (_debugLogNotice->isChecked()) { 0150 return Debug::Notice; 0151 } else if (_debugLogWarning->isChecked()) { 0152 return Debug::Warning; 0153 } else { 0154 return Debug::Error; 0155 } 0156 } 0157 0158 0159 bool EventMonitorTab::logLevelDirty() const { 0160 return _logLevelDirty; 0161 } 0162 0163 0164 void EventMonitorTab::setLogLevel(const Debug::LogLevel logLevel) { 0165 switch (logLevel) { 0166 case Debug::Notice: 0167 _debugLogNotice->setChecked(true); 0168 break; 0169 case Debug::Warning: 0170 _debugLogWarning->setChecked(true); 0171 break; 0172 case Debug::Error: 0173 _debugLogError->setChecked(true); 0174 break; 0175 default: 0176 break; 0177 } 0178 resetLogLevelDirty(); 0179 } 0180 0181 0182 bool EventMonitorTab::logDebug() const { 0183 return _debugLog->isChecked(); 0184 } 0185 0186 0187 bool EventMonitorTab::logDebugDirty() const { 0188 return _debugLog->checkState() != Qt::PartiallyChecked; 0189 } 0190 0191 0192 void EventMonitorTab::setLogDebug(const bool logDebug) { 0193 return _debugLog->setChecked(logDebug); 0194 } 0195 0196 0197 bool EventMonitorTab::logEMail() const { 0198 return _emailNotify->isChecked(); 0199 } 0200 0201 0202 bool EventMonitorTab::logEMailDirty() const { 0203 return _emailNotify->checkState() != Qt::PartiallyChecked; 0204 } 0205 0206 0207 void EventMonitorTab::setLogEMail(const bool logEMail) { 0208 return _emailNotify->setChecked(logEMail); 0209 } 0210 0211 0212 bool EventMonitorTab::logELOG() const { 0213 return _ELOGNotify->isChecked(); 0214 } 0215 0216 0217 bool EventMonitorTab::logELOGDirty() const { 0218 return _ELOGNotify->checkState() != Qt::PartiallyChecked; 0219 } 0220 0221 0222 void EventMonitorTab::setLogELOG(const bool logELOG) { 0223 return _ELOGNotify->setChecked(logELOG); 0224 } 0225 0226 0227 void EventMonitorTab::setObjectStore(ObjectStore *store) { 0228 _vectorSelector->setObjectStore(store); 0229 _scalarSelector->setObjectStore(store); 0230 } 0231 0232 0233 void EventMonitorTab::clearTabValues() { 0234 _equation->clear(); 0235 _emailRecipients->clear(); 0236 _description->clear(); 0237 _script->clear(); 0238 _executeScript->setCheckState(Qt::PartiallyChecked); 0239 _ELOGNotify->setCheckState(Qt::PartiallyChecked); 0240 _emailNotify->setCheckState(Qt::PartiallyChecked); 0241 _debugLog->setCheckState(Qt::PartiallyChecked); 0242 resetLogLevelDirty(); 0243 } 0244 0245 0246 EventMonitorDialog::EventMonitorDialog(ObjectPtr dataObject, QWidget *parent) 0247 : DataDialog(dataObject, parent) { 0248 0249 if (editMode() == Edit) 0250 setWindowTitle(tr("Edit Event Monitor")); 0251 else 0252 setWindowTitle(tr("New Event Monitor")); 0253 0254 _eventMonitorTab = new EventMonitorTab(this); 0255 addDataTab(_eventMonitorTab); 0256 0257 if (editMode() == Edit) { 0258 configureTab(dataObject); 0259 } 0260 0261 connect(_eventMonitorTab, SIGNAL(optionsChanged()), this, SLOT(updateButtons())); 0262 connect(this, SIGNAL(editMultipleMode()), this, SLOT(editMultipleMode())); 0263 connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode())); 0264 0265 connect(_eventMonitorTab, SIGNAL(modified()), this, SLOT(modified())); 0266 updateButtons(); 0267 } 0268 0269 0270 EventMonitorDialog::~EventMonitorDialog() { 0271 } 0272 0273 0274 // QString EventMonitorDialog::tagString() const { 0275 // return DataDialog::tagString(); 0276 // } 0277 0278 0279 void EventMonitorDialog::editMultipleMode() { 0280 _eventMonitorTab->clearTabValues(); 0281 } 0282 0283 0284 void EventMonitorDialog::editSingleMode() { 0285 configureTab(dataObject()); 0286 } 0287 0288 0289 void EventMonitorDialog::configureTab(ObjectPtr object) { 0290 if (EventMonitorEntryPtr eventMonitorEntry = kst_cast<EventMonitorEntry>(object)) { 0291 _eventMonitorTab->setScript(eventMonitorEntry->scriptCode()); 0292 _eventMonitorTab->setEvent(eventMonitorEntry->kstEvent()); 0293 _eventMonitorTab->setDescription(eventMonitorEntry->description()); 0294 _eventMonitorTab->setLogLevel(eventMonitorEntry->level()); 0295 _eventMonitorTab->setLogDebug(eventMonitorEntry->logDebug()); 0296 _eventMonitorTab->setLogEMail(eventMonitorEntry->logEMail()); 0297 _eventMonitorTab->setLogELOG(eventMonitorEntry->logELOG()); 0298 _eventMonitorTab->setEmailRecipients(eventMonitorEntry->eMailRecipients()); 0299 if (_editMultipleWidget) { 0300 EventMonitorEntryList objects = _document->objectStore()->getObjects<EventMonitorEntry>(); 0301 _editMultipleWidget->clearObjects(); 0302 foreach(EventMonitorEntryPtr object, objects) { 0303 _editMultipleWidget->addObject(object->Name(), object->descriptionTip()); 0304 } 0305 } 0306 } 0307 } 0308 0309 0310 void EventMonitorDialog::updateButtons() { 0311 _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!_eventMonitorTab->kstEvent().isEmpty() || (editMode() == EditMultiple)); 0312 } 0313 0314 0315 ObjectPtr EventMonitorDialog::createNewDataObject() { 0316 Q_ASSERT(_document && _document->objectStore()); 0317 EventMonitorEntryPtr eventMonitor = _document->objectStore()->createObject<EventMonitorEntry>(); 0318 0319 eventMonitor->setScriptCode(_eventMonitorTab->script()); 0320 eventMonitor->setEvent(_eventMonitorTab->kstEvent()); 0321 eventMonitor->setDescription(_eventMonitorTab->description()); 0322 eventMonitor->setLevel(_eventMonitorTab->logLevel()); 0323 eventMonitor->setLogDebug(_eventMonitorTab->logDebug()); 0324 eventMonitor->setLogEMail(_eventMonitorTab->logEMail()); 0325 eventMonitor->setLogELOG(_eventMonitorTab->logELOG()); 0326 eventMonitor->setEMailRecipients(_eventMonitorTab->emailRecipients()); 0327 0328 eventMonitor->reparse(); 0329 0330 eventMonitor->writeLock(); 0331 eventMonitor->registerChange(); 0332 eventMonitor->unlock(); 0333 0334 return ObjectPtr(eventMonitor.data()); 0335 } 0336 0337 0338 ObjectPtr EventMonitorDialog::editExistingDataObject() const { 0339 if (EventMonitorEntryPtr eventMonitor = kst_cast<EventMonitorEntry>(dataObject())) { 0340 if (editMode() == EditMultiple) { 0341 QStringList objects = _editMultipleWidget->selectedObjects(); 0342 foreach (const QString &objectName, objects) { 0343 EventMonitorEntryPtr eventMonitor = kst_cast<EventMonitorEntry>(_document->objectStore()->retrieveObject(objectName)); 0344 if (eventMonitor) { 0345 const QString script = _eventMonitorTab->scriptDirty() ? _eventMonitorTab->script() : eventMonitor->scriptCode(); 0346 const QString event = _eventMonitorTab->eventDirty() ? _eventMonitorTab->kstEvent() : eventMonitor->kstEvent(); 0347 const QString description = _eventMonitorTab->descriptionDirty() ? _eventMonitorTab->description() : eventMonitor->description(); 0348 const QString emailRecipients = _eventMonitorTab->emailRecipientsDirty() ? _eventMonitorTab->emailRecipients() : eventMonitor->eMailRecipients(); 0349 const Debug::LogLevel logLevel = _eventMonitorTab->logLevelDirty() ? _eventMonitorTab->logLevel() : eventMonitor->level(); 0350 const bool logDebug = _eventMonitorTab->logDebugDirty() ? _eventMonitorTab->logDebug() : eventMonitor->logDebug(); 0351 const bool logEMail = _eventMonitorTab->logEMailDirty() ? _eventMonitorTab->logEMail() : eventMonitor->logEMail(); 0352 const bool logELOG = _eventMonitorTab->logELOGDirty() ? _eventMonitorTab->logELOG() : eventMonitor->logELOG(); 0353 0354 eventMonitor->writeLock(); 0355 eventMonitor->setScriptCode(script); 0356 eventMonitor->setEvent(event); 0357 eventMonitor->setDescription(description); 0358 eventMonitor->setLevel(logLevel); 0359 eventMonitor->setLogDebug(logDebug); 0360 eventMonitor->setLogEMail(logEMail); 0361 eventMonitor->setLogELOG(logELOG); 0362 eventMonitor->setEMailRecipients(emailRecipients); 0363 0364 eventMonitor->reparse(); 0365 eventMonitor->registerChange(); 0366 eventMonitor->unlock(); 0367 } 0368 } 0369 } else { 0370 eventMonitor->writeLock(); 0371 eventMonitor->setScriptCode(_eventMonitorTab->script()); 0372 eventMonitor->setEvent(_eventMonitorTab->kstEvent()); 0373 eventMonitor->setDescription(_eventMonitorTab->description()); 0374 eventMonitor->setLevel(_eventMonitorTab->logLevel()); 0375 eventMonitor->setLogDebug(_eventMonitorTab->logDebug()); 0376 eventMonitor->setLogEMail(_eventMonitorTab->logEMail()); 0377 eventMonitor->setLogELOG(_eventMonitorTab->logELOG()); 0378 eventMonitor->setEMailRecipients(_eventMonitorTab->emailRecipients()); 0379 0380 eventMonitor->reparse(); 0381 0382 eventMonitor->registerChange(); 0383 eventMonitor->unlock(); 0384 } 0385 } 0386 return dataObject();} 0387 0388 } 0389 0390 // vim: ts=2 sw=2 et