1 /* 2 SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef KDEVPLATFORM_LAUNCHCONFIGURATIONDIALOG_H 8 #define KDEVPLATFORM_LAUNCHCONFIGURATIONDIALOG_H 9 10 #include <QAbstractItemModel> 11 #include <QDialog> 12 #include <QList> 13 #include <QMap> 14 #include <QStyledItemDelegate> 15 16 #include "ui_launchconfigurationdialog.h" 17 18 class QItemSelection; 19 20 namespace Ui 21 { 22 class LaunchConfigTypePage; 23 } 24 25 namespace KDevelop 26 { 27 class ILauncher; 28 class LaunchConfigurationPageFactory; 29 class ILaunchMode; 30 31 class LaunchConfigurationType; 32 class LaunchConfiguration; 33 class LaunchConfigurationPage; 34 class ILaunchConfiguration; 35 class IProject; 36 37 class LaunchConfigurationModelDelegate : public QStyledItemDelegate 38 { 39 Q_OBJECT 40 public: 41 using QStyledItemDelegate::QStyledItemDelegate; 42 43 QWidget* createEditor ( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; 44 void setEditorData ( QWidget* editor, const QModelIndex& index ) const override; 45 void setModelData ( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const override; 46 }; 47 48 49 class LaunchConfigurationsModel : public QAbstractItemModel 50 { 51 Q_OBJECT 52 public: 53 explicit LaunchConfigurationsModel(QObject* parent = nullptr); 54 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 55 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 56 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 57 QModelIndex parent(const QModelIndex& child) const override; 58 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 59 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 60 Qt::ItemFlags flags(const QModelIndex& index) const override; 61 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 62 void createConfiguration( const QModelIndex& ); 63 void deleteConfiguration( const QModelIndex& index ); 64 LaunchConfiguration* configForIndex( const QModelIndex& ) const; 65 ILaunchMode* modeForIndex( const QModelIndex& idx ) const; 66 QModelIndex indexForConfig( LaunchConfiguration* ) const; 67 void addConfiguration(KDevelop::ILaunchConfiguration* launch, const QModelIndex& idx); 68 KDevelop::IProject* projectForIndex(const QModelIndex& idx); 69 70 private: 71 class TreeItem 72 { 73 public: TreeItem()74 TreeItem() {} ~TreeItem()75 virtual ~TreeItem() {} 76 TreeItem* parent = nullptr; 77 int row; 78 QList<TreeItem*> children; 79 }; 80 class ProjectItem : public TreeItem 81 { 82 public: 83 IProject* project; 84 }; 85 class LaunchItem : public TreeItem 86 { 87 public: 88 LaunchConfiguration* launch; 89 }; 90 class LaunchModeItem : public TreeItem 91 { 92 public: 93 ILaunchMode* mode; 94 }; 95 class GenericPageItem : public TreeItem 96 { 97 public: 98 QString text; 99 }; 100 void addItemForLaunchConfig( LaunchConfiguration* l ); 101 void addLaunchModeItemsForLaunchConfig ( KDevelop::LaunchConfigurationsModel::LaunchItem* l ); 102 QList<TreeItem*> topItems; 103 104 public: 105 ProjectItem* findItemForProject(IProject* p) const; 106 }; 107 108 class LaunchConfigPagesContainer : public QWidget 109 { 110 Q_OBJECT 111 public: 112 explicit LaunchConfigPagesContainer( const QList<LaunchConfigurationPageFactory*> &, QWidget* parent = nullptr ); 113 void setLaunchConfiguration( LaunchConfiguration* ); 114 void save(); 115 Q_SIGNALS: 116 void changed(); 117 private: 118 LaunchConfiguration* config; 119 QList<LaunchConfigurationPage*> pages; 120 }; 121 122 class LaunchConfigurationDialog : public QDialog, public Ui::LaunchConfigurationDialog 123 { 124 Q_OBJECT 125 public: 126 explicit LaunchConfigurationDialog(QWidget* parent = nullptr ); 127 QSize sizeHint() const override; 128 129 private Q_SLOTS: 130 void deleteConfiguration(); 131 void createConfiguration(); 132 void addConfiguration(KDevelop::ILaunchConfiguration*); 133 void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); 134 void modelChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); 135 void pageChanged(); 136 void saveConfig(); 137 void updateNameLabel( LaunchConfiguration* l ); 138 void createEmptyLauncher(); 139 void launchModeChanged(int index); 140 void doTreeContextMenu(const QPoint& point); 141 void renameSelected(); 142 143 private: 144 void saveConfig( const QModelIndex& ); 145 LaunchConfigurationsModel* model; 146 QMap<LaunchConfigurationType*, LaunchConfigPagesContainer*> typeWidgets; 147 QMap<ILauncher*, LaunchConfigPagesContainer*> launcherWidgets; 148 bool currentPageChanged = false; 149 }; 150 151 } 152 153 #endif 154 155