File indexing completed on 2024-04-28 04:37:18
0001 /* 0002 SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_LAUNCHCONFIGURATIONDIALOG_H 0008 #define KDEVPLATFORM_LAUNCHCONFIGURATIONDIALOG_H 0009 0010 #include <QAbstractItemModel> 0011 #include <QDialog> 0012 #include <QList> 0013 #include <QMap> 0014 #include <QStyledItemDelegate> 0015 0016 #include "ui_launchconfigurationdialog.h" 0017 0018 class QItemSelection; 0019 0020 namespace Ui 0021 { 0022 class LaunchConfigTypePage; 0023 } 0024 0025 namespace KDevelop 0026 { 0027 class ILauncher; 0028 class LaunchConfigurationPageFactory; 0029 class ILaunchMode; 0030 0031 class LaunchConfigurationType; 0032 class LaunchConfiguration; 0033 class LaunchConfigurationPage; 0034 class ILaunchConfiguration; 0035 class IProject; 0036 0037 class LaunchConfigurationModelDelegate : public QStyledItemDelegate 0038 { 0039 Q_OBJECT 0040 public: 0041 using QStyledItemDelegate::QStyledItemDelegate; 0042 0043 QWidget* createEditor ( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; 0044 void setEditorData ( QWidget* editor, const QModelIndex& index ) const override; 0045 void setModelData ( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const override; 0046 }; 0047 0048 0049 class LaunchConfigurationsModel : public QAbstractItemModel 0050 { 0051 Q_OBJECT 0052 public: 0053 explicit LaunchConfigurationsModel(QObject* parent = nullptr); 0054 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0055 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0056 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 0057 QModelIndex parent(const QModelIndex& child) const override; 0058 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0059 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0060 Qt::ItemFlags flags(const QModelIndex& index) const override; 0061 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 0062 void createConfiguration( const QModelIndex& ); 0063 void deleteConfiguration( const QModelIndex& index ); 0064 LaunchConfiguration* configForIndex( const QModelIndex& ) const; 0065 ILaunchMode* modeForIndex( const QModelIndex& idx ) const; 0066 QModelIndex indexForConfig( LaunchConfiguration* ) const; 0067 void addConfiguration(KDevelop::ILaunchConfiguration* launch, const QModelIndex& idx); 0068 KDevelop::IProject* projectForIndex(const QModelIndex& idx); 0069 0070 private: 0071 class TreeItem 0072 { 0073 public: 0074 TreeItem() {} 0075 virtual ~TreeItem() {} 0076 TreeItem* parent = nullptr; 0077 int row; 0078 QList<TreeItem*> children; 0079 }; 0080 class ProjectItem : public TreeItem 0081 { 0082 public: 0083 IProject* project; 0084 }; 0085 class LaunchItem : public TreeItem 0086 { 0087 public: 0088 LaunchConfiguration* launch; 0089 }; 0090 class LaunchModeItem : public TreeItem 0091 { 0092 public: 0093 ILaunchMode* mode; 0094 }; 0095 class GenericPageItem : public TreeItem 0096 { 0097 public: 0098 QString text; 0099 }; 0100 void addItemForLaunchConfig( LaunchConfiguration* l ); 0101 void addLaunchModeItemsForLaunchConfig ( KDevelop::LaunchConfigurationsModel::LaunchItem* l ); 0102 QList<TreeItem*> topItems; 0103 0104 public: 0105 ProjectItem* findItemForProject(IProject* p) const; 0106 }; 0107 0108 class LaunchConfigPagesContainer : public QWidget 0109 { 0110 Q_OBJECT 0111 public: 0112 explicit LaunchConfigPagesContainer( const QList<LaunchConfigurationPageFactory*> &, QWidget* parent = nullptr ); 0113 void setLaunchConfiguration( LaunchConfiguration* ); 0114 void save(); 0115 Q_SIGNALS: 0116 void changed(); 0117 private: 0118 LaunchConfiguration* config; 0119 QList<LaunchConfigurationPage*> pages; 0120 }; 0121 0122 class LaunchConfigurationDialog : public QDialog, public Ui::LaunchConfigurationDialog 0123 { 0124 Q_OBJECT 0125 public: 0126 explicit LaunchConfigurationDialog(QWidget* parent = nullptr ); 0127 QSize sizeHint() const override; 0128 0129 private Q_SLOTS: 0130 void deleteConfiguration(); 0131 void createConfiguration(); 0132 void addConfiguration(KDevelop::ILaunchConfiguration*); 0133 void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); 0134 void modelChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); 0135 void pageChanged(); 0136 void saveConfig(); 0137 void updateNameLabel( LaunchConfiguration* l ); 0138 void createEmptyLauncher(); 0139 void launchModeChanged(int index); 0140 void doTreeContextMenu(const QPoint& point); 0141 void renameSelected(); 0142 0143 private: 0144 void saveConfig( const QModelIndex& ); 0145 LaunchConfigurationsModel* model; 0146 QMap<LaunchConfigurationType*, LaunchConfigPagesContainer*> typeWidgets; 0147 QMap<ILauncher*, LaunchConfigPagesContainer*> launcherWidgets; 0148 bool currentPageChanged = false; 0149 }; 0150 0151 } 0152 0153 #endif 0154