Example #1
0
void TargetSetupPage::setKitSelected(Core::Id id, bool selected)
{
    TargetSetupWidget *widget = m_widgets.value(id);
    if (widget) {
        widget->setKitSelected(selected);
        kitSelectionChanged();
    }
}
QWidget *KitOptionsPage::createPage(QWidget *parent)
{
    m_configWidget = new QWidget(parent);

    m_kitsView = new QTreeView(m_configWidget);
    m_kitsView->setUniformRowHeights(true);
    m_kitsView->header()->setStretchLastSection(true);
    m_kitsView->setSizePolicy(m_kitsView->sizePolicy().horizontalPolicy(),
                                  QSizePolicy::Ignored);

    m_addButton = new QPushButton(tr("Add"), m_configWidget);
    m_cloneButton = new QPushButton(tr("Clone"), m_configWidget);
    m_delButton = new QPushButton(tr("Remove"), m_configWidget);
    m_makeDefaultButton = new QPushButton(tr("Make Default"), m_configWidget);

    QVBoxLayout *buttonLayout = new QVBoxLayout();
    buttonLayout->setSpacing(6);
    buttonLayout->setContentsMargins(0, 0, 0, 0);
    buttonLayout->addWidget(m_addButton);
    buttonLayout->addWidget(m_cloneButton);
    buttonLayout->addWidget(m_delButton);
    buttonLayout->addWidget(m_makeDefaultButton);
    buttonLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));

    QHBoxLayout *horizontalLayout = new QHBoxLayout();
    horizontalLayout->addWidget(m_kitsView);
    horizontalLayout->addLayout(buttonLayout);

    QVBoxLayout *verticalLayout = new QVBoxLayout(m_configWidget);
    verticalLayout->addLayout(horizontalLayout);

    Q_ASSERT(!m_model);
    m_model = new Internal::KitModel(verticalLayout);
    connect(m_model, SIGNAL(kitStateChanged()), this, SLOT(updateState()));

    m_kitsView->setModel(m_model);
    m_kitsView->header()->setResizeMode(0, QHeaderView::Stretch);
    m_kitsView->expandAll();

    m_selectionModel = m_kitsView->selectionModel();
    connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(kitSelectionChanged()));
    connect(KitManager::instance(), SIGNAL(kitAdded(ProjectExplorer::Kit*)),
            this, SLOT(kitSelectionChanged()));
    connect(KitManager::instance(), SIGNAL(kitRemoved(ProjectExplorer::Kit*)),
            this, SLOT(kitSelectionChanged()));
    connect(KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
            this, SLOT(kitSelectionChanged()));

    // Set up add menu:
    connect(m_addButton, SIGNAL(clicked()), this, SLOT(addNewKit()));
    connect(m_cloneButton, SIGNAL(clicked()), this, SLOT(cloneKit()));
    connect(m_delButton, SIGNAL(clicked()), this, SLOT(removeKit()));
    connect(m_makeDefaultButton, SIGNAL(clicked()), this, SLOT(makeDefaultKit()));

    m_searchKeywords = tr("Kits");

    updateState();

    if (m_toShow) {
        QModelIndex index = m_model->indexOf(m_toShow);
        m_selectionModel->select(index,
                                 QItemSelectionModel::Clear
                                 | QItemSelectionModel::SelectCurrent
                                 | QItemSelectionModel::Rows);
        m_kitsView->scrollTo(index);
    }
    m_toShow = 0;

    return m_configWidget;
}