NewDialog: Simplfy code for templates view's signals

We don't need to connect to the clicked signal, since we are already
connected to the current changed of the selection model. Also set the
model for the templates view in the constructor, so that we can also
connect to the selection model in the constructor.

Change-Id: I88cd1bef97136604125fc74e18ffcc5c1c118a1d
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Daniel Teske
2014-04-07 12:16:48 +02:00
committed by Thomas Hartmann
parent 18e585b7a7
commit 6822c47c01

View File

@@ -206,16 +206,17 @@ NewDialog::NewDialog(QWidget *parent) :
m_ui->templateCategoryView->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_ui->templateCategoryView->setItemDelegate(new FancyTopLevelDelegate);
m_ui->templatesView->setModel(m_filterProxyModel);
m_ui->templatesView->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
connect(m_ui->templateCategoryView, SIGNAL(clicked(QModelIndex)),
this, SLOT(currentCategoryChanged(QModelIndex)));
connect(m_ui->templatesView, SIGNAL(clicked(QModelIndex)),
this, SLOT(currentItemChanged(QModelIndex)));
connect(m_ui->templateCategoryView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(currentCategoryChanged(QModelIndex)));
connect(m_ui->templatesView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(currentItemChanged(QModelIndex)));
connect(m_ui->templatesView,
SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(okButtonClicked()));
@@ -387,16 +388,11 @@ void NewDialog::addItem(QStandardItem *topLEvelCategoryItem, IWizard *wizard)
void NewDialog::currentCategoryChanged(const QModelIndex &index)
{
if (index.parent() != m_model->invisibleRootItem()->index()) {
m_ui->templatesView->setModel(m_filterProxyModel);
QModelIndex sourceIndex = m_twoLevelProxyModel->mapToSource(index);
sourceIndex = m_filterProxyModel->mapFromSource(sourceIndex);
m_ui->templatesView->setRootIndex(sourceIndex);
// Focus the first item by default
m_ui->templatesView->setCurrentIndex(m_ui->templatesView->rootIndex().child(0,0));
connect(m_ui->templatesView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(currentItemChanged(QModelIndex)));
}
}