Mercurial > hg > svcore
changeset 454:ba7aaacb7211
* Support transforms that output regions with more than one bin (by
creating more than one region)
* When model displayed in the spreadsheet dialog is deleted, close
the dialog in preference to crashing
author | Chris Cannam |
---|---|
date | Thu, 09 Oct 2008 13:13:33 +0000 |
parents | 1f15beefcd76 |
children | 3e0f1f7bec85 |
files | data/model/ModelDataTableModel.cpp data/model/ModelDataTableModel.h transform/FeatureExtractionModelTransformer.cpp |
diffstat | 3 files changed, 62 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/data/model/ModelDataTableModel.cpp Thu Oct 09 12:22:02 2008 +0000 +++ b/data/model/ModelDataTableModel.cpp Thu Oct 09 13:13:33 2008 +0000 @@ -33,6 +33,8 @@ connect(baseModel, SIGNAL(modelChanged()), this, SLOT(modelChanged())); connect(baseModel, SIGNAL(modelChanged(size_t, size_t)), this, SLOT(modelChanged(size_t, size_t))); + connect(baseModel, SIGNAL(aboutToBeDeleted()), + this, SLOT(modelAboutToBeDeleted())); } ModelDataTableModel::~ModelDataTableModel() @@ -42,6 +44,7 @@ QVariant ModelDataTableModel::data(const QModelIndex &index, int role) const { + if (!m_model) return QVariant(); if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant(); if (!index.isValid()) return QVariant(); return m_model->getData(getUnsorted(index.row()), index.column(), role); @@ -50,6 +53,7 @@ bool ModelDataTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { + if (!m_model) return false; if (!index.isValid()) return false; Command *command = m_model->getSetDataCommand(getUnsorted(index.row()), index.column(), @@ -65,6 +69,7 @@ bool ModelDataTableModel::insertRow(int row, const QModelIndex &parent) { + if (!m_model) return false; if (parent.isValid()) return false; emit beginInsertRows(parent, row, row); @@ -83,6 +88,7 @@ bool ModelDataTableModel::removeRow(int row, const QModelIndex &parent) { + if (!m_model) return false; if (parent.isValid()) return false; emit beginRemoveRows(parent, row, row); @@ -109,6 +115,8 @@ QVariant ModelDataTableModel::headerData(int section, Qt::Orientation orientation, int role) const { + if (!m_model) return QVariant(); + if (orientation == Qt::Vertical && role == Qt::DisplayRole) { return section + 1; } @@ -133,6 +141,7 @@ int ModelDataTableModel::rowCount(const QModelIndex &parent) const { + if (!m_model) return 0; if (parent.isValid()) return 0; return m_model->getRowCount(); } @@ -140,6 +149,7 @@ int ModelDataTableModel::columnCount(const QModelIndex &parent) const { + if (!m_model) return 0; if (parent.isValid()) return 0; return m_model->getColumnCount(); } @@ -147,6 +157,7 @@ QModelIndex ModelDataTableModel::getModelIndexForFrame(size_t frame) const { + if (!m_model) return createIndex(0, 0); int row = m_model->getRowForFrame(frame); return createIndex(getSorted(row), 0, 0); } @@ -154,6 +165,7 @@ size_t ModelDataTableModel::getFrameForModelIndex(const QModelIndex &index) const { + if (!m_model) return 0; return m_model->getFrameForRow(getUnsorted(index.row())); } @@ -191,9 +203,18 @@ emit layoutChanged(); } +void +ModelDataTableModel::modelAboutToBeDeleted() +{ + m_model = 0; + emit modelRemoved(); +} + int ModelDataTableModel::getSorted(int row) const { + if (!m_model) return row; + if (m_model->isColumnTimeValue(m_sortColumn)) { if (m_sortOrdering == Qt::AscendingOrder) { return row; @@ -219,6 +240,8 @@ int ModelDataTableModel::getUnsorted(int row) const { + if (!m_model) return row; + if (m_model->isColumnTimeValue(m_sortColumn)) { if (m_sortOrdering == Qt::AscendingOrder) { return row; @@ -246,6 +269,8 @@ void ModelDataTableModel::resort() const { + if (!m_model) return; + bool numeric = (m_model->getSortType(m_sortColumn) == TabularModel::SortNumeric); @@ -275,6 +300,8 @@ void ModelDataTableModel::resortNumeric() const { + if (!m_model) return; + typedef std::multimap<double, int> MapType; MapType rowMap; @@ -295,6 +322,8 @@ void ModelDataTableModel::resortAlphabetical() const { + if (!m_model) return; + typedef std::multimap<QString, int> MapType; MapType rowMap;
--- a/data/model/ModelDataTableModel.h Thu Oct 09 12:22:02 2008 +0000 +++ b/data/model/ModelDataTableModel.h Thu Oct 09 13:13:33 2008 +0000 @@ -63,10 +63,12 @@ void frameSelected(size_t); void addCommand(Command *); void currentChanged(const QModelIndex &); + void modelRemoved(); protected slots: void modelChanged(); void modelChanged(size_t, size_t); + void modelAboutToBeDeleted(); protected: TabularModel *m_model;
--- a/transform/FeatureExtractionModelTransformer.cpp Thu Oct 09 12:22:02 2008 +0000 +++ b/transform/FeatureExtractionModelTransformer.cpp Thu Oct 09 13:13:33 2008 +0000 @@ -633,15 +633,21 @@ } else if (isOutput<SparseTimeValueModel>()) { - float value = 0.0; - if (feature.values.size() > 0) value = feature.values[0]; - SparseTimeValueModel *model = getConformingOutput<SparseTimeValueModel>(); if (!model) return; - model->addPoint(SparseTimeValueModel::Point - (frame, value, feature.label.c_str())); + for (int i = 0; i < feature.values.size(); ++i) { + + float value = feature.values[i]; + + QString label = feature.label.c_str(); + if (feature.values.size() > 1) { + label = QString("[%1] %2").arg(i+1).arg(label); + } + + model->addPoint(SparseTimeValueModel::Point(frame, value, label)); + } } else if (isOutput<NoteModel>() || isOutput<RegionModel>()) { @@ -678,11 +684,29 @@ feature.label.c_str())); } else { RegionModel *model = getConformingOutput<RegionModel>(); - if (model) { + if (!model) return; + + if (feature.hasDuration) { + + for (int i = 0; i < feature.values.size(); ++i) { + + float value = feature.values[i]; + + QString label = feature.label.c_str(); + if (feature.values.size() > 1) { + label = QString("[%1] %2").arg(i+1).arg(label); + } + + model->addPoint(RegionModel::Point(frame, value, + lrintf(duration), + label)); + } + } else { + model->addPoint(RegionModel::Point(frame, value, lrintf(duration), feature.label.c_str())); - } else return; + } } } else if (isOutput<EditableDenseThreeDimensionalModel>()) {