| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "rs_blocklist.h" |
| |
|
| | #include <QRegularExpression> |
| | #include <iostream> |
| |
|
| | #include "rs_block.h" |
| | #include "rs_blocklistlistener.h" |
| | #include "rs_debug.h" |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | RS_BlockList::RS_BlockList(bool owner) { |
| | m_owner = owner; |
| | |
| | m_activeBlock = nullptr; |
| | setModified(false); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | void RS_BlockList::clear() { |
| | m_blocks.clear(); |
| | m_activeBlock = nullptr; |
| | setModified(true); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | void RS_BlockList::activate(const QString& name) { |
| | RS_DEBUG->print("RS_BlockList::activateBlock"); |
| |
|
| | activate(find(name)); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | void RS_BlockList::activate(RS_Block* block) { |
| | RS_DEBUG->print("RS_BlockList::activateBlock"); |
| | m_activeBlock = block; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RS_BlockList::add(RS_Block* block, bool notify) { |
| | RS_DEBUG->print("RS_BlockList::add()"); |
| |
|
| | if (!block) { |
| | return false; |
| | } |
| |
|
| | |
| | RS_Block* b = find(block->getName()); |
| | if (!b) { |
| | m_blocks.append(block); |
| |
|
| | if (notify) { |
| | addNotification(); |
| | } |
| | setModified(true); |
| |
|
| | return true; |
| | } else { |
| | if (m_owner) { |
| | delete block; |
| | block = nullptr; |
| | } |
| | return false; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void RS_BlockList::addNotification() { |
| | for(auto l: m_blockListListeners){ |
| | l->blockAdded(nullptr); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void RS_BlockList::remove(RS_Block* block) { |
| | RS_DEBUG->print("RS_BlockList::removeBlock()"); |
| |
|
| | |
| | m_blocks.removeOne(block); |
| |
|
| | for(auto l: m_blockListListeners){ |
| | l->blockRemoved(block); |
| | } |
| | |
| | setModified(true); |
| |
|
| | |
| | |
| | if (m_activeBlock==block) { |
| | |
| | m_activeBlock = nullptr; |
| | } |
| | |
| |
|
| | |
| | if (m_owner) { |
| | delete block; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RS_BlockList:: rename(RS_Block* block, const QString& name) { |
| | if (block) { |
| | if (!find(name)) { |
| | QString oldName = block->getName(); |
| | block->setName(name); |
| | setModified(true); |
| |
|
| | |
| | for(RS_Block* b: m_blocks) { |
| | b->renameInserts(oldName, name); |
| | } |
| |
|
| | return true; |
| | } |
| | } |
| |
|
| | return false; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | RS_Block* RS_BlockList::find(const QString& name) { |
| | try { |
| | RS_DEBUG->print(RS_Debug::D_DEBUGGING, "RS_BlockList::find(): %s", name.toLatin1().constData()); |
| | } |
| | catch(...) { |
| | RS_DEBUG->print(RS_Debug::D_DEBUGGING, "RS_BlockList::find(): wrong name to find"); |
| | return nullptr; |
| | } |
| | |
| | |
| | for(RS_Block* b: m_blocks) { |
| | if (b->getName()==name) { |
| | return b; |
| | } |
| | } |
| | RS_DEBUG->print(RS_Debug::D_DEBUGGING, "RS_BlockList::find(): bad"); |
| | return nullptr; |
| | } |
| |
|
| | RS_Block* RS_BlockList::findCaseInsensitive(const QString& name) const { |
| | try { |
| | RS_DEBUG->print(RS_Debug::D_DEBUGGING, "RS_BlockList::find(): %s", name.toLatin1().constData()); |
| | } |
| | catch(...) { |
| | RS_DEBUG->print(RS_Debug::D_DEBUGGING, "RS_BlockList::find(): wrong name to find"); |
| | return nullptr; |
| | } |
| | |
| | |
| | for(RS_Block* b: m_blocks) { |
| | if (b->getName().compare(name, Qt::CaseInsensitive) == 0) { |
| | return b; |
| | } |
| | } |
| | RS_DEBUG->print(RS_Debug::D_DEBUGGING, "RS_BlockList::find(): bad"); |
| | return nullptr; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | QString RS_BlockList::newName(const QString& suggestion) { |
| | |
| | if(!find(suggestion)) |
| | return suggestion; |
| |
|
| | QString name=suggestion; |
| | QRegularExpression const rx(R"(-\d+$)"); |
| | int index=rx.match(name).lastCapturedIndex(); |
| | int i=-1; |
| | if(index>0){ |
| | i=name.mid(index+1).toInt(); |
| | name=name.mid(0, index); |
| | } |
| | for(RS_Block* b: m_blocks){ |
| | index=b->getName().lastIndexOf(rx); |
| | if(index<0) continue; |
| | QString const part1= b->getName().mid(0, index); |
| | if(part1 != name) continue; |
| | i=std::max(b->getName().mid(index+1).toInt(),i); |
| | } |
| | |
| | return QString("%1-%2").arg(name).arg(i+1); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | void RS_BlockList::toggle(const QString& name) { |
| | toggle(find(name)); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | void RS_BlockList::toggle(RS_Block* block) { |
| | if (!block) { |
| | return; |
| | } |
| |
|
| | block->toggle(); |
| | |
| | |
| |
|
| | |
| | for(auto l: m_blockListListeners){ |
| | l->blockToggled(block); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void RS_BlockList::freezeAll(bool freeze) { |
| |
|
| | for (int l=0; l<count(); l++) { |
| | if (at(l)->isVisibleInBlockList()) { |
| | at(l)->freeze(freeze); |
| | } |
| | } |
| | |
| | |
| |
|
| | for(auto l: m_blockListListeners){ |
| | l->blockToggled(nullptr); |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | void RS_BlockList::addListener(RS_BlockListListener* listener) { |
| | for (auto const l: m_blockListListeners) { |
| | if (l == listener) { |
| | return; |
| | } |
| | } |
| | m_blockListListeners.append(listener); |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_BlockList::removeListener(RS_BlockListListener* listener) { |
| | m_blockListListeners.removeOne(listener); |
| | } |
| |
|
| | int RS_BlockList::count() const{ |
| | return m_blocks.count(); |
| | } |
| |
|
| | |
| | |
| | |
| | RS_Block* RS_BlockList::at(int i) { |
| | return m_blocks.at(i); |
| | } |
| | RS_Block* RS_BlockList::at(int i) const{ |
| | return m_blocks.at(i); |
| | } |
| | QList<RS_Block*>::iterator RS_BlockList::begin() |
| | { |
| | return m_blocks.begin(); |
| | } |
| |
|
| | QList<RS_Block*>::iterator RS_BlockList::end() |
| | { |
| | return m_blocks.end(); |
| | } |
| |
|
| | QList<RS_Block*>::const_iterator RS_BlockList::begin()const |
| | { |
| | return m_blocks.begin(); |
| | } |
| |
|
| | QList<RS_Block*>::const_iterator RS_BlockList::end()const |
| | { |
| | return m_blocks.end(); |
| | } |
| |
|
| | |
| | RS_Block* RS_BlockList::getActive() const |
| | { |
| | return m_activeBlock; |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_BlockList::setModified(bool m) { |
| | m_modified = m; |
| |
|
| | |
| | |
| | if (m == false) { |
| | for (auto b: m_blocks) { |
| | b->setModifiedFlag(false); |
| | } |
| | } |
| |
|
| | |
| | for (auto l: m_blockListListeners) { |
| | l->blockListModified(m); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | bool RS_BlockList::isModified() const { |
| | return m_modified; |
| | } |
| |
|
| | |
| | |
| | |
| | std::ostream& operator << (std::ostream& os, RS_BlockList& b) { |
| |
|
| | os << "Blocklist: \n"; |
| | for (int i=0; i<b.count(); ++i) { |
| | RS_Block* blk = b.at(i); |
| |
|
| | os << *blk << "\n"; |
| | } |
| |
|
| | return os; |
| | } |
| |
|