changeset 56:fedaf3ffe80a

* 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
author Chris Cannam
date Fri, 17 Mar 2006 17:38:28 +0000
parents 128ebfeeebee
children 2b87a7bd9256
files layer/WaveformLayer.cpp widgets/LayerTree.cpp widgets/LayerTree.h widgets/Pane.cpp
diffstat 4 files changed, 85 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- 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")) {
 
--- 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 <iostream>
 
 
+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<QObject *>(index.internalPointer());
     
     PaneStack *paneStack = dynamic_cast<PaneStack *>(obj);
@@ -55,28 +78,43 @@
 	return QVariant();
     }
 
-    Layer *layer = dynamic_cast<Layer *>(obj);
-    if (layer) {
-	std::cerr << "node is layer" << std::endl;
-	return QVariant(QString("%1").arg(layer->objectName()));
+    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());
+	}
     }
 
     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<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));
@@ -104,9 +144,20 @@
 
     Pane *pane = dynamic_cast<Pane *>(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<LayerTreeModel *>(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<LayerTreeModel *>(this), pane, layer->getModel());
+		return createIndex(row, column, assoc);
+	    }		
 	}
     }
 
@@ -133,26 +184,23 @@
 	return createIndex(0, 0, m_stack);
     }
 
-    Layer *layer = dynamic_cast<Layer *>(obj);
-    if (layer) {
-//!!!	const View *view = layer->getView();
-	const View *view = 0;
-	Pane *pane = const_cast<Pane *>(dynamic_cast<const Pane *>(view));
+    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 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<QObject *>(parent.internalPointer());
     
     Pane *pane = dynamic_cast<Pane *>(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;
 }
 
--- 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 <QAbstractItemModel>
 
 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;
--- 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;