annotate widgets/LayerTree.cpp @ 381:44670ce11a0c spectrogram-cache-rejig

* Some debug output and tweaks
author Chris Cannam
date Thu, 08 May 2008 09:23:16 +0000
parents 64e84e5efb76
children 1d85aa5a49be
rev   line source
Chris@43 1
Chris@58 2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@43 3
Chris@43 4 /*
Chris@59 5 Sonic Visualiser
Chris@59 6 An audio file viewer and annotation editor.
Chris@59 7 Centre for Digital Music, Queen Mary, University of London.
Chris@59 8 This file copyright 2006 Chris Cannam.
Chris@43 9
Chris@59 10 This program is free software; you can redistribute it and/or
Chris@59 11 modify it under the terms of the GNU General Public License as
Chris@59 12 published by the Free Software Foundation; either version 2 of the
Chris@59 13 License, or (at your option) any later version. See the file
Chris@59 14 COPYING included with this distribution for more information.
Chris@43 15 */
Chris@43 16
Chris@43 17 #include "LayerTree.h"
Chris@128 18 #include "view/PaneStack.h"
Chris@43 19
Chris@298 20 #include "base/PlayParameters.h"
Chris@128 21 #include "view/Pane.h"
Chris@128 22 #include "layer/Layer.h"
Chris@128 23 #include "data/model/Model.h"
Chris@374 24 #include "data/model/WaveFileModel.h"
Chris@43 25
Chris@280 26 #include <QIcon>
Chris@43 27 #include <iostream>
Chris@43 28
Chris@43 29
Chris@374 30 ModelDataModel::ModelDataModel(PaneStack *stack, bool waveModelsOnly,
Chris@374 31 QObject *parent) :
Chris@43 32 QAbstractItemModel(parent),
Chris@374 33 m_stack(stack),
Chris@374 34 m_waveModelsOnly(waveModelsOnly)
Chris@43 35 {
Chris@374 36 if (m_waveModelsOnly) {
Chris@374 37 m_modelTypeColumn = -1;
Chris@374 38 m_modelNameColumn = 0;
Chris@374 39 m_modelMakerColumn = 1;
Chris@374 40 m_modelSourceColumn = 2;
Chris@374 41 m_columnCount = 3;
Chris@374 42 } else {
Chris@374 43 m_modelTypeColumn = 0;
Chris@374 44 m_modelNameColumn = 1;
Chris@374 45 m_modelMakerColumn = 2;
Chris@374 46 m_modelSourceColumn = 3;
Chris@374 47 m_columnCount = 4;
Chris@374 48 }
Chris@374 49
Chris@374 50 connect(stack, SIGNAL(paneAdded()), this, SLOT(paneAdded()));
Chris@374 51 connect(stack, SIGNAL(paneDeleted()), this, SLOT(paneDeleted()));
Chris@298 52
Chris@298 53 for (int i = 0; i < stack->getPaneCount(); ++i) {
Chris@298 54 Pane *pane = stack->getPane(i);
Chris@298 55 if (!pane) continue;
Chris@298 56 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@298 57 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@298 58 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@298 59 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@298 60 connect(pane, SIGNAL(propertyContainerSelected(PropertyContainer *)),
Chris@298 61 this, SLOT(propertyContainerSelected(PropertyContainer *)));
Chris@298 62 connect(pane, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
Chris@298 63 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@298 64 connect(pane, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@298 65 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@374 66 connect(pane, SIGNAL(layerModelChanged()),
Chris@374 67 this, SLOT(paneLayerModelChanged()));
Chris@374 68 }
Chris@374 69
Chris@374 70 rebuildModelSet();
Chris@374 71 }
Chris@374 72
Chris@374 73 ModelDataModel::~ModelDataModel()
Chris@374 74 {
Chris@374 75 }
Chris@374 76
Chris@374 77 void
Chris@374 78 ModelDataModel::rebuildModelSet()
Chris@374 79 {
Chris@374 80 std::set<Model *> unfound = m_models;
Chris@374 81
Chris@374 82 for (int i = 0; i < m_stack->getPaneCount(); ++i) {
Chris@374 83
Chris@374 84 Pane *pane = m_stack->getPane(i);
Chris@374 85 if (!pane) continue;
Chris@374 86
Chris@374 87 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@374 88
Chris@374 89 Layer *layer = pane->getLayer(j);
Chris@374 90 if (!layer) continue;
Chris@374 91
Chris@374 92 Model *model = layer->getModel();
Chris@374 93 if (!model) continue;
Chris@374 94
Chris@374 95 if (m_waveModelsOnly) {
Chris@374 96 if (!dynamic_cast<WaveFileModel *>(model)) continue;
Chris@374 97 }
Chris@374 98
Chris@374 99 if (m_models.find(model) == m_models.end()) {
Chris@374 100 connect(model, SIGNAL(aboutToBeDeleted()),
Chris@374 101 this, SLOT(rebuildModelSet()));
Chris@374 102 m_models.insert(model);
Chris@374 103 } else {
Chris@374 104 unfound.erase(model);
Chris@374 105 }
Chris@374 106 }
Chris@374 107 }
Chris@374 108
Chris@374 109 for (std::set<Model *>::iterator i = unfound.begin();
Chris@374 110 i != unfound.end(); ++i) {
Chris@374 111 m_models.erase(*i);
Chris@374 112 }
Chris@374 113
Chris@374 114 std::cerr << "ModelDataModel::rebuildModelSet: " << m_models.size() << " models" << std::endl;
Chris@374 115 }
Chris@374 116
Chris@374 117 void
Chris@374 118 ModelDataModel::paneAdded()
Chris@374 119 {
Chris@374 120 rebuildModelSet();
Chris@374 121 emit layoutChanged();
Chris@374 122 }
Chris@374 123
Chris@374 124 void
Chris@374 125 ModelDataModel::paneDeleted()
Chris@374 126 {
Chris@374 127 rebuildModelSet();
Chris@374 128 emit layoutChanged();
Chris@374 129 }
Chris@374 130
Chris@374 131 void
Chris@374 132 ModelDataModel::paneLayerModelChanged()
Chris@374 133 {
Chris@374 134 rebuildModelSet();
Chris@374 135 emit layoutChanged();
Chris@374 136 }
Chris@374 137
Chris@374 138 void
Chris@374 139 ModelDataModel::propertyContainerAdded(PropertyContainer *)
Chris@374 140 {
Chris@374 141 rebuildModelSet();
Chris@374 142 emit layoutChanged();
Chris@374 143 }
Chris@374 144
Chris@374 145 void
Chris@374 146 ModelDataModel::propertyContainerRemoved(PropertyContainer *)
Chris@374 147 {
Chris@374 148 rebuildModelSet();
Chris@374 149 emit layoutChanged();
Chris@374 150 }
Chris@374 151
Chris@374 152 void
Chris@374 153 ModelDataModel::propertyContainerSelected(PropertyContainer *)
Chris@374 154 {
Chris@374 155 }
Chris@374 156
Chris@374 157 void
Chris@374 158 ModelDataModel::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@374 159 {
Chris@374 160 }
Chris@374 161
Chris@374 162 void
Chris@374 163 ModelDataModel::playParametersAudibilityChanged(bool a)
Chris@374 164 {
Chris@374 165 }
Chris@374 166
Chris@374 167 QVariant
Chris@374 168 ModelDataModel::data(const QModelIndex &index, int role) const
Chris@374 169 {
Chris@374 170 if (!index.isValid()) return QVariant();
Chris@374 171
Chris@374 172 QObject *obj = static_cast<QObject *>(index.internalPointer());
Chris@374 173 int row = index.row(), col = index.column();
Chris@374 174
Chris@374 175 //!!! not exactly the ideal use of a std::set
Chris@374 176 std::set<Model *>::iterator itr = m_models.begin();
Chris@374 177 for (int i = 0; i < row && itr != m_models.end(); ++i, ++itr);
Chris@374 178 if (itr == m_models.end()) return QVariant();
Chris@374 179
Chris@374 180 Model *model = *itr;
Chris@374 181
Chris@374 182 if (role != Qt::DisplayRole) {
Chris@374 183 if (m_waveModelsOnly && col == m_modelNameColumn &&
Chris@374 184 role == Qt::DecorationRole) {
Chris@374 185 // There is no meaningful icon for a model, in general --
Chris@374 186 // the icons we have represent layer types and it would be
Chris@374 187 // misleading to use them for models. However, if we're
Chris@374 188 // only showing wave models, we use the waveform icon just
Chris@374 189 // for decorative purposes.
Chris@374 190 return QVariant(QIcon(QString(":/icons/waveform.png")));
Chris@374 191 }
Chris@374 192 return QVariant();
Chris@374 193 }
Chris@374 194
Chris@374 195 if (col == m_modelTypeColumn) {
Chris@374 196 return QVariant(model->getTypeName());
Chris@374 197 } else if (col == m_modelNameColumn) {
Chris@374 198 return QVariant(model->objectName());
Chris@374 199 } else if (col == m_modelMakerColumn) {
Chris@374 200 return QVariant(model->getMaker());
Chris@374 201 } else if (col == m_modelSourceColumn) {
Chris@374 202 return QVariant(model->getLocation());
Chris@374 203 }
Chris@374 204
Chris@374 205 return QVariant();
Chris@374 206 }
Chris@374 207
Chris@374 208 bool
Chris@374 209 ModelDataModel::setData(const QModelIndex &index, const QVariant &value, int role)
Chris@374 210 {
Chris@374 211 return false;
Chris@374 212 }
Chris@374 213
Chris@374 214 Qt::ItemFlags
Chris@374 215 ModelDataModel::flags(const QModelIndex &index) const
Chris@374 216 {
Chris@374 217 Qt::ItemFlags flags = Qt::ItemIsEnabled;
Chris@374 218 return flags;
Chris@374 219 }
Chris@374 220
Chris@374 221 QVariant
Chris@374 222 ModelDataModel::headerData(int section,
Chris@374 223 Qt::Orientation orientation,
Chris@374 224 int role) const
Chris@374 225 {
Chris@374 226 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
Chris@374 227 if (section == m_modelTypeColumn) return QVariant(tr("Type"));
Chris@374 228 else if (section == m_modelNameColumn) return QVariant(tr("Name"));
Chris@374 229 else if (section == m_modelMakerColumn) return QVariant(tr("Maker"));
Chris@374 230 else if (section == m_modelSourceColumn) return QVariant(tr("Source"));
Chris@374 231 }
Chris@374 232
Chris@374 233 return QVariant();
Chris@374 234 }
Chris@374 235
Chris@374 236 QModelIndex
Chris@374 237 ModelDataModel::index(int row, int column, const QModelIndex &parent) const
Chris@374 238 {
Chris@374 239 if (!parent.isValid()) {
Chris@374 240 if (row >= m_models.size()) return QModelIndex();
Chris@374 241 return createIndex(row, column, 0);
Chris@374 242 }
Chris@374 243
Chris@374 244 return QModelIndex();
Chris@374 245 }
Chris@374 246
Chris@374 247 QModelIndex
Chris@374 248 ModelDataModel::parent(const QModelIndex &index) const
Chris@374 249 {
Chris@374 250 return QModelIndex();
Chris@374 251 }
Chris@374 252
Chris@374 253 int
Chris@374 254 ModelDataModel::rowCount(const QModelIndex &parent) const
Chris@374 255 {
Chris@374 256 if (!parent.isValid()) return m_models.size();
Chris@374 257 return 0;
Chris@374 258 }
Chris@374 259
Chris@374 260 int
Chris@374 261 ModelDataModel::columnCount(const QModelIndex &parent) const
Chris@374 262 {
Chris@374 263 return m_columnCount;
Chris@374 264 }
Chris@374 265
Chris@374 266
Chris@374 267
Chris@374 268 LayerTreeModel::LayerTreeModel(PaneStack *stack, QObject *parent) :
Chris@374 269 QAbstractItemModel(parent),
Chris@374 270 m_stack(stack)
Chris@374 271 {
Chris@374 272 m_layerNameColumn = 0;
Chris@374 273 m_layerVisibleColumn = 1;
Chris@374 274 m_layerPlayedColumn = 2;
Chris@374 275 m_modelNameColumn = 3;
Chris@374 276 m_columnCount = 4;
Chris@374 277
Chris@374 278 connect(stack, SIGNAL(paneAdded()), this, SLOT(paneAdded()));
Chris@374 279 connect(stack, SIGNAL(paneAboutToBeDeleted(Pane *)),
Chris@374 280 this, SLOT(paneAboutToBeDeleted(Pane *)));
Chris@374 281
Chris@374 282 for (int i = 0; i < stack->getPaneCount(); ++i) {
Chris@374 283 Pane *pane = stack->getPane(i);
Chris@374 284 if (!pane) continue;
Chris@374 285 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@374 286 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@374 287 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@374 288 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@374 289 connect(pane, SIGNAL(propertyContainerSelected(PropertyContainer *)),
Chris@374 290 this, SLOT(propertyContainerSelected(PropertyContainer *)));
Chris@374 291 connect(pane, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
Chris@374 292 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@374 293 connect(pane, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@374 294 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@374 295 connect(pane, SIGNAL(layerModelChanged()),
Chris@374 296 this, SLOT(paneLayerModelChanged()));
Chris@374 297
Chris@298 298 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@298 299 Layer *layer = pane->getLayer(j);
Chris@298 300 if (!layer) continue;
Chris@298 301 PlayParameters *params = layer->getPlayParameters();
Chris@298 302 if (!params) continue;
Chris@298 303 connect(params, SIGNAL(playAudibleChanged(bool)),
Chris@298 304 this, SLOT(playParametersAudibilityChanged(bool)));
Chris@298 305 }
Chris@298 306 }
Chris@43 307 }
Chris@43 308
Chris@43 309 LayerTreeModel::~LayerTreeModel()
Chris@43 310 {
Chris@43 311 }
Chris@43 312
Chris@298 313 void
Chris@374 314 LayerTreeModel::paneAdded()
Chris@374 315 {
Chris@374 316 emit layoutChanged();
Chris@374 317 }
Chris@374 318
Chris@374 319 void
Chris@374 320 LayerTreeModel::paneAboutToBeDeleted(Pane *pane)
Chris@374 321 {
Chris@374 322 std::cerr << "paneDeleted: " << pane << std::endl;
Chris@374 323 m_deletedPanes.insert(pane);
Chris@374 324 emit layoutChanged();
Chris@374 325 }
Chris@374 326
Chris@374 327 void
Chris@298 328 LayerTreeModel::propertyContainerAdded(PropertyContainer *)
Chris@298 329 {
Chris@298 330 emit layoutChanged();
Chris@298 331 }
Chris@298 332
Chris@298 333 void
Chris@298 334 LayerTreeModel::propertyContainerRemoved(PropertyContainer *)
Chris@298 335 {
Chris@298 336 emit layoutChanged();
Chris@298 337 }
Chris@298 338
Chris@298 339 void
Chris@298 340 LayerTreeModel::propertyContainerSelected(PropertyContainer *)
Chris@298 341 {
Chris@298 342 emit layoutChanged();
Chris@298 343 }
Chris@298 344
Chris@298 345 void
Chris@374 346 LayerTreeModel::paneLayerModelChanged()
Chris@374 347 {
Chris@374 348 emit layoutChanged();
Chris@374 349 }
Chris@374 350
Chris@374 351 void
Chris@298 352 LayerTreeModel::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@298 353 {
Chris@298 354 for (int i = 0; i < m_stack->getPaneCount(); ++i) {
Chris@298 355 Pane *pane = m_stack->getPane(i);
Chris@298 356 if (!pane) continue;
Chris@298 357 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@298 358 if (pane->getLayer(j) == pc) {
Chris@298 359 emit dataChanged(createIndex(pane->getLayerCount() - j - 1,
Chris@374 360 m_layerNameColumn, pane),
Chris@298 361 createIndex(pane->getLayerCount() - j - 1,
Chris@374 362 m_modelNameColumn, pane));
Chris@298 363 }
Chris@298 364 }
Chris@298 365 }
Chris@298 366 }
Chris@298 367
Chris@298 368 void
Chris@298 369 LayerTreeModel::playParametersAudibilityChanged(bool a)
Chris@298 370 {
Chris@298 371 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@298 372 if (!params) return;
Chris@298 373
Chris@298 374 std::cerr << "LayerTreeModel::playParametersAudibilityChanged("
Chris@298 375 << params << "," << a << ")" << std::endl;
Chris@298 376
Chris@298 377 for (int i = 0; i < m_stack->getPaneCount(); ++i) {
Chris@298 378 Pane *pane = m_stack->getPane(i);
Chris@298 379 if (!pane) continue;
Chris@298 380 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@298 381 Layer *layer = pane->getLayer(j);
Chris@298 382 if (!layer) continue;
Chris@298 383 if (layer->getPlayParameters() == params) {
Chris@298 384 std::cerr << "LayerTreeModel::playParametersAudibilityChanged("
Chris@298 385 << params << "," << a << "): row " << pane->getLayerCount() - j - 1 << ", col " << 2 << std::endl;
Chris@298 386
Chris@298 387 emit dataChanged(createIndex(pane->getLayerCount() - j - 1,
Chris@374 388 m_layerPlayedColumn, pane),
Chris@298 389 createIndex(pane->getLayerCount() - j - 1,
Chris@374 390 m_layerPlayedColumn, pane));
Chris@298 391 }
Chris@298 392 }
Chris@298 393 }
Chris@298 394 }
Chris@298 395
Chris@43 396 QVariant
Chris@43 397 LayerTreeModel::data(const QModelIndex &index, int role) const
Chris@43 398 {
Chris@43 399 if (!index.isValid()) return QVariant();
Chris@56 400
Chris@43 401 QObject *obj = static_cast<QObject *>(index.internalPointer());
Chris@277 402 int row = index.row(), col = index.column();
Chris@277 403
Chris@277 404 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@277 405 if (!pane) {
Chris@277 406 if (col == 0 && row < m_stack->getPaneCount()) {
Chris@277 407 switch (role) {
Chris@277 408 case Qt::DisplayRole:
Chris@277 409 return QVariant(QString("Pane %1").arg(row + 1));
Chris@277 410 case Qt::DecorationRole:
Chris@277 411 return QVariant(QIcon(QString(":/icons/pane.png")));
Chris@277 412 default: break;
Chris@277 413 }
Chris@277 414 }
Chris@43 415 }
Chris@43 416
Chris@277 417 if (pane && pane->getLayerCount() > row) {
Chris@298 418 Layer *layer = pane->getLayer(pane->getLayerCount() - row - 1);
Chris@277 419 if (layer) {
Chris@374 420 if (col == m_layerNameColumn) {
Chris@277 421 switch (role) {
Chris@277 422 case Qt::DisplayRole:
Chris@277 423 return QVariant(layer->objectName());
Chris@277 424 case Qt::DecorationRole:
Chris@277 425 return QVariant
Chris@277 426 (QIcon(QString(":/icons/%1.png")
Chris@277 427 .arg(layer->getPropertyContainerIconName())));
Chris@277 428 default: break;
Chris@277 429 }
Chris@374 430 } else if (col == m_layerVisibleColumn) {
Chris@298 431 if (role == Qt::CheckStateRole) {
Chris@298 432 return QVariant(layer->isLayerDormant(pane) ?
Chris@298 433 Qt::Unchecked : Qt::Checked);
Chris@298 434 } else if (role == Qt::TextAlignmentRole) {
Chris@298 435 return QVariant(Qt::AlignHCenter);
Chris@298 436 }
Chris@374 437 } else if (col == m_layerPlayedColumn) {
Chris@298 438 if (role == Qt::CheckStateRole) {
Chris@298 439 PlayParameters *params = layer->getPlayParameters();
Chris@298 440 if (params) return QVariant(params->isPlayMuted() ?
Chris@298 441 Qt::Unchecked : Qt::Checked);
Chris@298 442 else return QVariant();
Chris@298 443 } else if (role == Qt::TextAlignmentRole) {
Chris@298 444 return QVariant(Qt::AlignHCenter);
Chris@298 445 }
Chris@374 446 } else if (col == m_modelNameColumn) {
Chris@277 447 Model *model = layer->getModel();
Chris@277 448 if (model && role == Qt::DisplayRole) {
Chris@277 449 return QVariant(model->objectName());
Chris@277 450 }
Chris@277 451 }
Chris@277 452 }
Chris@43 453 }
Chris@43 454
Chris@43 455 return QVariant();
Chris@43 456 }
Chris@43 457
Chris@298 458 bool
Chris@298 459 LayerTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
Chris@298 460 {
Chris@298 461 if (!index.isValid()) return false;
Chris@298 462
Chris@298 463 QObject *obj = static_cast<QObject *>(index.internalPointer());
Chris@298 464 int row = index.row(), col = index.column();
Chris@298 465
Chris@298 466 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@298 467 if (!pane || pane->getLayerCount() <= row) return false;
Chris@298 468
Chris@298 469 Layer *layer = pane->getLayer(pane->getLayerCount() - row - 1);
Chris@298 470 if (!layer) return false;
Chris@298 471
Chris@374 472 if (col == m_layerVisibleColumn) {
Chris@298 473 if (role == Qt::CheckStateRole) {
Chris@298 474 layer->showLayer(pane, value.toInt() == Qt::Checked);
Chris@298 475 emit dataChanged(index, index);
Chris@298 476 return true;
Chris@298 477 }
Chris@374 478 } else if (col == m_layerPlayedColumn) {
Chris@298 479 if (role == Qt::CheckStateRole) {
Chris@298 480 PlayParameters *params = layer->getPlayParameters();
Chris@298 481 if (params) {
Chris@298 482 params->setPlayMuted(value.toInt() == Qt::Unchecked);
Chris@298 483 emit dataChanged(index, index);
Chris@298 484 return true;
Chris@298 485 }
Chris@298 486 }
Chris@298 487 }
Chris@298 488
Chris@298 489 return false;
Chris@298 490 }
Chris@298 491
Chris@43 492 Qt::ItemFlags
Chris@43 493 LayerTreeModel::flags(const QModelIndex &index) const
Chris@43 494 {
Chris@298 495 Qt::ItemFlags flags = Qt::ItemIsEnabled;
Chris@298 496 if (!index.isValid()) return flags;
Chris@298 497
Chris@374 498 if (index.column() == m_layerVisibleColumn ||
Chris@374 499 index.column() == m_layerPlayedColumn) {
Chris@298 500 flags |= Qt::ItemIsUserCheckable;
Chris@298 501 } else if (index.column() == 0) {
Chris@298 502 flags |= Qt::ItemIsSelectable;
Chris@298 503 }
Chris@298 504
Chris@298 505 return flags;
Chris@43 506 }
Chris@43 507
Chris@43 508 QVariant
Chris@56 509 LayerTreeModel::headerData(int section,
Chris@43 510 Qt::Orientation orientation,
Chris@43 511 int role) const
Chris@43 512 {
Chris@56 513 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
Chris@374 514 if (section == m_layerNameColumn) return QVariant(tr("Layer"));
Chris@374 515 else if (section == m_layerVisibleColumn) return QVariant(tr("Shown"));
Chris@374 516 else if (section == m_layerPlayedColumn) return QVariant(tr("Played"));
Chris@374 517 else if (section == m_modelNameColumn) return QVariant(tr("Model"));
Chris@56 518 }
Chris@56 519
Chris@56 520 return QVariant();
Chris@43 521 }
Chris@43 522
Chris@43 523 QModelIndex
Chris@43 524 LayerTreeModel::index(int row, int column, const QModelIndex &parent) const
Chris@43 525 {
Chris@277 526 // cell for a pane contains row, column, pane stack
Chris@277 527 // -> its parent is the invalid cell
Chris@277 528
Chris@277 529 // cell for a layer contains row, column, pane
Chris@277 530 // -> its parent is row, column, pane stack (which identify the pane)
Chris@43 531
Chris@43 532 if (!parent.isValid()) {
Chris@277 533 if (row >= m_stack->getPaneCount() || column > 0) return QModelIndex();
Chris@43 534 return createIndex(row, column, m_stack);
Chris@43 535 }
Chris@43 536
Chris@43 537 QObject *obj = static_cast<QObject *>(parent.internalPointer());
Chris@277 538
Chris@277 539 if (obj == m_stack) {
Chris@277 540 Pane *pane = m_stack->getPane(parent.row());
Chris@277 541 if (!pane || parent.column() > 0) return QModelIndex();
Chris@277 542 return createIndex(row, column, pane);
Chris@43 543 }
Chris@43 544
Chris@43 545 return QModelIndex();
Chris@43 546 }
Chris@43 547
Chris@43 548 QModelIndex
Chris@43 549 LayerTreeModel::parent(const QModelIndex &index) const
Chris@43 550 {
Chris@43 551 QObject *obj = static_cast<QObject *>(index.internalPointer());
Chris@43 552
Chris@374 553 if (m_deletedPanes.find(obj) != m_deletedPanes.end()) {
Chris@374 554 // m_deletedPanes.erase(obj);
Chris@374 555 return QModelIndex();
Chris@374 556 }
Chris@374 557
Chris@43 558 Pane *pane = dynamic_cast<Pane *>(obj);
Chris@43 559 if (pane) {
Chris@277 560 int index = m_stack->getPaneIndex(pane);
Chris@277 561 if (index >= 0) return createIndex(index, 0, m_stack);
Chris@43 562 }
Chris@43 563
Chris@43 564 return QModelIndex();
Chris@43 565 }
Chris@43 566
Chris@43 567 int
Chris@43 568 LayerTreeModel::rowCount(const QModelIndex &parent) const
Chris@43 569 {
Chris@277 570 if (!parent.isValid()) return m_stack->getPaneCount();
Chris@43 571
Chris@43 572 QObject *obj = static_cast<QObject *>(parent.internalPointer());
Chris@43 573
Chris@277 574 if (obj == m_stack) {
Chris@277 575 Pane *pane = m_stack->getPane(parent.row());
Chris@277 576 if (!pane || parent.column() > 0) return 0;
Chris@277 577 return pane->getLayerCount();
Chris@43 578 }
Chris@43 579
Chris@43 580 return 0;
Chris@43 581 }
Chris@43 582
Chris@43 583 int
Chris@43 584 LayerTreeModel::columnCount(const QModelIndex &parent) const
Chris@43 585 {
Chris@374 586 if (!parent.isValid()) return m_columnCount;
Chris@43 587
Chris@43 588 QObject *obj = static_cast<QObject *>(parent.internalPointer());
Chris@374 589 if (obj == m_stack) return m_columnCount; // row for a layer
Chris@56 590
Chris@43 591 return 1;
Chris@43 592 }
Chris@43 593