File indexing completed on 2024-05-05 04:48:33

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com>                             *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef STATSYNCING_SIMPLE_IMPORTER_CONFIG_WIDGET
0018 #define STATSYNCING_SIMPLE_IMPORTER_CONFIG_WIDGET
0019 
0020 #include "statsyncing/Provider.h"
0021 
0022 #include <QMap>
0023 
0024 class QGridLayout;
0025 
0026 namespace StatSyncing
0027 {
0028 
0029 /**
0030  * SimpleImporterConfigWidget is a helper class for creating non-sophisticated config
0031  * widgets for importers.
0032  */
0033 class AMAROK_EXPORT SimpleImporterConfigWidget : public ProviderConfigWidget
0034 {
0035 public:
0036     /**
0037      * Constructor. Creates a widget with one label: "Target name," and one text field
0038      * with its default value specified in @p targetName . @p config contains
0039      * configuration for this widget.
0040      * @param targetName the target name
0041      * @param config configuration for the created widget
0042      * @param parent the parent widget
0043      * @param f Qt window flags
0044      */
0045     SimpleImporterConfigWidget( const QString &targetName, const QVariantMap &config,
0046                                 QWidget *parent = nullptr, Qt::WindowFlags f = {} );
0047 
0048     /**
0049       * Destructor.
0050       */
0051     ~SimpleImporterConfigWidget() override;
0052 
0053     /**
0054      * addField adds a new row to the widget. @param configName is the name of the config
0055      * value associated with this field. The row contains a label initialized with
0056      * @param label and a QWidget @param field initialized with config[configName]
0057      * (if set). @param property must specify the name of field's property that contains
0058      * value we want to configure; e.g. for a text field property will be "text", and for
0059      * a combo box the property may be "currentText" .
0060      *
0061      * The ownership of field is transferred to SimpleImporterConfigWidget.
0062      */
0063     void addField( const QString &configName, const QString &label,
0064                    QWidget * const field, const QString &property );
0065 
0066     /**
0067      * Returns a config generated from this widget's fields.
0068      */
0069     QVariantMap config() const override;
0070 
0071 private:
0072     const QVariantMap m_config;
0073     QMap<QString, QPair<QWidget*, QString> > m_fieldForName;
0074     QGridLayout *m_layout;
0075 };
0076 
0077 } // namespace StatSyncing
0078 
0079 #endif // STATSYNCING_SIMPLE_IMPORTER_CONFIG_WIDGET