Commit 0bf1c85b authored by hjk's avatar hjk
Browse files

ProjectExplorer: Hide some KitOptionsPage implementation details.



Follows the recently established pattern.

Change-Id: I869da4df9d1d879ebff3ed7c45e8c33f376968a0
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent a6f835de
......@@ -44,120 +44,103 @@
#include <QVBoxLayout>
namespace ProjectExplorer {
namespace Internal {
// --------------------------------------------------------------------------
// KitOptionsPage:
// KitOptionsPageWidget:
// --------------------------------------------------------------------------
KitOptionsPage::KitOptionsPage() :
m_model(0), m_selectionModel(0), m_currentWidget(0), m_toShow(0)
{
setId(Constants::KITS_SETTINGS_PAGE_ID);
setDisplayName(tr("Kits"));
setCategory(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY));
setCategoryIcon(QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON));
}
QWidget *KitOptionsPage::widget()
{
if (!m_configWidget) {
m_configWidget = new QWidget;
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->addStretch();
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->addWidget(m_kitsView);
horizontalLayout->addLayout(buttonLayout);
QVBoxLayout *verticalLayout = new QVBoxLayout(m_configWidget);
verticalLayout->addLayout(horizontalLayout);
m_model = new Internal::KitModel(verticalLayout);
connect(m_model, &Internal::KitModel::kitStateChanged, this, &KitOptionsPage::updateState);
verticalLayout->setStretch(0, 1);
verticalLayout->setStretch(1, 0);
m_kitsView->setModel(m_model);
m_kitsView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
m_kitsView->expandAll();
m_selectionModel = m_kitsView->selectionModel();
connect(m_selectionModel, &QItemSelectionModel::selectionChanged,
this, &KitOptionsPage::kitSelectionChanged);
connect(KitManager::instance(), &KitManager::kitAdded,
this, &KitOptionsPage::kitSelectionChanged);
connect(KitManager::instance(), &KitManager::kitRemoved,
this, &KitOptionsPage::kitSelectionChanged);
connect(KitManager::instance(), &KitManager::kitUpdated,
this, &KitOptionsPage::kitSelectionChanged);
// Set up add menu:
connect(m_addButton, &QAbstractButton::clicked, this, &KitOptionsPage::addNewKit);
connect(m_cloneButton, &QAbstractButton::clicked, this, &KitOptionsPage::cloneKit);
connect(m_delButton, &QAbstractButton::clicked, this, &KitOptionsPage::removeKit);
connect(m_makeDefaultButton, &QAbstractButton::clicked, this, &KitOptionsPage::makeDefaultKit);
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;
}
void KitOptionsPage::apply()
class KitOptionsPageWidget : public QWidget
{
if (m_model)
m_model->apply();
}
void KitOptionsPage::finish()
public:
KitOptionsPageWidget();
QModelIndex currentIndex() const;
Kit *currentKit() const;
void kitSelectionChanged();
void addNewKit();
void cloneKit();
void removeKit();
void makeDefaultKit();
void updateState();
public:
QTreeView *m_kitsView;
QPushButton *m_addButton;
QPushButton *m_cloneButton;
QPushButton *m_delButton;
QPushButton *m_makeDefaultButton;
KitModel *m_model;
QItemSelectionModel *m_selectionModel;
QWidget *m_currentWidget;
};
KitOptionsPageWidget::KitOptionsPageWidget()
: m_model(0), m_selectionModel(0), m_currentWidget(0)
{
if (m_model) {
delete m_model;
m_model = 0;
}
delete m_configWidget;
m_selectionModel = 0; // child of m_configWidget
m_kitsView = 0; // child of m_configWidget
m_currentWidget = 0; // not owned
m_toShow = 0;
}
m_kitsView = new QTreeView(this);
m_kitsView->setUniformRowHeights(true);
m_kitsView->header()->setStretchLastSection(true);
m_kitsView->setSizePolicy(m_kitsView->sizePolicy().horizontalPolicy(),
QSizePolicy::Ignored);
m_addButton = new QPushButton(KitOptionsPage::tr("Add"), this);
m_cloneButton = new QPushButton(KitOptionsPage::tr("Clone"), this);
m_delButton = new QPushButton(KitOptionsPage::tr("Remove"), this);
m_makeDefaultButton = new QPushButton(KitOptionsPage::tr("Make Default"), this);
auto 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->addStretch();
auto horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(m_kitsView);
horizontalLayout->addLayout(buttonLayout);
auto verticalLayout = new QVBoxLayout(this);
verticalLayout->addLayout(horizontalLayout);
m_model = new Internal::KitModel(verticalLayout, this);
connect(m_model, &Internal::KitModel::kitStateChanged,
this, &KitOptionsPageWidget::updateState);
verticalLayout->setStretch(0, 1);
verticalLayout->setStretch(1, 0);
m_kitsView->setModel(m_model);
m_kitsView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
m_kitsView->expandAll();
m_selectionModel = m_kitsView->selectionModel();
connect(m_selectionModel, &QItemSelectionModel::selectionChanged,
this, &KitOptionsPageWidget::kitSelectionChanged);
connect(KitManager::instance(), &KitManager::kitAdded,
this, &KitOptionsPageWidget::kitSelectionChanged);
connect(KitManager::instance(), &KitManager::kitRemoved,
this, &KitOptionsPageWidget::kitSelectionChanged);
connect(KitManager::instance(), &KitManager::kitUpdated,
this, &KitOptionsPageWidget::kitSelectionChanged);
// Set up add menu:
connect(m_addButton, &QAbstractButton::clicked,
this, &KitOptionsPageWidget::addNewKit);
connect(m_cloneButton, &QAbstractButton::clicked,
this, &KitOptionsPageWidget::cloneKit);
connect(m_delButton, &QAbstractButton::clicked,
this, &KitOptionsPageWidget::removeKit);
connect(m_makeDefaultButton, &QAbstractButton::clicked,
this, &KitOptionsPageWidget::makeDefaultKit);
void KitOptionsPage::showKit(Kit *k)
{
m_toShow = k;
updateState();
}
void KitOptionsPage::kitSelectionChanged()
void KitOptionsPageWidget::kitSelectionChanged()
{
QModelIndex current = currentIndex();
QWidget *newWidget = m_model->widget(current);
......@@ -176,7 +159,7 @@ void KitOptionsPage::kitSelectionChanged()
updateState();
}
void KitOptionsPage::addNewKit()
void KitOptionsPageWidget::addNewKit()
{
Kit *k = m_model->markForAddition(0);
......@@ -187,12 +170,12 @@ void KitOptionsPage::addNewKit()
| QItemSelectionModel::Rows);
}
Kit *KitOptionsPage::currentKit() const
Kit *KitOptionsPageWidget::currentKit() const
{
return m_model->kit(currentIndex());
}
void KitOptionsPage::cloneKit()
void KitOptionsPageWidget::cloneKit()
{
Kit *current = currentKit();
if (!current)
......@@ -207,19 +190,19 @@ void KitOptionsPage::cloneKit()
| QItemSelectionModel::Rows);
}
void KitOptionsPage::removeKit()
void KitOptionsPageWidget::removeKit()
{
if (Kit *k = currentKit())
m_model->markForRemoval(k);
}
void KitOptionsPage::makeDefaultKit()
void KitOptionsPageWidget::makeDefaultKit()
{
m_model->setDefaultKit(currentIndex());
updateState();
}
void KitOptionsPage::updateState()
void KitOptionsPageWidget::updateState()
{
if (!m_kitsView)
return;
......@@ -239,7 +222,7 @@ void KitOptionsPage::updateState()
m_makeDefaultButton->setEnabled(canMakeDefault);
}
QModelIndex KitOptionsPage::currentIndex() const
QModelIndex KitOptionsPageWidget::currentIndex() const
{
if (!m_selectionModel)
return QModelIndex();
......@@ -250,4 +233,56 @@ QModelIndex KitOptionsPage::currentIndex() const
return idxs.at(0);
}
} // namespace Internal
// --------------------------------------------------------------------------
// KitOptionsPage:
// --------------------------------------------------------------------------
KitOptionsPage::KitOptionsPage()
{
setId(Constants::KITS_SETTINGS_PAGE_ID);
setDisplayName(tr("Kits"));
setCategory(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY));
setCategoryIcon(QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON));
}
QWidget *KitOptionsPage::widget()
{
if (!m_widget)
m_widget = new Internal::KitOptionsPageWidget;
return m_widget;
}
void KitOptionsPage::apply()
{
if (m_widget)
m_widget->m_model->apply();
}
void KitOptionsPage::finish()
{
if (m_widget) {
delete m_widget;
m_widget = 0;
}
}
void KitOptionsPage::showKit(Kit *k)
{
if (!k)
return;
(void) widget();
QModelIndex index = m_widget->m_model->indexOf(k);
m_widget->m_selectionModel->select(index,
QItemSelectionModel::Clear
| QItemSelectionModel::SelectCurrent
| QItemSelectionModel::Rows);
m_widget->m_kitsView->scrollTo(index);
}
} // namespace ProjectExplorer
......@@ -35,18 +35,11 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <QModelIndex>
#include <QPointer>
QT_BEGIN_NAMESPACE
class QItemSelectionModel;
class QTreeView;
class QPushButton;
QT_END_NAMESPACE
namespace ProjectExplorer {
namespace Internal { class KitModel; }
namespace Internal { class KitOptionsPageWidget; }
class Kit;
......@@ -66,31 +59,9 @@ public:
void finish();
void showKit(Kit *k);
private slots:
void kitSelectionChanged();
void addNewKit();
void cloneKit();
void removeKit();
void makeDefaultKit();
void updateState();
private:
QModelIndex currentIndex() const;
Kit *currentKit() const;
QTreeView *m_kitsView;
QPushButton *m_addButton;
QPushButton *m_cloneButton;
QPushButton *m_delButton;
QPushButton *m_makeDefaultButton;
QPointer<QWidget> m_configWidget;
Internal::KitModel *m_model;
QItemSelectionModel *m_selectionModel;
QWidget *m_currentWidget;
Kit *m_toShow;
QPointer<Internal::KitOptionsPageWidget> m_widget;
};
} // namespace ProjectExplorer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment