File indexing completed on 2025-01-05 05:14:48

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QComboBox>
0010 #include <QDialog>
0011 #include <QMetaEnum>
0012 
0013 #include "libkommitwidgets_export.h"
0014 
0015 namespace Git
0016 {
0017 class Manager;
0018 }
0019 
0020 class LIBKOMMITWIDGETS_EXPORT AppDialog : public QDialog
0021 {
0022     Q_OBJECT
0023 public:
0024     explicit AppDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0025     explicit AppDialog(Git::Manager *git, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0026 
0027     bool event(QEvent *event) override;
0028 
0029 protected:
0030     Git::Manager *mGit = nullptr;
0031 
0032     template<typename _Enum>
0033     void initComboBox(QComboBox *comboBox)
0034     {
0035         comboBox->clear();
0036         QMetaEnum e = QMetaEnum::fromType<_Enum>();
0037         for (auto i = 0; i < e.keyCount(); i++) {
0038             const QString name = e.key(i);
0039             comboBox->addItem(name, e.value(i));
0040         }
0041     }
0042 
0043     template<typename _Enum>
0044     _Enum comboBoxCurrentValue(QComboBox *comboBox) const
0045     {
0046         return static_cast<_Enum>(comboBox->currentData().toInt());
0047     }
0048 
0049     template<typename _Enum>
0050     void setComboboxValue(QComboBox *comboBox, _Enum value)
0051     {
0052         for (int i = 0; i < comboBox->count(); i++)
0053             if (comboBox->itemData(i).toInt() == static_cast<int>(value)) {
0054                 comboBox->setCurrentIndex(i);
0055                 return;
0056             }
0057     }
0058 };