diff options
author | Tobias Hunger <tobias.hunger@nokia.com> | 2010-02-22 14:41:34 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@nokia.com> | 2010-02-22 18:07:20 +0100 |
commit | b2636e9b85ad72280c593ae2f847b83a7d21aee0 (patch) | |
tree | 6728ddebb3ddfcb4b69fd4514145ba7ce20ebf5c /src/plugins/projectexplorer/targetselector.cpp | |
parent | 35bcc49bdfd40e058b53e18f14de455d3709dcae (diff) | |
download | qt-creator-b2636e9b85ad72280c593ae2f847b83a7d21aee0.tar.gz |
Add method to insert into targetselector
... and make that available through the targetsettingswidget,
too.
Reviewed-by: con
Diffstat (limited to 'src/plugins/projectexplorer/targetselector.cpp')
-rw-r--r-- | src/plugins/projectexplorer/targetselector.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/plugins/projectexplorer/targetselector.cpp b/src/plugins/projectexplorer/targetselector.cpp index 8650bf6f96..63d82fe344 100644 --- a/src/plugins/projectexplorer/targetselector.cpp +++ b/src/plugins/projectexplorer/targetselector.cpp @@ -1,5 +1,7 @@ #include "targetselector.h" +#include <utils/qtcassert.h> + #include <QtGui/QPainter> #include <QtGui/QMouseEvent> #include <QtGui/QFontMetrics> @@ -29,20 +31,29 @@ TargetSelector::TargetSelector(QWidget *parent) : void TargetSelector::addTarget(const QString &name) { + insertTarget(m_targets.count(), name); +} + +void TargetSelector::insertTarget(int index, const QString &name) +{ + QTC_ASSERT(index >= 0 && index <= m_targets.count(), return); + Target target; target.name = name; target.currentSubIndex = 0; target.isActive = false; - m_targets.append(target); + + m_targets.insert(index, target); + if (m_currentTargetIndex == -1) - setCurrentIndex(m_targets.size() - 1); + setCurrentIndex(index); update(); } void TargetSelector::markActive(int index) { - if (index < 0 || index >= m_targets.count()) - return; + QTC_ASSERT(index >= 0 && index < m_targets.count(), return); + for (int i = 0; i < m_targets.count(); ++i) m_targets[i].isActive = (i == index); update(); @@ -50,9 +61,13 @@ void TargetSelector::markActive(int index) void TargetSelector::removeTarget(int index) { + QTC_ASSERT(index >= 0 && index < m_targets.count(), return); + m_targets.removeAt(index); - if (m_currentTargetIndex == index) - setCurrentIndex(m_targets.size() - 1); + if (m_currentTargetIndex > index) + setCurrentIndex(m_currentTargetIndex - 1); + if (m_currentTargetIndex == m_targets.count()) + setCurrentIndex(m_currentTargetIndex - 1); update(); } @@ -63,6 +78,9 @@ void TargetSelector::setCurrentIndex(int index) index == m_currentTargetIndex) return; + if (index == -1 && !m_targets.isEmpty()) + return; + m_currentTargetIndex = index; update(); @@ -84,6 +102,7 @@ void TargetSelector::setCurrentSubIndex(int subindex) { if (subindex < 0 || subindex >= 2 || + m_currentTargetIndex < 0 || subindex == m_targets.at(m_currentTargetIndex).currentSubIndex) return; m_targets[m_currentTargetIndex].currentSubIndex = subindex; |