Commit b2636e9b authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Add method to insert into targetselector

 ... and make that available through the targetsettingswidget,
 too.

Reviewed-by: con
parent 35bcc49b
#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;
......
......@@ -31,6 +31,7 @@ public:
public slots:
void addTarget(const QString &name);
void insertTarget(int index, const QString &name);
void markActive(int index);
void removeTarget(int index);
void setCurrentIndex(int index);
......
......@@ -35,6 +35,12 @@ void TargetSettingsWidget::addTarget(const QString &name)
updateTargetSelector();
}
void TargetSettingsWidget::insertTarget(int index, const QString &name)
{
m_targetSelector->insertTarget(index, name);
updateTargetSelector();
}
void TargetSettingsWidget::markActive(int index)
{
m_targetSelector->markActive(index);
......@@ -43,6 +49,7 @@ void TargetSettingsWidget::markActive(int index)
void TargetSettingsWidget::removeTarget(int index)
{
m_targetSelector->removeTarget(index);
updateTargetSelector();
}
void TargetSettingsWidget::setCurrentIndex(int index)
......
......@@ -30,6 +30,7 @@ public:
public slots:
void addTarget(const QString &name);
void insertTarget(int index, const QString &name);
void markActive(int index);
void removeTarget(int index);
void setCurrentIndex(int index);
......
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