Commit 37ec59f9 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Fix crash when deleting targets

 * Update signal names to be more in sync with those found on the QTabBar

Reviewed-by: con
parent 07d02560
......@@ -49,6 +49,8 @@ void TargetSelector::insertTarget(int index, const QString &name)
if (m_currentTargetIndex == -1)
setCurrentIndex(index);
else if (m_currentTargetIndex >= index)
setCurrentIndex(m_currentTargetIndex + 1);
update();
}
......@@ -66,10 +68,13 @@ void TargetSelector::removeTarget(int index)
QTC_ASSERT(index >= 0 && index < m_targets.count(), return);
m_targets.removeAt(index);
if (m_currentTargetIndex > index)
setCurrentIndex(m_currentTargetIndex - 1);
if (m_currentTargetIndex == m_targets.count())
setCurrentIndex(m_currentTargetIndex - 1);
if (m_currentTargetIndex >= m_targets.count())
setCurrentIndex(m_targets.count() - 1);
else if (m_currentTargetIndex >= index)
// force a signal since the target pointed to has changed:
emit currentChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex);
update();
}
......@@ -86,7 +91,7 @@ void TargetSelector::setCurrentIndex(int index)
m_currentTargetIndex = index;
update();
emit currentIndexChanged(m_currentTargetIndex,
emit currentChanged(m_currentTargetIndex,
m_currentTargetIndex >= 0 ? m_targets.at(m_currentTargetIndex).currentSubIndex : -1);
}
......@@ -110,7 +115,7 @@ void TargetSelector::setCurrentSubIndex(int subindex)
m_targets[m_currentTargetIndex].currentSubIndex = subindex;
update();
emit currentIndexChanged(m_currentTargetIndex,
emit currentChanged(m_currentTargetIndex,
m_targets.at(m_currentTargetIndex).currentSubIndex);
}
......@@ -169,7 +174,7 @@ void TargetSelector::mousePressEvent(QMouseEvent *event)
m_currentTargetIndex = index;
//TODO don't emit if nothing changed!
update();
emit currentIndexChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex);
emit currentChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex);
} else {
event->ignore();
}
......
......@@ -42,7 +42,9 @@ public slots:
signals:
void addButtonClicked();
void removeButtonClicked();
void currentIndexChanged(int targetIndex, int subIndex);
// This signal is emited whenever the target pointed to by the indices
// has changed.
void currentChanged(int targetIndex, int subIndex);
protected:
void paintEvent(QPaintEvent *event);
......
......@@ -118,7 +118,7 @@ QIcon TargetSettingsPanel::icon() const
///
TargetSettingsPanelWidget::TargetSettingsPanelWidget(Project *project) :
m_currentIndex(-1),
m_currentTarget(0),
m_project(project),
m_selector(0),
m_centralWidget(0)
......@@ -171,34 +171,34 @@ void TargetSettingsPanelWidget::setupUi()
noTargetLayout->addStretch(10);
m_centralWidget->addWidget(m_noTargetLabel);
connect(m_selector, SIGNAL(currentChanged(int,int)),
this, SLOT(currentTargetChanged(int,int)));
foreach (Target *t, m_project->targets())
targetAdded(t);
m_selector->markActive(m_targets.indexOf(m_project->activeTarget()));
connect(m_selector, SIGNAL(currentIndexChanged(int,int)),
this, SLOT(currentTargetIndexChanged(int,int)));
connect(m_selector, SIGNAL(addButtonClicked()),
this, SLOT(addTarget()));
connect(m_selector, SIGNAL(removeButtonClicked()),
this, SLOT(removeTarget()));
if (m_project->targets().count())
currentTargetIndexChanged(m_targets.indexOf(m_project->activeTarget()), 0);
if (m_project->activeTarget()) {
m_selector->markActive(m_targets.indexOf(m_project->activeTarget()));
m_selector->setCurrentIndex(m_targets.indexOf(m_project->activeTarget()));
}
}
void TargetSettingsPanelWidget::currentTargetIndexChanged(int targetIndex, int subIndex)
void TargetSettingsPanelWidget::currentTargetChanged(int targetIndex, int subIndex)
{
if (targetIndex < -1 || targetIndex >= m_targets.count())
return;
if (subIndex < -1 || subIndex >= 2)
return;
m_selector->setCurrentIndex(targetIndex);
m_selector->setCurrentSubIndex(subIndex);
Target *target(m_targets.at(targetIndex));
// Target was not actually changed:
if (m_currentIndex == targetIndex) {
if (m_currentTarget == target) {
if (m_panelWidgets[subIndex])
m_centralWidget->setCurrentWidget(m_panelWidgets[subIndex]);
else
......@@ -206,7 +206,7 @@ void TargetSettingsPanelWidget::currentTargetIndexChanged(int targetIndex, int s
return;
}
m_currentIndex = targetIndex;
m_currentTarget = target;
// Target has changed:
if (targetIndex == -1) { // no more targets!
......
......@@ -83,7 +83,7 @@ public:
void setupUi();
private slots:
void currentTargetIndexChanged(int targetIndex, int subIndex);
void currentTargetChanged(int targetIndex, int subIndex);
void addTarget();
void removeTarget();
void targetAdded(ProjectExplorer::Target *target);
......@@ -91,7 +91,7 @@ private slots:
void activeTargetChanged(ProjectExplorer::Target *target);
private:
int m_currentIndex;
Target *m_currentTarget;
Project *m_project;
TargetSettingsWidget *m_selector;
QStackedWidget *m_centralWidget;
......
......@@ -19,8 +19,8 @@ TargetSettingsWidget::TargetSettingsWidget(QWidget *parent) :
this, SIGNAL(addButtonClicked()));
connect(m_targetSelector, SIGNAL(removeButtonClicked()),
this, SIGNAL(removeButtonClicked()));
connect(m_targetSelector, SIGNAL(currentIndexChanged(int,int)),
this, SIGNAL(currentIndexChanged(int,int)));
connect(m_targetSelector, SIGNAL(currentChanged(int,int)),
this, SIGNAL(currentChanged(int,int)));
updateTargetSelector();
}
......
......@@ -41,7 +41,7 @@ public slots:
signals:
void addButtonClicked();
void removeButtonClicked();
void currentIndexChanged(int targetIndex, int subIndex);
void currentChanged(int targetIndex, int subIndex);
protected:
void changeEvent(QEvent *e);
......
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