File indexing completed on 2024-12-22 04:17:16

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 "sampledatasource.h"
0014 
0015 #include <QXmlStreamWriter>
0016 #include <QImageReader>
0017 #include <qcolor.h>
0018 
0019 /**********************
0020 SampleDatasourceSource::Config - This class defines the config widget that will be added to the 
0021 Dialog Config Button for configuring the plugin.  This is only needed for special handling required
0022 by the plugin.  Many plugins will not require configuration.  See plugins/sampleplugin for additional
0023 details.
0024 
0025 ***********************/
0026 class SampleDatasourceSource::Config {
0027   public:
0028     Config() {
0029     }
0030 
0031     void read(QSettings *cfg, const QString& fileName = QString()) {
0032       Q_UNUSED(fileName);
0033       cfg->beginGroup("Sample Datasource");
0034       cfg->endGroup();
0035     }
0036 
0037     void save(QXmlStreamWriter& s) {
0038       Q_UNUSED(s);
0039     }
0040 
0041     void load(const QDomElement& e) {
0042       Q_UNUSED(e);
0043     }
0044 };
0045 
0046 
0047 /**********************
0048 SampleDatasourceSource - This class defines the main DataSource which derives from DataSource.
0049 The key functions that this class must provide is the ability to create the source, provide details about the source
0050 be able to process the data.
0051 
0052 ***********************/
0053 SampleDatasourceSource::SampleDatasourceSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e)
0054 : Kst::DataSource(store, cfg, filename, type), _config(0L) {
0055 
0056   startUpdating(None);
0057 
0058   _valid = false;
0059   if (!type.isEmpty() && type != "Sample Datasource") {
0060     return;
0061   }
0062 
0063   _config = new SampleDatasourceSource::Config;
0064   _config->read(cfg, filename);
0065   if (!e.isNull()) {
0066     _config->load(e);
0067   }
0068 
0069   if (init()) {
0070     _valid = true;
0071   }
0072 
0073   registerChange();
0074 }
0075 
0076 
0077 
0078 SampleDatasourceSource::~SampleDatasourceSource() {
0079 }
0080 
0081 
0082 void SampleDatasourceSource::reset() {
0083   init();
0084   Object::reset();
0085 }
0086 
0087 
0088 // If the datasource has any predefined fields they should be populated here.
0089 bool SampleDatasourceSource::init() {
0090   registerChange();
0091   return true; // false if something went wrong
0092 }
0093 
0094 
0095 // Check if the data in the from the source has updated.  Typically done by checking the frame count of the datasource for 
0096 // changes.
0097 Kst::Object::UpdateType SampleDatasourceSource::internalDataSourceUpdate() {
0098   return Kst::Object::NoChange;
0099 }
0100 
0101 
0102 // TODO a DataSource::DataInterface implementation as example
0103 
0104 
0105 
0106 
0107 QString SampleDatasourceSource::fileType() const {
0108   return "Sample Datasource";
0109 }
0110 
0111 
0112 void SampleDatasourceSource::save(QXmlStreamWriter &streamWriter) {
0113   Kst::DataSource::save(streamWriter);
0114 }
0115 
0116 
0117 
0118 
0119 
0120 // Name used to identify the plugin.  Used when loading the plugin.
0121 QString SampleDatasourcePlugin::pluginName() const { return tr("Sample Datasource Reader"); }
0122 QString SampleDatasourcePlugin::pluginDescription() const { return tr("Sample Datasource Reader"); }
0123 
0124 /**********************
0125 SampleDatasourcePlugin - This class defines the plugin interface to the DataSource defined by the plugin.
0126 The primary requirements of this class are to provide the necessary connections to create the object
0127 which includes providing access to the configuration widget.
0128 
0129 ***********************/
0130 
0131 Kst::DataSource *SampleDatasourcePlugin::create(Kst::ObjectStore *store,
0132                                             QSettings *cfg,
0133                                             const QString &filename,
0134                                             const QString &type,
0135                                             const QDomElement &element) const {
0136 
0137   return new SampleDatasourceSource(store, cfg, filename, type, element);
0138 }
0139 
0140 
0141 // Provides the matrix list that this dataSource can provide from the provided filename.
0142 // This function should use understands to validate the file and then open and calculate the 
0143 // list of matrices.
0144 QStringList SampleDatasourcePlugin::matrixList(QSettings *cfg,
0145                                              const QString& filename,
0146                                              const QString& type,
0147                                              QString *typeSuggestion,
0148                                              bool *complete) const {
0149 
0150 
0151   if (typeSuggestion) {
0152     *typeSuggestion = "Sample Datasource";
0153   }
0154   if ((!type.isEmpty() && !provides().contains(type)) ||
0155       0 == understands(cfg, filename)) {
0156     if (complete) {
0157       *complete = false;
0158     }
0159     return QStringList();
0160   }
0161   QStringList matrixList;
0162 
0163   return matrixList;
0164 
0165 }
0166 
0167 
0168 // Provides the scalar list that this dataSource can provide from the provided filename.
0169 // This function should use understands to validate the file and then open and calculate the 
0170 // list of scalars if necessary.
0171 QStringList SampleDatasourcePlugin::scalarList(QSettings *cfg,
0172                                             const QString& filename,
0173                                             const QString& type,
0174                                             QString *typeSuggestion,
0175                                             bool *complete) const {
0176 
0177   QStringList scalarList;
0178 
0179   if ((!type.isEmpty() && !provides().contains(type)) || 0 == understands(cfg, filename)) {
0180     if (complete) {
0181       *complete = false;
0182     }
0183     return QStringList();
0184   }
0185 
0186   if (typeSuggestion) {
0187     *typeSuggestion = "Sample Datasource";
0188   }
0189 
0190   scalarList.append("FRAMES");
0191   return scalarList;
0192 
0193 }
0194 
0195 
0196 // Provides the string list that this dataSource can provide from the provided filename.
0197 // This function should use understands to validate the file and then open and calculate the 
0198 // list of strings if necessary.
0199 QStringList SampleDatasourcePlugin::stringList(QSettings *cfg,
0200                                       const QString& filename,
0201                                       const QString& type,
0202                                       QString *typeSuggestion,
0203                                       bool *complete) const {
0204 
0205   QStringList stringList;
0206 
0207   if ((!type.isEmpty() && !provides().contains(type)) || 0 == understands(cfg, filename)) {
0208     if (complete) {
0209       *complete = false;
0210     }
0211     return QStringList();
0212   }
0213 
0214   if (typeSuggestion) {
0215     *typeSuggestion = "Sample Datasource";
0216   }
0217 
0218   stringList.append("FILENAME");
0219   return stringList;
0220 
0221 }
0222 
0223 
0224 // Provides the field list that this dataSource can provide from the provided filename.
0225 // This function should use understands to validate the file and then open and calculate the 
0226 // list of fields if necessary.
0227 QStringList SampleDatasourcePlugin::fieldList(QSettings *cfg,
0228                                             const QString& filename,
0229                                             const QString& type,
0230                                             QString *typeSuggestion,
0231                                             bool *complete) const {
0232   Q_UNUSED(cfg)
0233   Q_UNUSED(filename)
0234   Q_UNUSED(type)
0235 
0236   if (complete) {
0237     *complete = true;
0238   }
0239 
0240   if (typeSuggestion) {
0241     *typeSuggestion = "Sample Datasource";
0242   }
0243 
0244   QStringList fieldList;
0245   return fieldList;
0246 }
0247 
0248 
0249 // The main function used to determine if this plugin knows how to process the provided file.
0250 // Each datasource plugin should check the file and return a number between 0 and 100 based 
0251 // on the likelyhood of the file being this type.  100 should only be returned if there is no way
0252 // that the file could be any datasource other than this one.
0253 int SampleDatasourcePlugin::understands(QSettings *cfg, const QString& filename) const {
0254   Q_UNUSED(cfg)
0255   Q_UNUSED(filename)
0256   return 0;
0257 }
0258 
0259 
0260 
0261 bool SampleDatasourcePlugin::supportsTime(QSettings *cfg, const QString& filename) const {
0262   //FIXME
0263   Q_UNUSED(cfg)
0264   Q_UNUSED(filename)
0265   return true;
0266 }
0267 
0268 
0269 QStringList SampleDatasourcePlugin::provides() const {
0270   QStringList rc;
0271   rc += "Sample Datasource";
0272   return rc;
0273 }
0274 
0275 
0276 // Request for this plugins configuration widget.  
0277 Kst::DataSourceConfigWidget *SampleDatasourcePlugin::configWidget(QSettings *cfg, const QString& filename) const {
0278   Q_UNUSED(cfg)
0279   Q_UNUSED(filename)
0280   return 0;;
0281 
0282 }
0283 
0284 #ifndef QT5
0285 Q_EXPORT_PLUGIN2(kstdata_sampledatasource, SampleDatasourcePlugin)
0286 #endif
0287 
0288 // vim: ts=2 sw=2 et