--- qsampler/trunk/src/qsamplerInstrumentList.cpp 2010/03/12 16:02:32 2064 +++ qsampler/trunk/src/qsamplerInstrumentList.cpp 2015/07/22 21:28:27 2828 @@ -1,7 +1,7 @@ // qsamplerInstrumentList.cpp // /**************************************************************************** - Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2003-2015, 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 @@ -39,11 +40,9 @@ // InstrumentListModel::InstrumentListModel ( QObject *pParent ) - : QAbstractItemModel(pParent) + : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL) { - m_iMidiMap = LSCP_MIDI_MAP_ALL; - - QAbstractItemModel::reset(); +// QAbstractItemModel::reset(); } InstrumentListModel::~InstrumentListModel (void) @@ -81,7 +80,6 @@ { if (!index.isValid()) return QVariant(); - const Instrument *pInstr = static_cast (index.internalPointer()); @@ -132,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); } @@ -145,7 +142,7 @@ } -QModelIndex InstrumentListModel::parent ( const QModelIndex& child ) const +QModelIndex InstrumentListModel::parent ( const QModelIndex& /*child*/ ) const { return QModelIndex(); } @@ -194,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; @@ -204,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())) { @@ -225,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; } @@ -245,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(); @@ -335,6 +336,28 @@ m_pListModel = new InstrumentListModel(this); QTreeView::setModel(m_pListModel); + + QTreeView::setRootIsDecorated(false); + QTreeView::setUniformRowHeights(true); + 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 + QTreeView::resizeColumnToContents(2); // Bank + QTreeView::resizeColumnToContents(3); // Prog + QTreeView::resizeColumnToContents(4); // Engine + pHeader->resizeSection(5, 240); // File + QTreeView::resizeColumnToContents(6); // Nr + pHeader->resizeSection(7, 60); // Vol } @@ -369,7 +392,7 @@ } -void InstrumentListView::removeInstrument ( const Instrument *pInstrument ) +void InstrumentListView::removeInstrument ( Instrument *pInstrument ) { m_pListModel->beginReset(); m_pListModel->removeInstrument(pInstrument); @@ -377,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.