# HG changeset patch # User Chris Cannam # Date 1142617108 0 # Node ID fedaf3ffe80a819990f3c13a4e4493708bd237e3 # Parent 128ebfeeebee3f87152543c662b225eaa184aa56 * Add menu for re-adding existing layers * Fix layer tree window so that it at least approximates correct * Add bundled operations in command history, for use with things like multiple consecutive changes to a parameter value * Disambiguate plugins that happen to have identical descriptions * Add spectral centroid plugin (could use some parameters!) * Some other fixes diff -r 128ebfeeebee -r fedaf3ffe80a layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Thu Mar 16 18:46:00 2006 +0000 +++ b/layer/WaveformLayer.cpp Fri Mar 17 17:38:28 2006 +0000 @@ -98,9 +98,9 @@ { int deft = 0; - int throwaway; - if (!min) min = &throwaway; - if (!max) max = &throwaway; + int garbage0, garbage1; + if (!min) min = &garbage0; + if (!max) max = &garbage1; if (name == tr("Gain")) { diff -r 128ebfeeebee -r fedaf3ffe80a widgets/LayerTree.cpp --- a/widgets/LayerTree.cpp Thu Mar 16 18:46:00 2006 +0000 +++ b/widgets/LayerTree.cpp Fri Mar 17 17:38:28 2006 +0000 @@ -13,10 +13,33 @@ #include "widgets/Pane.h" #include "base/Layer.h" +#include "base/Model.h" #include +class ViewObjectAssoc : public QObject +{ +public: + ViewObjectAssoc(QObject *parent, View *v, QObject *o) : + QObject(parent), view(v), object(o) { + ++extantCount; + } + + 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) @@ -30,11 +53,11 @@ QVariant LayerTreeModel::data(const QModelIndex &index, int role) const { - std::cerr << "LayerTreeModel::data(" << &index << ", role " << role << ")" << std::endl; - if (!index.isValid()) return QVariant(); if (role != Qt::DisplayRole) return QVariant(); + std::cerr << "LayerTreeModel::data(" << &index << ", role " << role << ")" << std::endl; + QObject *obj = static_cast(index.internalPointer()); PaneStack *paneStack = dynamic_cast(obj); @@ -55,28 +78,43 @@ return QVariant(); } - Layer *layer = dynamic_cast(obj); - if (layer) { - std::cerr << "node is layer" << std::endl; - return QVariant(QString("%1").arg(layer->objectName())); + ViewObjectAssoc *assoc = dynamic_cast(obj); + if (assoc) { + std::cerr << "node is assoc" << std::endl; + Layer *layer = dynamic_cast(assoc->object); + if (layer) { + std::cerr << "with layer" << std::endl; + return QVariant(layer->objectName()); + } + Model *model = dynamic_cast(assoc->object); + if (model) { + std::cerr << "with model" << std::endl; + return QVariant(model->objectName()); + } } return QVariant(); } -/* Qt::ItemFlags LayerTreeModel::flags(const QModelIndex &index) const { + if (!index.isValid()) return Qt::ItemIsEnabled; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QVariant -LayerTreeModel::headerData(const QModelIndex &index, +LayerTreeModel::headerData(int section, Qt::Orientation orientation, int role) const { + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + if (section == 0) return QVariant(tr("Layer")); + else if (section == 1) return QVariant(tr("Model")); + } + + return QVariant(); } -*/ QModelIndex LayerTreeModel::index(int row, int column, const QModelIndex &parent) const @@ -87,6 +125,7 @@ if (!parent.isValid()) { // this is the pane stack std::cerr << "parent invalid, returning pane stack as root" << std::endl; + if (column > 0) return QModelIndex(); return createIndex(row, column, m_stack); } @@ -94,6 +133,7 @@ PaneStack *paneStack = dynamic_cast(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)); @@ -104,9 +144,20 @@ Pane *pane = dynamic_cast(obj); if (pane) { + std::cerr << "parent is pane" << std::endl; if (row < pane->getLayerCount()) { - std::cerr << "parent is pane, returning layer" << std::endl; - return createIndex(row, column, pane->getLayer(row)); + Layer *layer = pane->getLayer(row); + if (column == 0) { + std::cerr << "parent is pane, returning layer" << std::endl; + ViewObjectAssoc *assoc = new ViewObjectAssoc + (const_cast(this), 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(this), pane, layer->getModel()); + return createIndex(row, column, assoc); + } } } @@ -133,26 +184,23 @@ return createIndex(0, 0, m_stack); } - Layer *layer = dynamic_cast(obj); - if (layer) { -//!!! const View *view = layer->getView(); - const View *view = 0; - Pane *pane = const_cast(dynamic_cast(view)); + ViewObjectAssoc *assoc = dynamic_cast(obj); + if (assoc) { + View *view = assoc->view; + Pane *pane = dynamic_cast(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 layer, returning pane " << i << " as parent" << std::endl; + std::cerr << "node is assoc, returning pane " << i << " as parent" << std::endl; return createIndex(i, 0, pane); } } } - std::cerr << "node is layer, but no parent found" << std::endl; + std::cerr << "node is assoc, but no parent found" << std::endl; return QModelIndex(); } - - std::cerr << "unknown node" << std::endl; return QModelIndex(); } @@ -194,15 +242,21 @@ int LayerTreeModel::columnCount(const QModelIndex &parent) const { - if (!parent.isValid()) return 1; + if (!parent.isValid()) { + std::cerr << "LayerTreeModel::columnCount: parent invalid, returning 2" << std::endl; + return 2; + } QObject *obj = static_cast(parent.internalPointer()); Pane *pane = dynamic_cast(obj); if (pane) { - return 1; // 2; // layer and model + std::cerr << "LayerTreeModel::columnCount: pane, returning 2" << std::endl; + return 2; // layer and model } + std::cerr << "LayerTreeModel::columnCount: returning 1" << std::endl; + return 1; } diff -r 128ebfeeebee -r fedaf3ffe80a widgets/LayerTree.h --- a/widgets/LayerTree.h Thu Mar 16 18:46:00 2006 +0000 +++ b/widgets/LayerTree.h Fri Mar 17 17:38:28 2006 +0000 @@ -14,6 +14,8 @@ #include class PaneStack; +class View; +class Layer; class LayerTreeModel : public QAbstractItemModel { @@ -25,10 +27,10 @@ QVariant data(const QModelIndex &index, int role) const; -// Qt::ItemFlags flags(const QModelIndex &index) const; + Qt::ItemFlags flags(const QModelIndex &index) const; -// QVariant headerData(int section, Qt::Orientation orientation, -// int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; diff -r 128ebfeeebee -r fedaf3ffe80a widgets/Pane.cpp --- a/widgets/Pane.cpp Thu Mar 16 18:46:00 2006 +0000 +++ b/widgets/Pane.cpp Fri Mar 17 17:38:28 2006 +0000 @@ -323,17 +323,7 @@ for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { - QString layerName = (*i)->objectName(); - QString modelName; - if ((*i)->getModel()) modelName = (*i)->getModel()->objectName(); - - QString text; - if (modelName != "") { - text = QString("%1: %2").arg(modelName).arg(layerName); - } else { - text = layerName; - } - + QString text = (*i)->getLayerPresentationName(); texts.push_back(text); int tw = paint.fontMetrics().width(text); if (tw > maxTextWidth) maxTextWidth = tw;