1 /**************************************************************************************** 2 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com> * 3 * * 4 * This program is free software; you can redistribute it and/or modify it under * 5 * the terms of the GNU General Public License as published by the Free Software * 6 * Foundation; either version 2 of the License, or (at your option) any later * 7 * version. * 8 * * 9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 12 * * 13 * You should have received a copy of the GNU General Public License along with * 14 * this program. If not, see <http://www.gnu.org/licenses/>. * 15 ****************************************************************************************/ 16 17 #ifndef STATSYNCING_SIMPLE_IMPORTER_CONFIG_WIDGET 18 #define STATSYNCING_SIMPLE_IMPORTER_CONFIG_WIDGET 19 20 #include "statsyncing/Provider.h" 21 22 #include <QMap> 23 24 class QGridLayout; 25 26 namespace StatSyncing 27 { 28 29 /** 30 * SimpleImporterConfigWidget is a helper class for creating non-sophisticated config 31 * widgets for importers. 32 */ 33 class AMAROK_EXPORT SimpleImporterConfigWidget : public ProviderConfigWidget 34 { 35 public: 36 /** 37 * Constructor. Creates a widget with one label: "Target name," and one text field 38 * with its default value specified in @p targetName . @p config contains 39 * configuration for this widget. 40 * @param targetName the target name 41 * @param config configuration for the created widget 42 * @param parent the parent widget 43 * @param f Qt window flags 44 */ 45 SimpleImporterConfigWidget( const QString &targetName, const QVariantMap &config, 46 QWidget *parent = nullptr, Qt::WindowFlags f = {} ); 47 48 /** 49 * Destructor. 50 */ 51 ~SimpleImporterConfigWidget() override; 52 53 /** 54 * addField adds a new row to the widget. @param configName is the name of the config 55 * value associated with this field. The row contains a label initialized with 56 * @param label and a QWidget @param field initialized with config[configName] 57 * (if set). @param property must specify the name of field's property that contains 58 * value we want to configure; e.g. for a text field property will be "text", and for 59 * a combo box the property may be "currentText" . 60 * 61 * The ownership of field is transferred to SimpleImporterConfigWidget. 62 */ 63 void addField( const QString &configName, const QString &label, 64 QWidget * const field, const QString &property ); 65 66 /** 67 * Returns a config generated from this widget's fields. 68 */ 69 QVariantMap config() const override; 70 71 private: 72 const QVariantMap m_config; 73 QMap<QString, QPair<QWidget*, QString> > m_fieldForName; 74 QGridLayout *m_layout; 75 }; 76 77 } // namespace StatSyncing 78 79 #endif // STATSYNCING_SIMPLE_IMPORTER_CONFIG_WIDGET 80