Mercurial > hg > svgui
diff widgets/LayerTree.cpp @ 277:8acd30ed735c
* Fix up and simplify the LayerTreeModel, removing a horrible memory leak
* Move phase-unwrapped frequency estimation from SpectrogramLayer to
FFTDataServer
* Make the spectrum show peak phase-unwrapped frequencies as well (still
needs work)
* Start adding piano keyboard horizontal scale to spectrum
* Debug output for id3 tags
author | Chris Cannam |
---|---|
date | Tue, 03 Jul 2007 12:46:18 +0000 |
parents | 1a49bd0d8375 |
children | 3c402c6052f6 |
line wrap: on
line diff
--- a/widgets/LayerTree.cpp Mon Jul 02 14:58:34 2007 +0000 +++ b/widgets/LayerTree.cpp Tue Jul 03 12:46:18 2007 +0000 @@ -24,30 +24,6 @@ #include <iostream> -class ViewObjectAssoc : public QObject -{ -public: - ViewObjectAssoc(View *v, QObject *o) : - QObject(0), view(v), object(o) { - ++extantCount; - std::cerr << "ViewObjectAssoc (now " << extantCount << " extant)" - << std::endl; - } - - virtual ~ViewObjectAssoc() { - std::cerr << "~ViewObjectAssoc (now " << --extantCount << " extant)" - << std::endl; - } - - View *view; - QObject *object; - - static int extantCount; -}; - -int ViewObjectAssoc::extantCount = 0; - - LayerTreeModel::LayerTreeModel(PaneStack *stack, QObject *parent) : QAbstractItemModel(parent), m_stack(stack) @@ -64,43 +40,43 @@ LayerTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - if (role != Qt::DisplayRole) return QVariant(); - - std::cerr << "LayerTreeModel::data(" << &index << ", role " << role << ")" << std::endl; QObject *obj = static_cast<QObject *>(index.internalPointer()); - - PaneStack *paneStack = dynamic_cast<PaneStack *>(obj); - if (paneStack) { - std::cerr << "node is pane stack" << std::endl; - return QVariant("Pane stack"); + int row = index.row(), col = index.column(); + + Pane *pane = dynamic_cast<Pane *>(obj); + if (!pane) { + if (col == 0 && row < m_stack->getPaneCount()) { + switch (role) { + case Qt::DisplayRole: + return QVariant(QString("Pane %1").arg(row + 1)); + case Qt::DecorationRole: + return QVariant(QIcon(QString(":/icons/pane.png"))); + default: break; + } + } } - Pane *pane = dynamic_cast<Pane *>(obj); - if (pane) { - // need index of pane in pane stack - for (int i = 0; i < m_stack->getPaneCount(); ++i) { - if (pane == m_stack->getPane(i)) { - std::cerr << "node is pane " << i << std::endl; - return QVariant(QString("Pane %1").arg(i + 1)); - } - } - return QVariant(); - } - - ViewObjectAssoc *assoc = dynamic_cast<ViewObjectAssoc *>(obj); - if (assoc) { - std::cerr << "node is assoc" << std::endl; - Layer *layer = dynamic_cast<Layer *>(assoc->object); - if (layer) { - std::cerr << "with layer" << std::endl; - return QVariant(layer->objectName()); - } - Model *model = dynamic_cast<Model *>(assoc->object); - if (model) { - std::cerr << "with model" << std::endl; - return QVariant(model->objectName()); - } + if (pane && pane->getLayerCount() > row) { + Layer *layer = pane->getLayer(row); + if (layer) { + if (col == 0) { + switch (role) { + case Qt::DisplayRole: + return QVariant(layer->objectName()); + case Qt::DecorationRole: + return QVariant + (QIcon(QString(":/icons/%1.png") + .arg(layer->getPropertyContainerIconName()))); + default: break; + } + } else if (col == 1) { + Model *model = layer->getModel(); + if (model && role == Qt::DisplayRole) { + return QVariant(model->objectName()); + } + } + } } return QVariant(); @@ -129,145 +105,65 @@ QModelIndex LayerTreeModel::index(int row, int column, const QModelIndex &parent) const { - std::cerr << "LayerTreeModel::index(" << row << ", " << column << ", " - << &parent << ")" << std::endl; + // cell for a pane contains row, column, pane stack + // -> its parent is the invalid cell + + // cell for a layer contains row, column, pane + // -> its parent is row, column, pane stack (which identify the pane) if (!parent.isValid()) { - // this is the pane stack - std::cerr << "parent invalid, returning pane stack as root" << std::endl; - if (column > 0) return QModelIndex(); + if (row >= m_stack->getPaneCount() || column > 0) return QModelIndex(); return createIndex(row, column, m_stack); } QObject *obj = static_cast<QObject *>(parent.internalPointer()); - - PaneStack *paneStack = dynamic_cast<PaneStack *>(obj); - if (paneStack) { - if (column > 0) return QModelIndex(); - if (paneStack == m_stack && row < m_stack->getPaneCount()) { - std::cerr << "parent is pane stack, returning a pane" << std::endl; - return createIndex(row, column, m_stack->getPane(row)); - } - std::cerr << "parent is wrong pane stack, returning nothing" << std::endl; - return QModelIndex(); + + if (obj == m_stack) { + Pane *pane = m_stack->getPane(parent.row()); + if (!pane || parent.column() > 0) return QModelIndex(); + return createIndex(row, column, pane); } - Pane *pane = dynamic_cast<Pane *>(obj); - if (pane) { - std::cerr << "parent is pane" << std::endl; - if (row < pane->getLayerCount()) { - Layer *layer = pane->getLayer(row); - if (column == 0) { - std::cerr << "parent is pane, returning layer" << std::endl; - ViewObjectAssoc *assoc = new ViewObjectAssoc -// (const_cast<LayerTreeModel *>(this), pane, layer); - (pane, layer); - return createIndex(row, column, assoc); - } else { - std::cerr << "parent is pane, column != 0, returning model" << std::endl; - ViewObjectAssoc *assoc = new ViewObjectAssoc -// (const_cast<LayerTreeModel *>(this), pane, layer->getModel()); - (pane, layer->getModel()); - return createIndex(row, column, assoc); - } - } - } - - std::cerr << "unknown parent, returning nothing" << std::endl; return QModelIndex(); } QModelIndex LayerTreeModel::parent(const QModelIndex &index) const { - std::cerr << "LayerTreeModel::parent(" << &index << ")" << std::endl; - QObject *obj = static_cast<QObject *>(index.internalPointer()); - - PaneStack *paneStack = dynamic_cast<PaneStack *>(obj); - if (paneStack) { - std::cerr << "node is pane stack, returning no parent" << std::endl; - return QModelIndex(); - } Pane *pane = dynamic_cast<Pane *>(obj); if (pane) { - std::cerr << "node is pane, returning pane stack as parent" << std::endl; - return createIndex(0, 0, m_stack); + int index = m_stack->getPaneIndex(pane); + if (index >= 0) return createIndex(index, 0, m_stack); } - ViewObjectAssoc *assoc = dynamic_cast<ViewObjectAssoc *>(obj); - if (assoc) { - View *view = assoc->view; - Pane *pane = dynamic_cast<Pane *>(view); - if (pane) { - // need index of pane in pane stack - for (int i = 0; i < m_stack->getPaneCount(); ++i) { - if (pane == m_stack->getPane(i)) { - std::cerr << "node is assoc, returning pane " << i << " as parent" << std::endl; - return createIndex(i, 0, pane); - } - } - } - std::cerr << "node is assoc, but no parent found" << std::endl; - return QModelIndex(); - } - - std::cerr << "unknown node" << std::endl; return QModelIndex(); } int LayerTreeModel::rowCount(const QModelIndex &parent) const { - std::cerr << "LayerTreeModel::rowCount(" << &parent << ")" << std::endl; - - if (!parent.isValid()) { - std::cerr << "parent invalid, returning 1 for the pane stack" << std::endl; - return 1; // the pane stack - } + if (!parent.isValid()) return m_stack->getPaneCount(); QObject *obj = static_cast<QObject *>(parent.internalPointer()); - PaneStack *paneStack = dynamic_cast<PaneStack *>(obj); - if (paneStack) { - if (paneStack == m_stack) { - std::cerr << "parent is pane stack, returning " - << m_stack->getPaneCount() << " panes" << std::endl; - return m_stack->getPaneCount(); - } else { - return 0; - } - } - - Pane *pane = dynamic_cast<Pane *>(obj); - if (pane) { - std::cerr << "parent is pane, returning " - << pane->getLayerCount() << " layers" << std::endl; - return pane->getLayerCount(); + if (obj == m_stack) { + Pane *pane = m_stack->getPane(parent.row()); + if (!pane || parent.column() > 0) return 0; + return pane->getLayerCount(); } - std::cerr << "parent unknown, returning 0" << std::endl; return 0; } int LayerTreeModel::columnCount(const QModelIndex &parent) const { - if (!parent.isValid()) { - std::cerr << "LayerTreeModel::columnCount: parent invalid, returning 2" << std::endl; - return 2; - } + if (!parent.isValid()) return 2; QObject *obj = static_cast<QObject *>(parent.internalPointer()); - - Pane *pane = dynamic_cast<Pane *>(obj); - if (pane) { - std::cerr << "LayerTreeModel::columnCount: pane, returning 2" << std::endl; - return 2; // layer and model - } - - std::cerr << "LayerTreeModel::columnCount: returning 1" << std::endl; + if (obj == m_stack) return 2; return 1; }