Mercurial > hg > svgui
comparison widgets/LayerTree.cpp @ 298:226cb289bdf4
* Layer tree view updating when visibility / audibility changed (and layers
updating when they are changed in view) -- still some problems when a model
is loaded while the tree is visible
* FFTW_MEASURE throughout -- it does turn out to make an appreciable
difference sometimes
author | Chris Cannam |
---|---|
date | Thu, 16 Aug 2007 16:47:07 +0000 |
parents | 3c402c6052f6 |
children | 4a542ba875c2 |
comparison
equal
deleted
inserted
replaced
297:860f9ada4327 | 298:226cb289bdf4 |
---|---|
15 */ | 15 */ |
16 | 16 |
17 #include "LayerTree.h" | 17 #include "LayerTree.h" |
18 #include "view/PaneStack.h" | 18 #include "view/PaneStack.h" |
19 | 19 |
20 #include "base/PlayParameters.h" | |
20 #include "view/Pane.h" | 21 #include "view/Pane.h" |
21 #include "layer/Layer.h" | 22 #include "layer/Layer.h" |
22 #include "data/model/Model.h" | 23 #include "data/model/Model.h" |
23 | 24 |
24 #include <QIcon> | 25 #include <QIcon> |
29 QAbstractItemModel(parent), | 30 QAbstractItemModel(parent), |
30 m_stack(stack) | 31 m_stack(stack) |
31 { | 32 { |
32 connect(stack, SIGNAL(paneAdded()), this, SIGNAL(layoutChanged())); | 33 connect(stack, SIGNAL(paneAdded()), this, SIGNAL(layoutChanged())); |
33 connect(stack, SIGNAL(paneDeleted()), this, SIGNAL(layoutChanged())); | 34 connect(stack, SIGNAL(paneDeleted()), this, SIGNAL(layoutChanged())); |
35 | |
36 for (int i = 0; i < stack->getPaneCount(); ++i) { | |
37 Pane *pane = stack->getPane(i); | |
38 if (!pane) continue; | |
39 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)), | |
40 this, SLOT(propertyContainerAdded(PropertyContainer *))); | |
41 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)), | |
42 this, SLOT(propertyContainerRemoved(PropertyContainer *))); | |
43 connect(pane, SIGNAL(propertyContainerSelected(PropertyContainer *)), | |
44 this, SLOT(propertyContainerSelected(PropertyContainer *))); | |
45 connect(pane, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)), | |
46 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *))); | |
47 connect(pane, SIGNAL(propertyContainerNameChanged(PropertyContainer *)), | |
48 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *))); | |
49 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
50 Layer *layer = pane->getLayer(j); | |
51 if (!layer) continue; | |
52 PlayParameters *params = layer->getPlayParameters(); | |
53 if (!params) continue; | |
54 connect(params, SIGNAL(playAudibleChanged(bool)), | |
55 this, SLOT(playParametersAudibilityChanged(bool))); | |
56 } | |
57 } | |
34 } | 58 } |
35 | 59 |
36 LayerTreeModel::~LayerTreeModel() | 60 LayerTreeModel::~LayerTreeModel() |
37 { | 61 { |
62 } | |
63 | |
64 void | |
65 LayerTreeModel::propertyContainerAdded(PropertyContainer *) | |
66 { | |
67 emit layoutChanged(); | |
68 } | |
69 | |
70 void | |
71 LayerTreeModel::propertyContainerRemoved(PropertyContainer *) | |
72 { | |
73 emit layoutChanged(); | |
74 } | |
75 | |
76 void | |
77 LayerTreeModel::propertyContainerSelected(PropertyContainer *) | |
78 { | |
79 emit layoutChanged(); | |
80 } | |
81 | |
82 void | |
83 LayerTreeModel::propertyContainerPropertyChanged(PropertyContainer *pc) | |
84 { | |
85 for (int i = 0; i < m_stack->getPaneCount(); ++i) { | |
86 Pane *pane = m_stack->getPane(i); | |
87 if (!pane) continue; | |
88 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
89 if (pane->getLayer(j) == pc) { | |
90 emit dataChanged(createIndex(pane->getLayerCount() - j - 1, | |
91 0, pane), | |
92 createIndex(pane->getLayerCount() - j - 1, | |
93 3, pane)); | |
94 } | |
95 } | |
96 } | |
97 } | |
98 | |
99 void | |
100 LayerTreeModel::playParametersAudibilityChanged(bool a) | |
101 { | |
102 PlayParameters *params = dynamic_cast<PlayParameters *>(sender()); | |
103 if (!params) return; | |
104 | |
105 std::cerr << "LayerTreeModel::playParametersAudibilityChanged(" | |
106 << params << "," << a << ")" << std::endl; | |
107 | |
108 for (int i = 0; i < m_stack->getPaneCount(); ++i) { | |
109 Pane *pane = m_stack->getPane(i); | |
110 if (!pane) continue; | |
111 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
112 Layer *layer = pane->getLayer(j); | |
113 if (!layer) continue; | |
114 if (layer->getPlayParameters() == params) { | |
115 std::cerr << "LayerTreeModel::playParametersAudibilityChanged(" | |
116 << params << "," << a << "): row " << pane->getLayerCount() - j - 1 << ", col " << 2 << std::endl; | |
117 | |
118 emit dataChanged(createIndex(pane->getLayerCount() - j - 1, | |
119 2, pane), | |
120 createIndex(pane->getLayerCount() - j - 1, | |
121 2, pane)); | |
122 } | |
123 } | |
124 } | |
38 } | 125 } |
39 | 126 |
40 QVariant | 127 QVariant |
41 LayerTreeModel::data(const QModelIndex &index, int role) const | 128 LayerTreeModel::data(const QModelIndex &index, int role) const |
42 { | 129 { |
57 } | 144 } |
58 } | 145 } |
59 } | 146 } |
60 | 147 |
61 if (pane && pane->getLayerCount() > row) { | 148 if (pane && pane->getLayerCount() > row) { |
62 Layer *layer = pane->getLayer(row); | 149 Layer *layer = pane->getLayer(pane->getLayerCount() - row - 1); |
63 if (layer) { | 150 if (layer) { |
64 if (col == 0) { | 151 if (col == 0) { |
65 switch (role) { | 152 switch (role) { |
66 case Qt::DisplayRole: | 153 case Qt::DisplayRole: |
67 return QVariant(layer->objectName()); | 154 return QVariant(layer->objectName()); |
70 (QIcon(QString(":/icons/%1.png") | 157 (QIcon(QString(":/icons/%1.png") |
71 .arg(layer->getPropertyContainerIconName()))); | 158 .arg(layer->getPropertyContainerIconName()))); |
72 default: break; | 159 default: break; |
73 } | 160 } |
74 } else if (col == 1) { | 161 } else if (col == 1) { |
162 if (role == Qt::CheckStateRole) { | |
163 return QVariant(layer->isLayerDormant(pane) ? | |
164 Qt::Unchecked : Qt::Checked); | |
165 } else if (role == Qt::TextAlignmentRole) { | |
166 return QVariant(Qt::AlignHCenter); | |
167 } | |
168 } else if (col == 2) { | |
169 if (role == Qt::CheckStateRole) { | |
170 PlayParameters *params = layer->getPlayParameters(); | |
171 if (params) return QVariant(params->isPlayMuted() ? | |
172 Qt::Unchecked : Qt::Checked); | |
173 else return QVariant(); | |
174 } else if (role == Qt::TextAlignmentRole) { | |
175 return QVariant(Qt::AlignHCenter); | |
176 } | |
177 } else if (col == 3) { | |
75 Model *model = layer->getModel(); | 178 Model *model = layer->getModel(); |
76 if (model && role == Qt::DisplayRole) { | 179 if (model && role == Qt::DisplayRole) { |
77 return QVariant(model->objectName()); | 180 return QVariant(model->objectName()); |
78 } | 181 } |
79 } | 182 } |
81 } | 184 } |
82 | 185 |
83 return QVariant(); | 186 return QVariant(); |
84 } | 187 } |
85 | 188 |
189 bool | |
190 LayerTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) | |
191 { | |
192 if (!index.isValid()) return false; | |
193 | |
194 QObject *obj = static_cast<QObject *>(index.internalPointer()); | |
195 int row = index.row(), col = index.column(); | |
196 | |
197 Pane *pane = dynamic_cast<Pane *>(obj); | |
198 if (!pane || pane->getLayerCount() <= row) return false; | |
199 | |
200 Layer *layer = pane->getLayer(pane->getLayerCount() - row - 1); | |
201 if (!layer) return false; | |
202 | |
203 if (col == 1) { | |
204 if (role == Qt::CheckStateRole) { | |
205 layer->showLayer(pane, value.toInt() == Qt::Checked); | |
206 emit dataChanged(index, index); | |
207 return true; | |
208 } | |
209 } else if (col == 2) { | |
210 if (role == Qt::CheckStateRole) { | |
211 PlayParameters *params = layer->getPlayParameters(); | |
212 if (params) { | |
213 params->setPlayMuted(value.toInt() == Qt::Unchecked); | |
214 emit dataChanged(index, index); | |
215 return true; | |
216 } | |
217 } | |
218 } | |
219 | |
220 return false; | |
221 } | |
222 | |
86 Qt::ItemFlags | 223 Qt::ItemFlags |
87 LayerTreeModel::flags(const QModelIndex &index) const | 224 LayerTreeModel::flags(const QModelIndex &index) const |
88 { | 225 { |
89 if (!index.isValid()) return Qt::ItemIsEnabled; | 226 Qt::ItemFlags flags = Qt::ItemIsEnabled; |
90 return Qt::ItemIsEnabled | Qt::ItemIsSelectable; | 227 if (!index.isValid()) return flags; |
228 | |
229 if (index.column() == 1 || index.column() == 2) { | |
230 flags |= Qt::ItemIsUserCheckable; | |
231 } else if (index.column() == 0) { | |
232 flags |= Qt::ItemIsSelectable; | |
233 } | |
234 | |
235 return flags; | |
91 } | 236 } |
92 | 237 |
93 QVariant | 238 QVariant |
94 LayerTreeModel::headerData(int section, | 239 LayerTreeModel::headerData(int section, |
95 Qt::Orientation orientation, | 240 Qt::Orientation orientation, |
96 int role) const | 241 int role) const |
97 { | 242 { |
98 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | 243 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
99 if (section == 0) return QVariant(tr("Layer")); | 244 if (section == 0) return QVariant(tr("Layer")); |
100 else if (section == 1) return QVariant(tr("Model")); | 245 else if (section == 1) return QVariant(tr("Shown")); |
246 else if (section == 2) return QVariant(tr("Played")); | |
247 else if (section == 3) return QVariant(tr("Model")); | |
101 } | 248 } |
102 | 249 |
103 return QVariant(); | 250 return QVariant(); |
104 } | 251 } |
105 | 252 |
159 } | 306 } |
160 | 307 |
161 int | 308 int |
162 LayerTreeModel::columnCount(const QModelIndex &parent) const | 309 LayerTreeModel::columnCount(const QModelIndex &parent) const |
163 { | 310 { |
164 if (!parent.isValid()) return 2; | 311 if (!parent.isValid()) return 4; |
165 | 312 |
166 QObject *obj = static_cast<QObject *>(parent.internalPointer()); | 313 QObject *obj = static_cast<QObject *>(parent.internalPointer()); |
167 if (obj == m_stack) return 2; | 314 if (obj == m_stack) return 4; // row for a layer |
168 | 315 |
169 return 1; | 316 return 1; |
170 } | 317 } |
171 | 318 |