--- qsampler/trunk/src/qsamplerInstrumentList.cpp 2010/03/13 12:44:15 2065 +++ qsampler/trunk/src/qsamplerInstrumentList.cpp 2012/12/29 00:21:11 2387 @@ -1,7 +1,7 @@ // qsamplerInstrumentList.cpp // /**************************************************************************** - Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2003-2012, rncbc aka Rui Nuno Capela. All rights reserved. Copyright (C) 2007, Christian Schoenebeck This program is free software; you can redistribute it and/or @@ -29,6 +29,7 @@ #include "qsamplerMainForm.h" #include +#include #include @@ -41,7 +42,7 @@ InstrumentListModel::InstrumentListModel ( QObject *pParent ) : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL) { - QAbstractItemModel::reset(); +// QAbstractItemModel::reset(); } InstrumentListModel::~InstrumentListModel (void) @@ -79,7 +80,6 @@ { if (!index.isValid()) return QVariant(); - const Instrument *pInstr = static_cast (index.internalPointer()); @@ -130,7 +130,6 @@ InstrumentMap::const_iterator itMap = m_instruments.find(m_iMidiMap); if (itMap != m_instruments.constEnd()) { const InstrumentList& list = *itMap; - // resolve instrument in that map if (row < list.size()) pInstr = list.at(row); } @@ -192,7 +191,9 @@ // with the very same key (bank, program); // if yes, just remove it without prejudice... InstrumentList& list = m_instruments[iMap]; - for (int i = 0; i < list.size(); ++i) { + + int i = 0; + for ( ; i < list.size(); ++i) { const Instrument *pInstr = list.at(i); if (pInstr->bank() == iBank && pInstr->prog() == iProg) { delete pInstr; @@ -202,8 +203,7 @@ } // Resolve the appropriate place, we keep the list sorted that way... - int i = 0; - for ( ; i < list.size(); ++i) { + for (i = 0; i < list.size(); ++i) { const Instrument *pInstr = list.at(i); if (iBank < pInstr->bank() || (iBank == pInstr->bank() && iProg < pInstr->prog())) { @@ -223,18 +223,15 @@ } -void InstrumentListModel::removeInstrument ( const Instrument *pInstrument ) +void InstrumentListModel::removeInstrument ( Instrument *pInstrument ) { - const int iMap = pInstrument->map(); - const int iBank = pInstrument->bank(); - const int iProg = pInstrument->prog(); + const int iMap = pInstrument->map(); if (m_instruments.contains(iMap)) { InstrumentList& list = m_instruments[iMap]; for (int i = 0; i < list.size(); ++i) { - const Instrument *pInstr = list.at(i); - if (pInstr->bank() == iBank && pInstr->prog() == iProg) { - delete pInstr; + if (pInstrument == list.at(i)) { + delete pInstrument; list.removeAt(i); break; } @@ -243,8 +240,14 @@ } +void InstrumentListModel::updateInstrument ( Instrument *pInstrument ) +{ + pInstrument->getInstrument(); +} + + // Reposition the instrument in the model (called when map/bank/prg changed) -void InstrumentListModel::updateInstrument ( const Instrument *pInstrument ) +void InstrumentListModel::resortInstrument ( Instrument *pInstrument ) { const int iMap = pInstrument->map(); const int iBank = pInstrument->bank(); @@ -339,10 +342,13 @@ QTreeView::setAlternatingRowColors(true); QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows); QTreeView::setSelectionMode(QAbstractItemView::SingleSelection); - + QTreeView::setItemsExpandable(false); + QHeaderView *pHeader = QTreeView::header(); pHeader->setDefaultAlignment(Qt::AlignLeft); +#if QT_VERSION < 0x050000 pHeader->setMovable(false); +#endif pHeader->setStretchLastSection(true); pHeader->resizeSection(0, 120); // Name QTreeView::resizeColumnToContents(1); // Map @@ -386,7 +392,7 @@ } -void InstrumentListView::removeInstrument ( const Instrument *pInstrument ) +void InstrumentListView::removeInstrument ( Instrument *pInstrument ) { m_pListModel->beginReset(); m_pListModel->removeInstrument(pInstrument); @@ -394,12 +400,21 @@ } -// Reposition the instrument in the model (called when map/bank/prg changed) -void InstrumentListView::updateInstrument ( const Instrument *pInstrument ) +void InstrumentListView::updateInstrument ( Instrument *pInstrument ) { m_pListModel->beginReset(); m_pListModel->updateInstrument(pInstrument); - m_pListModel->endReset();} + m_pListModel->endReset(); +} + + +// Reposition the instrument in the model (called when map/bank/prg changed) +void InstrumentListView::resortInstrument ( Instrument *pInstrument ) +{ + m_pListModel->beginReset(); + m_pListModel->resortInstrument(pInstrument); + m_pListModel->endReset(); +} // Refreshener.