File indexing completed on 2024-12-22 04:13:12
0001 /* 0002 * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "widgets/kis_meta_data_merge_strategy_chooser_widget.h" 0008 0009 #include <KoDialog.h> 0010 #include <kis_debug.h> 0011 #include <kis_meta_data_merge_strategy_registry.h> 0012 0013 #include "ui_wdgmetadatamergestrategychooser.h" 0014 0015 struct KisMetaDataMergeStrategyChooserWidget::Private { 0016 Ui::WdgMetaDataMergeStrategyChooser uiWdg; 0017 }; 0018 0019 KisMetaDataMergeStrategyChooserWidget::KisMetaDataMergeStrategyChooserWidget(QWidget* parent) 0020 : d(new Private) 0021 { 0022 Q_UNUSED(parent); 0023 setObjectName("KisMetadataMergeStrategyChooserWidget"); 0024 d->uiWdg.setupUi(this); 0025 QList<QString> keys = KisMetaData::MergeStrategyRegistry::instance()->keys(); 0026 Q_FOREACH (const QString & key, keys) { 0027 const KisMetaData::MergeStrategy* ms = KisMetaData::MergeStrategyRegistry::instance()->get(key); 0028 d->uiWdg.mergeStrategy->addItem(ms->name(), ms->id()); 0029 } 0030 int initial = d->uiWdg.mergeStrategy->findData("Smart"); 0031 if (initial != -1) { 0032 d->uiWdg.mergeStrategy->setCurrentIndex(initial); 0033 } 0034 setCurrentDescription(d->uiWdg.mergeStrategy->currentIndex()); 0035 connect(d->uiWdg.mergeStrategy, SIGNAL(currentIndexChanged(int)), SLOT(setCurrentDescription(int))); 0036 } 0037 0038 KisMetaDataMergeStrategyChooserWidget::~KisMetaDataMergeStrategyChooserWidget() 0039 { 0040 delete d; 0041 } 0042 0043 const KisMetaData::MergeStrategy* KisMetaDataMergeStrategyChooserWidget::currentStrategy() 0044 { 0045 return mergeStrategy(d->uiWdg.mergeStrategy->currentIndex()); 0046 } 0047 0048 void KisMetaDataMergeStrategyChooserWidget::setCurrentDescription(int index) 0049 { 0050 d->uiWdg.description->setText(mergeStrategy(index)->description()); 0051 } 0052 0053 const KisMetaData::MergeStrategy* KisMetaDataMergeStrategyChooserWidget::mergeStrategy(int index) 0054 { 0055 return KisMetaData::MergeStrategyRegistry::instance()->get( 0056 d->uiWdg.mergeStrategy->itemData(index).toString()); 0057 } 0058 0059 const KisMetaData::MergeStrategy* KisMetaDataMergeStrategyChooserWidget::showDialog(QWidget* parent) 0060 { 0061 KoDialog dlg(parent); 0062 dlg.setCaption(i18n("Choose meta data merge strategy")); 0063 dlg.setButtons(KoDialog::Ok | KoDialog::Cancel); 0064 dlg.setDefaultButton(KoDialog::Ok); 0065 0066 KisMetaDataMergeStrategyChooserWidget* wdg = new KisMetaDataMergeStrategyChooserWidget(&dlg); 0067 wdg->setMinimumSize(wdg->sizeHint()); 0068 dlg.setMainWidget(wdg); 0069 if (dlg.exec() == QDialog::Accepted) { 0070 return wdg->currentStrategy(); 0071 } 0072 0073 return 0; 0074 } 0075