TODO: Maybe use KPageDialog instead, might make the model stuff easier and the default-size stuff as well
| 42 | |
| 43 | //TODO: Maybe use KPageDialog instead, might make the model stuff easier and the default-size stuff as well |
| 44 | LaunchConfigurationDialog::LaunchConfigurationDialog(QWidget* parent) |
| 45 | : QDialog(parent) |
| 46 | { |
| 47 | setWindowTitle( i18nc("@title:window", "Launch Configurations" ) ); |
| 48 | |
| 49 | auto* mainWidget = new QWidget(this); |
| 50 | auto *mainLayout = new QVBoxLayout(this); |
| 51 | mainLayout->addWidget(mainWidget); |
| 52 | |
| 53 | setupUi(mainWidget); |
| 54 | splitter->setSizes(QList<int>{260, 620}); |
| 55 | splitter->setCollapsible(0, false); |
| 56 | |
| 57 | addConfig->setToolTip(i18nc("@info:tooltip", "Add a new launch configuration.")); |
| 58 | deleteConfig->setEnabled( false ); |
| 59 | deleteConfig->setToolTip(i18nc("@info:tooltip", "Delete selected launch configuration.")); |
| 60 | |
| 61 | model = new LaunchConfigurationsModel( tree ); |
| 62 | tree->setModel( model ); |
| 63 | tree->setExpandsOnDoubleClick( true ); |
| 64 | tree->setSelectionBehavior( QAbstractItemView::SelectRows ); |
| 65 | tree->setSelectionMode( QAbstractItemView::SingleSelection ); |
| 66 | tree->setUniformRowHeights( true ); |
| 67 | tree->setItemDelegate( new LaunchConfigurationModelDelegate(this) ); |
| 68 | tree->setColumnHidden(1, true); |
| 69 | for(int row=0; row<model->rowCount(); row++) { |
| 70 | tree->setExpanded(model->index(row, 0), true); |
| 71 | } |
| 72 | |
| 73 | tree->setContextMenuPolicy(Qt::CustomContextMenu); |
| 74 | connect( tree, &QTreeView::customContextMenuRequested, this, &LaunchConfigurationDialog::doTreeContextMenu ); |
| 75 | connect( deleteConfig, &QPushButton::clicked, this, &LaunchConfigurationDialog::deleteConfiguration); |
| 76 | connect( model, &LaunchConfigurationsModel::dataChanged, this, &LaunchConfigurationDialog::modelChanged ); |
| 77 | connect( tree->selectionModel(), &QItemSelectionModel::selectionChanged, this, &LaunchConfigurationDialog::selectionChanged); |
| 78 | QModelIndex idx = model->indexForConfig( Core::self()->runControllerInternal()->defaultLaunch() ); |
| 79 | qCDebug(SHELL) << "selecting index:" << idx; |
| 80 | if( !idx.isValid() ) |
| 81 | { |
| 82 | for( int i = 0; i < model->rowCount(); i++ ) |
| 83 | { |
| 84 | if( model->rowCount( model->index( i, 0, QModelIndex() ) ) > 0 ) |
| 85 | { |
| 86 | idx = model->index( 1, 0, model->index( i, 0, QModelIndex() ) ); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | if( !idx.isValid() ) |
| 91 | { |
| 92 | idx = model->index( 0, 0, QModelIndex() ); |
| 93 | } |
| 94 | } |
| 95 | tree->selectionModel()->select( QItemSelection( idx, idx ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); |
| 96 | tree->selectionModel()->setCurrentIndex( idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); |
| 97 | |
| 98 | // Unfortunately tree->resizeColumnToContents() only looks at the top-level |
| 99 | // items, instead of all open ones. Hence we're calculating it ourselves like |
| 100 | // this: |
| 101 | // Take the selected index, check if it has childs, if so take the first child |
nothing calls this directly
no test coverage detected