From e1b36719796209bfe47320c493b708d27dab3f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikko=20Syrj=C3=A4?= Date: Tue, 26 Feb 2019 22:33:42 +0200 Subject: Implemented raise and lower. --- symbol.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'symbol.cpp') diff --git a/symbol.cpp b/symbol.cpp index ea24933..32dd7d0 100644 --- a/symbol.cpp +++ b/symbol.cpp @@ -291,3 +291,29 @@ void SymEditSymbol::RotateSymbol(int dir) rotate(item.Value, dir); } } + +//! Raise or lower item. +/*! + \param dir Positive value raises, negative lowers. + \return True for success. +*/ +bool SymEditSymbol::RaiseItem(int dir) +{ + if ( !Items.empty() ) + { + size_t index = static_cast(ActiveIndex); + if ( dir > 0 && index < Items.size() - 1 ) // raise + { + std::swap(Items[index], Items[index + 1]); + ++ActiveIndex; + return true; + } + if ( dir < 0 && index > 0 ) // lower + { + std::swap(Items[index - 1], Items[index]); + --ActiveIndex; + return true; + } + } + return false; +} -- cgit v1.2.3