diff data/model/ModelDataTableModel.cpp @ 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 7226ebac8bd3
children b1dc68507e46
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;