annotate widgets/LayerTree.cpp @ 43:78515b1e29eb

* Rejig project file a bit to do pkg-config detection &c and change some HAVE_* symbol names accordingly * Add selection move/resize/delete * First stubs for add layer / pane commands
author Chris Cannam
date Wed, 01 Mar 2006 18:13:01 +0000
parents
children ad214997dddb
rev   line source
Chris@43 1
Chris@43 2 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@43 3
Chris@43 4 /*
Chris@43 5 A waveform viewer and audio annotation editor.
Chris@43 6 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@43 7
Chris@43 8 This is experimental software. Not for distribution.
Chris@43 9 */
Chris@43 10
Chris@43 11 #include "LayerTree.h"
Chris@43 12 #include "PaneStack.h"
Chris@43 13
Chris@43 14 #include "widgets/Pane.h"
Chris@43 15 #include "base/Layer.h"
Chris@43 16
Chris@43 17 #include <iostream>
Chris@43 18
Chris@43 19
Chris@43 20 LayerTreeModel::LayerTreeModel(PaneStack *stack, QObject *parent) :
Chris@43 21 QAbstractItemModel(parent),
Chris@43 22 m_stack(stack)
Chris@43 23 {
Chris@43 24 }
Chris@43 25
Chris@43 26 LayerTreeModel::~LayerTreeModel()
Chris@43 27 {
Chris@43 28 }
Chris@43 29
Chris@43 30 QVariant
Chris@43 31 LayerTreeModel::data(const QModelIndex &index, int role) const
Chris@43 32 {
Chris@43 33 std::cerr << "LayerTreeModel::data(" << &index << ", role " << role << ")" << std::endl;
Chris@43 34
Chris@43 35 if (!index.isValid()) return QVariant();
Chris@43 36 if (role != Qt::DisplayRole) return QVariant();
Chris@43 37
Chris@43 38 QObject *obj = static_cast<QObject *>(index.internalPointer());
Chris@43 39
Chris@43 40 PaneStack *paneStack = dynamic_cast<PaneStack *>(obj);
Chris@43 41 if (paneStack) {
Chris@43 42 std::cerr << "node is pane stack" << std::endl;
Chris@43 43 return QVariant("Pane stack");
Chris@43 44 }
Chris@43 45
Chris@43 46 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@43 47 if (pane) {
Chris@43 48 // need index of pane in pane stack
Chris@43 49 for (int i = 0; i < m_stack->getPaneCount(); ++i) {
Chris@43 50 if (pane == m_stack->getPane(i)) {
Chris@43 51 std::cerr << "node is pane " << i << std::endl;
Chris@43 52 return QVariant(QString("Pane %1").arg(i + 1));
Chris@43 53 }
Chris@43 54 }
Chris@43 55 return QVariant();
Chris@43 56 }
Chris@43 57
Chris@43 58 Layer *layer = dynamic_cast<Layer *>(obj);
Chris@43 59 if (layer) {
Chris@43 60 std::cerr << "node is layer" << std::endl;
Chris@43 61 return QVariant(QString("%1").arg(layer->objectName()));
Chris@43 62 }
Chris@43 63
Chris@43 64 return QVariant();
Chris@43 65 }
Chris@43 66
Chris@43 67 /*
Chris@43 68 Qt::ItemFlags
Chris@43 69 LayerTreeModel::flags(const QModelIndex &index) const
Chris@43 70 {
Chris@43 71 }
Chris@43 72
Chris@43 73 QVariant
Chris@43 74 LayerTreeModel::headerData(const QModelIndex &index,
Chris@43 75 Qt::Orientation orientation,
Chris@43 76 int role) const
Chris@43 77 {
Chris@43 78 }
Chris@43 79 */
Chris@43 80
Chris@43 81 QModelIndex
Chris@43 82 LayerTreeModel::index(int row, int column, const QModelIndex &parent) const
Chris@43 83 {
Chris@43 84 std::cerr << "LayerTreeModel::index(" << row << ", " << column << ", "
Chris@43 85 << &parent << ")" << std::endl;
Chris@43 86
Chris@43 87 if (!parent.isValid()) {
Chris@43 88 // this is the pane stack
Chris@43 89 std::cerr << "parent invalid, returning pane stack as root" << std::endl;
Chris@43 90 return createIndex(row, column, m_stack);
Chris@43 91 }
Chris@43 92
Chris@43 93 QObject *obj = static_cast<QObject *>(parent.internalPointer());
Chris@43 94
Chris@43 95 PaneStack *paneStack = dynamic_cast<PaneStack *>(obj);
Chris@43 96 if (paneStack) {
Chris@43 97 if (paneStack == m_stack && row < m_stack->getPaneCount()) {
Chris@43 98 std::cerr << "parent is pane stack, returning a pane" << std::endl;
Chris@43 99 return createIndex(row, column, m_stack->getPane(row));
Chris@43 100 }
Chris@43 101 std::cerr << "parent is wrong pane stack, returning nothing" << std::endl;
Chris@43 102 return QModelIndex();
Chris@43 103 }
Chris@43 104
Chris@43 105 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@43 106 if (pane) {
Chris@43 107 if (row < pane->getLayerCount()) {
Chris@43 108 std::cerr << "parent is pane, returning layer" << std::endl;
Chris@43 109 return createIndex(row, column, pane->getLayer(row));
Chris@43 110 }
Chris@43 111 }
Chris@43 112
Chris@43 113 std::cerr << "unknown parent, returning nothing" << std::endl;
Chris@43 114 return QModelIndex();
Chris@43 115 }
Chris@43 116
Chris@43 117 QModelIndex
Chris@43 118 LayerTreeModel::parent(const QModelIndex &index) const
Chris@43 119 {
Chris@43 120 std::cerr << "LayerTreeModel::parent(" << &index << ")" << std::endl;
Chris@43 121
Chris@43 122 QObject *obj = static_cast<QObject *>(index.internalPointer());
Chris@43 123
Chris@43 124 PaneStack *paneStack = dynamic_cast<PaneStack *>(obj);
Chris@43 125 if (paneStack) {
Chris@43 126 std::cerr << "node is pane stack, returning no parent" << std::endl;
Chris@43 127 return QModelIndex();
Chris@43 128 }
Chris@43 129
Chris@43 130 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@43 131 if (pane) {
Chris@43 132 std::cerr << "node is pane, returning pane stack as parent" << std::endl;
Chris@43 133 return createIndex(0, 0, m_stack);
Chris@43 134 }
Chris@43 135
Chris@43 136 Layer *layer = dynamic_cast<Layer *>(obj);
Chris@43 137 if (layer) {
Chris@43 138 const View *view = layer->getView();
Chris@43 139 Pane *pane = const_cast<Pane *>(dynamic_cast<const Pane *>(view));
Chris@43 140 if (pane) {
Chris@43 141 // need index of pane in pane stack
Chris@43 142 for (int i = 0; i < m_stack->getPaneCount(); ++i) {
Chris@43 143 if (pane == m_stack->getPane(i)) {
Chris@43 144 std::cerr << "node is layer, returning pane " << i << " as parent" << std::endl;
Chris@43 145 return createIndex(i, 0, pane);
Chris@43 146 }
Chris@43 147 }
Chris@43 148 }
Chris@43 149 std::cerr << "node is layer, but no parent found" << std::endl;
Chris@43 150 return QModelIndex();
Chris@43 151 }
Chris@43 152
Chris@43 153
Chris@43 154
Chris@43 155 std::cerr << "unknown node" << std::endl;
Chris@43 156 return QModelIndex();
Chris@43 157 }
Chris@43 158
Chris@43 159 int
Chris@43 160 LayerTreeModel::rowCount(const QModelIndex &parent) const
Chris@43 161 {
Chris@43 162 std::cerr << "LayerTreeModel::rowCount(" << &parent << ")" << std::endl;
Chris@43 163
Chris@43 164 if (!parent.isValid()) {
Chris@43 165 std::cerr << "parent invalid, returning 1 for the pane stack" << std::endl;
Chris@43 166 return 1; // the pane stack
Chris@43 167 }
Chris@43 168
Chris@43 169 QObject *obj = static_cast<QObject *>(parent.internalPointer());
Chris@43 170
Chris@43 171 PaneStack *paneStack = dynamic_cast<PaneStack *>(obj);
Chris@43 172 if (paneStack) {
Chris@43 173 if (paneStack == m_stack) {
Chris@43 174 std::cerr << "parent is pane stack, returning "
Chris@43 175 << m_stack->getPaneCount() << " panes" << std::endl;
Chris@43 176 return m_stack->getPaneCount();
Chris@43 177 } else {
Chris@43 178 return 0;
Chris@43 179 }
Chris@43 180 }
Chris@43 181
Chris@43 182 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@43 183 if (pane) {
Chris@43 184 std::cerr << "parent is pane, returning "
Chris@43 185 << pane->getLayerCount() << " layers" << std::endl;
Chris@43 186 return pane->getLayerCount();
Chris@43 187 }
Chris@43 188
Chris@43 189 std::cerr << "parent unknown, returning 0" << std::endl;
Chris@43 190 return 0;
Chris@43 191 }
Chris@43 192
Chris@43 193 int
Chris@43 194 LayerTreeModel::columnCount(const QModelIndex &parent) const
Chris@43 195 {
Chris@43 196 if (!parent.isValid()) return 1;
Chris@43 197
Chris@43 198 QObject *obj = static_cast<QObject *>(parent.internalPointer());
Chris@43 199
Chris@43 200 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@43 201 if (pane) {
Chris@43 202 return 1; // 2; // layer and model
Chris@43 203 }
Chris@43 204
Chris@43 205 return 1;
Chris@43 206 }
Chris@43 207