File indexing completed on 2024-12-22 04:17:25
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 "basicplugindialog.h" 0014 0015 #include "dialogpage.h" 0016 0017 #include "objectstore.h" 0018 #include "datacollection.h" 0019 #include "document.h" 0020 #include "basicplugin.h" 0021 #include "updatemanager.h" 0022 0023 #include <QMessageBox> 0024 0025 namespace Kst { 0026 0027 BasicPluginTab::BasicPluginTab(QString& pluginName, QWidget *parent) 0028 : DataTab(parent) { 0029 0030 setupUi(this); 0031 setTabTitle(tr("Basic Plugin")); 0032 0033 QGridLayout *layout = new QGridLayout(_inputOutputBox); 0034 _configWidget = DataObject::pluginWidget(pluginName); 0035 _configWidget->setupSlots(this); 0036 layout->addWidget(_configWidget, 0, 0); 0037 layout->activate(); 0038 } 0039 0040 0041 BasicPluginTab::~BasicPluginTab() { 0042 } 0043 0044 0045 void BasicPluginTab::setObjectStore(ObjectStore *store) { 0046 _configWidget->setObjectStore(store); 0047 } 0048 0049 0050 BasicPluginDialog::BasicPluginDialog(QString& pluginName, ObjectPtr dataObject, QWidget *parent) 0051 : DataDialog(dataObject, parent), _pluginName(pluginName) { 0052 0053 QString title; 0054 if (editMode() == Edit) 0055 title = tr("Edit %1 Plugin", "arg1 is a plugin name").arg(pluginName); 0056 else 0057 title = tr("New %1 Plugin", "arg1 is a plugin name").arg(pluginName); 0058 setWindowTitle(title); 0059 0060 _basicPluginTab = new BasicPluginTab(pluginName, this); 0061 addDataTab(_basicPluginTab); 0062 0063 if (dataObject) { 0064 _basicPluginTab->configWidget()->setupFromObject(dataObject); 0065 } else { 0066 _basicPluginTab->configWidget()->load(); 0067 } 0068 } 0069 0070 0071 BasicPluginDialog::~BasicPluginDialog() { 0072 } 0073 0074 0075 QString BasicPluginDialog::tagString() const { 0076 return DataDialog::tagString(); 0077 } 0078 0079 0080 ObjectPtr BasicPluginDialog::createNewDataObject() { 0081 BasicPluginPtr dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(_pluginName, _document->objectStore(), _basicPluginTab->configWidget())); 0082 0083 _basicPluginTab->configWidget()->save(); 0084 0085 if (!dataObject->isValid()) { 0086 _document->objectStore()->removeObject(dataObject); 0087 QString msg(tr("Unable to create Plugin Object using provided parameters.\n\n")); 0088 msg += dataObject->errorMessage(); 0089 QMessageBox::warning(this, tr("Kst"), msg); 0090 0091 return 0; 0092 } 0093 UpdateManager::self()->doUpdates(true); 0094 0095 return dataObject; 0096 } 0097 0098 0099 ObjectPtr BasicPluginDialog::editExistingDataObject() const { 0100 if (BasicPlugin* plugin = kst_cast<BasicPlugin>(dataObject())) { 0101 plugin->writeLock(); 0102 plugin->change(_basicPluginTab->configWidget()); 0103 if (DataDialog::tagStringAuto()) { 0104 plugin->setDescriptiveName(QString()); 0105 } else { 0106 plugin->setDescriptiveName(DataDialog::tagString()); 0107 } 0108 0109 plugin->registerChange(); 0110 plugin->unlock(); 0111 } 0112 UpdateManager::self()->doUpdates(true); 0113 0114 return dataObject(); 0115 } 0116 0117 } 0118 0119 // vim: ts=2 sw=2 et