changeset 52:f2fe98a7c57e

* Use commands for add/delete pane in main window * Add compound command collection to command history (for add pane, import file etc) * Add hide/show pane and hidden pane list to PaneStack * Various other fixes
author Chris Cannam
date Mon, 13 Mar 2006 17:55:19 +0000
parents d2eac322d71b
children 68869408f5c7
files layer/LayerFactory.cpp layer/LayerFactory.h widgets/PaneStack.cpp widgets/PaneStack.h widgets/PropertyStack.cpp widgets/PropertyStack.h
diffstat 6 files changed, 161 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/layer/LayerFactory.cpp	Fri Mar 10 17:37:45 2006 +0000
+++ b/layer/LayerFactory.cpp	Mon Mar 13 17:55:19 2006 +0000
@@ -231,7 +231,7 @@
 }
 
 Layer *
-LayerFactory::createLayer(LayerType type, Model *model, int channel)
+LayerFactory::createLayer(LayerType type, int channel)
 {
     Layer *layer = 0;
 
@@ -288,7 +288,6 @@
 	std::cerr << "LayerFactory::createLayer: Unknown layer type " 
 		  << type << std::endl;
     } else {
-	if (model) setModel(layer, model);
 	std::cerr << "LayerFactory::createLayer: Setting object name "
 		  << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl;
 	layer->setObjectName(getLayerPresentationName(type));
--- a/layer/LayerFactory.h	Fri Mar 10 17:37:45 2006 +0000
+++ b/layer/LayerFactory.h	Mon Mar 13 17:55:19 2006 +0000
@@ -49,7 +49,7 @@
 
     LayerType getLayerType(const Layer *);
 
-    Layer *createLayer(LayerType type, Model *model = 0, int channel = -1);
+    Layer *createLayer(LayerType type, int channel = -1);
 
     QString getLayerPresentationName(LayerType type);
 
--- a/widgets/PaneStack.cpp	Fri Mar 10 17:37:45 2006 +0000
+++ b/widgets/PaneStack.cpp	Mon Mar 13 17:55:19 2006 +0000
@@ -45,25 +45,28 @@
     layout->addWidget(currentIndicator);
     layout->setStretchFactor(currentIndicator, 1);
     currentIndicator->setScaledContents(true);
-    m_currentIndicators.push_back(currentIndicator);
 
     Pane *pane = new Pane(frame);
     pane->setViewManager(m_viewManager);
     layout->addWidget(pane);
     layout->setStretchFactor(pane, 10);
-    m_panes.push_back(pane);
 
     QWidget *properties = 0;
     if (suppressPropertyBox) {
 	properties = new QFrame();
     } else {
 	properties = new PropertyStack(frame, pane);
-	connect(properties, SIGNAL(propertyContainerSelected(PropertyContainer *)),
-		this, SLOT(propertyContainerSelected(PropertyContainer *)));
+	connect(properties, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
+		this, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
     }
     layout->addWidget(properties);
     layout->setStretchFactor(properties, 1);
-    m_propertyStacks.push_back(properties);
+
+    PaneRec rec;
+    rec.pane = pane;
+    rec.propertyStack = properties;
+    rec.currentIndicator = currentIndicator;
+    m_panes.push_back(rec);
 
     frame->setLayout(layout);
     addWidget(frame);
@@ -85,34 +88,50 @@
 Pane *
 PaneStack::getPane(int n)
 {
-    return m_panes[n];
+    return m_panes[n].pane;
+}
+
+Pane *
+PaneStack::getHiddenPane(int n)
+{
+    return m_hiddenPanes[n].pane;
 }
 
 void
 PaneStack::deletePane(Pane *pane)
 {
-    int n = 0;
-    std::vector<Pane *>::iterator i = m_panes.begin();
-    std::vector<QWidget *>::iterator j = m_propertyStacks.begin();
-    std::vector<QLabel *>::iterator k = m_currentIndicators.begin();
+    std::vector<PaneRec>::iterator i;
+    bool found = false;
 
-    while (i != m_panes.end()) {
-	if (*i == pane) break;
-	++i;
-	++j;
-	++k;
-	++n;
+    for (i = m_panes.begin(); i != m_panes.end(); ++i) {
+	if (i->pane == pane) {
+	    m_panes.erase(i);
+	    found = true;
+	    break;
+	}
     }
-    if (n >= int(m_panes.size())) return;
 
-    m_panes.erase(i);
-    m_propertyStacks.erase(j);
-    m_currentIndicators.erase(k);
-    delete widget(n);
+    if (!found) {
+
+	for (i = m_hiddenPanes.begin(); i != m_hiddenPanes.end(); ++i) {
+	    if (i->pane == pane) {
+		m_hiddenPanes.erase(i);
+		found = true;
+		break;
+	    }
+	}
+
+	if (!found) {
+	    std::cerr << "WARNING: PaneStack::deletePane(" << pane << "): Pane not found in visible or hidden panes, not deleting" << std::endl;
+	    return;
+	}
+    }
+
+    delete pane->parent();
 
     if (m_currentPane == pane) {
 	if (m_panes.size() > 0) {
-	    setCurrentPane(m_panes[0]);
+	    setCurrentPane(m_panes[0].pane);
 	} else {
 	    setCurrentPane(0);
 	}
@@ -125,13 +144,70 @@
     return m_panes.size();
 }
 
+int
+PaneStack::getHiddenPaneCount() const
+{
+    return m_hiddenPanes.size();
+}
+
+void
+PaneStack::hidePane(Pane *pane)
+{
+    std::vector<PaneRec>::iterator i = m_panes.begin();
+
+    while (i != m_panes.end()) {
+	if (i->pane == pane) {
+
+	    m_hiddenPanes.push_back(*i);
+	    m_panes.erase(i);
+
+	    QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
+	    if (pw) pw->hide();
+
+	    if (m_currentPane == pane) {
+		if (m_panes.size() > 0) {
+		    setCurrentPane(m_panes[0].pane);
+		} else {
+		    setCurrentPane(0);
+		}
+	    }
+	    
+	    return;
+	}
+	++i;
+    }
+
+    std::cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << std::endl;
+}
+
+void
+PaneStack::showPane(Pane *pane)
+{
+    std::vector<PaneRec>::iterator i = m_hiddenPanes.begin();
+
+    while (i != m_hiddenPanes.end()) {
+	if (i->pane == pane) {
+	    m_panes.push_back(*i);
+	    m_hiddenPanes.erase(i);
+	    QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
+	    if (pw) pw->show();
+
+	    //!!! update current pane
+
+	    return;
+	}
+	++i;
+    }
+
+    std::cerr << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << std::endl;
+}
+
 void
 PaneStack::setCurrentPane(Pane *pane) // may be null
 {
     if (m_currentPane == pane) return;
     
-    std::vector<Pane *>::iterator i = m_panes.begin();
-    std::vector<QLabel *>::iterator k = m_currentIndicators.begin();
+    std::vector<PaneRec>::iterator i = m_panes.begin();
 
     // We used to do this by setting the foreground and background
     // role, but it seems the background role is ignored and the
@@ -143,18 +219,24 @@
     QPixmap unselectedMap(1, 1);
     unselectedMap.fill(QApplication::palette().color(QPalette::Background));
 
+    bool found = false;
+
     while (i != m_panes.end()) {
-	if (*i == pane) {
-	    (*k)->setPixmap(selectedMap);
+	if (i->pane == pane) {
+	    i->currentIndicator->setPixmap(selectedMap);
+	    found = true;
 	} else {
-	    (*k)->setPixmap(unselectedMap);
+	    i->currentIndicator->setPixmap(unselectedMap);
 	}
 	++i;
-	++k;
     }
-    m_currentPane = pane;
 
-    emit currentPaneChanged(m_currentPane);
+    if (found || pane == 0) {
+	m_currentPane = pane;
+	emit currentPaneChanged(m_currentPane);
+    } else {
+	std::cerr << "WARNING: PaneStack::setCurrentPane(" << pane << "): pane is not a visible pane in this stack" << std::endl;
+    }
 }
 
 void
@@ -164,13 +246,13 @@
 
     if (m_currentPane) {
 
-	std::vector<Pane *>::iterator i = m_panes.begin();
-	std::vector<QWidget *>::iterator j = m_propertyStacks.begin();
+	std::vector<PaneRec>::iterator i = m_panes.begin();
 
 	while (i != m_panes.end()) {
 
-	    if (*i == pane) {
-		PropertyStack *stack = dynamic_cast<PropertyStack *>(*j);
+	    if (i->pane == pane) {
+		PropertyStack *stack = dynamic_cast<PropertyStack *>
+		    (i->propertyStack);
 		if (stack) {
 		    if (stack->containsContainer(layer)) {
 			stack->setCurrentIndex(stack->getContainerIndex(layer));
@@ -185,7 +267,6 @@
 		break;
 	    }
 	    ++i;
-	    ++j;
 	}
     }
 }
@@ -209,19 +290,19 @@
 }
 
 void
-PaneStack::propertyContainerSelected(PropertyContainer *pc)
+PaneStack::propertyContainerSelected(View *client, PropertyContainer *pc)
 {
-    std::vector<Pane *>::iterator i = m_panes.begin();
-    std::vector<QWidget *>::iterator j = m_propertyStacks.begin();
+    std::vector<PaneRec>::iterator i = m_panes.begin();
 
     while (i != m_panes.end()) {
-	PropertyStack *stack = dynamic_cast<PropertyStack *>(*j);
-	if (stack && stack->containsContainer(pc)) {
-	    setCurrentPane(*i);
+	PropertyStack *stack = dynamic_cast<PropertyStack *>(i->propertyStack);
+	if (stack &&
+	    stack->getClient() == client &&
+	    stack->containsContainer(pc)) {
+	    setCurrentPane(i->pane);
 	    break;
 	}
 	++i;
-	++j;
     }
 
     Layer *layer = dynamic_cast<Layer *>(pc);
@@ -242,14 +323,14 @@
 {
     int maxMinWidth = 0;
 
-    for (unsigned int i = 0; i < m_propertyStacks.size(); ++i) {
-	if (!m_propertyStacks[i]) continue;
+    for (size_t i = 0; i < m_panes.size(); ++i) {
+	if (!m_panes[i].propertyStack) continue;
 	std::cerr << "PaneStack::sizePropertyStacks: " << i << ": min " 
-		  << m_propertyStacks[i]->minimumSizeHint().width() << ", current "
-		  << m_propertyStacks[i]->width() << std::endl;
+		  << m_panes[i].propertyStack->minimumSizeHint().width() << ", current "
+		  << m_panes[i].propertyStack->width() << std::endl;
 
-	if (m_propertyStacks[i]->minimumSizeHint().width() > maxMinWidth) {
-	    maxMinWidth = m_propertyStacks[i]->minimumSizeHint().width();
+	if (m_panes[i].propertyStack->minimumSizeHint().width() > maxMinWidth) {
+	    maxMinWidth = m_panes[i].propertyStack->minimumSizeHint().width();
 	}
     }
 
@@ -263,9 +344,9 @@
     int setWidth = maxMinWidth;
 #endif
 
-    for (unsigned int i = 0; i < m_propertyStacks.size(); ++i) {
-	if (!m_propertyStacks[i]) continue;
-	m_propertyStacks[i]->setMinimumWidth(setWidth);
+    for (size_t i = 0; i < m_panes.size(); ++i) {
+	if (!m_panes[i].propertyStack) continue;
+	m_panes[i].propertyStack->setMinimumWidth(setWidth);
     }
 }
     
--- a/widgets/PaneStack.h	Fri Mar 10 17:37:45 2006 +0000
+++ b/widgets/PaneStack.h	Mon Mar 13 17:55:19 2006 +0000
@@ -15,6 +15,7 @@
 
 class QWidget;
 class QLabel;
+class View;
 class Pane;
 class Layer;
 class ViewManager;
@@ -29,12 +30,16 @@
     PaneStack(QWidget *parent, ViewManager *viewManager);
 
     Pane *addPane(bool suppressPropertyBox = false); // I own the returned value
-    Pane *getPane(int n); // I own the returned value
-    void deletePane(Pane *pane); // Deletes the pane and all its layers
-    int getPaneCount() const;
+    void deletePane(Pane *pane); // Deletes the pane, but _not_ its layers
 
-//!!!    void hidePane(Pane *pane);
-//    void showPane(Pane *pane);
+    int getPaneCount() const; // Returns only count of visible panes
+    Pane *getPane(int n); // Of visible panes; I own the returned value
+
+    void hidePane(Pane *pane); // Also removes pane from getPane/getPaneCount
+    void showPane(Pane *pane); // Returns pane to getPane/getPaneCount
+
+    int getHiddenPaneCount() const;
+    Pane *getHiddenPane(int n); // I own the returned value
 
     void setCurrentPane(Pane *pane);
     void setCurrentLayer(Pane *pane, Layer *layer);
@@ -47,17 +52,23 @@
 public slots:
     void propertyContainerAdded(PropertyContainer *);
     void propertyContainerRemoved(PropertyContainer *);
-    void propertyContainerSelected(PropertyContainer *);
+    void propertyContainerSelected(View *client, PropertyContainer *);
     void paneInteractedWith();
 
 protected:
     Pane *m_currentPane;
-    //!!! should be a single vector of structs
-    std::vector<Pane *> m_panes; // I own these
-    std::vector<QWidget *> m_propertyStacks; // I own these
-    std::vector<QLabel *> m_currentIndicators; // I own these
+
+    struct PaneRec
+    {
+	Pane *pane;
+	QWidget *propertyStack;
+	QLabel *currentIndicator;
+    };
+
+    std::vector<PaneRec> m_panes;
+    std::vector<PaneRec> m_hiddenPanes;
+
     ViewManager *m_viewManager; // I don't own this
-
     void sizePropertyStacks();
 };
 
--- a/widgets/PropertyStack.cpp	Fri Mar 10 17:37:45 2006 +0000
+++ b/widgets/PropertyStack.cpp	Mon Mar 13 17:55:19 2006 +0000
@@ -41,8 +41,8 @@
     connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
 	    this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
 
-    connect(this, SIGNAL(propertyContainerSelected(PropertyContainer *)),
-	    m_client, SLOT(propertyContainerSelected(PropertyContainer *)));
+    connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
+	    m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
 }
 
 void
@@ -160,7 +160,7 @@
 PropertyStack::selectedContainerChanged(int n)
 {
     if (n >= int(m_boxes.size())) return;
-    emit propertyContainerSelected(m_boxes[n]->getContainer());
+    emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
 }
 
 #ifdef INCLUDE_MOCFILES
--- a/widgets/PropertyStack.h	Fri Mar 10 17:37:45 2006 +0000
+++ b/widgets/PropertyStack.h	Mon Mar 13 17:55:19 2006 +0000
@@ -26,11 +26,12 @@
 public:
     PropertyStack(QWidget *parent, View *client);
 
+    View *getClient() { return m_client; }
     bool containsContainer(PropertyContainer *container) const;
     int getContainerIndex(PropertyContainer *container) const;
 
 signals:
-    void propertyContainerSelected(PropertyContainer *container);
+    void propertyContainerSelected(View *client, PropertyContainer *container);
 
 public slots:
     void propertyContainerAdded(PropertyContainer *);