make subanalysis window editable
authorDiane Trout <diane@caltech.edu>
Sat, 1 Jul 2006 04:40:58 +0000 (04:40 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 1 Jul 2006 04:40:58 +0000 (04:40 +0000)
one can now edit the left and right sequence positions for the subanalysis
mode.

qui/SequenceLocationModel.cpp
qui/SequenceLocationModel.hpp

index f724596e431438f6682cb063c46849e76dc2c766..f0c4d252c0c86514d903e038b3af78df2db11fc3 100644 (file)
@@ -160,4 +160,46 @@ SequenceLocationModel::headerData(
   return QVariant();
 }
 
+bool SequenceLocationModel::setData(
+   const QModelIndex& index, 
+   const QVariant &value, 
+   int role
+)
+{
+   bool isInt;
+   int intValue(value.toInt(&isInt));
+   if (index.isValid() and role == Qt::EditRole and isInt) {
+    SequenceLocation& location = sequence_locations[index.row()];
+    switch(index.column()) {
+      case 0:
+        return false;
+        break;
+      case 1:
+        location.setLeft(intValue);
+        break;
+      case 2:
+        location.setRight(intValue);
+        break;
+      default:
+        return false;
+        break;
+    }
+    emit dataChanged(index, index);
+    return true;
+  } else {
+    return false;
+  }
+}
+
+Qt::ItemFlags SequenceLocationModel::flags(const QModelIndex& index) const
+{
+  if (!index.isValid())
+    return Qt::ItemIsEnabled;
+
+  // first column is not editable
+  if (index.column() == 0)
+    return QAbstractItemModel::flags(index);
+  else
+    return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+}
 
index 7a4b0e782b80079808fc32b74a08e7d86adac750..6b6a924e37616baf9a051ce42765c879c79fd165 100644 (file)
@@ -56,13 +56,13 @@ class SequenceLocationModel : public QAbstractTableModel
 
     QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const;
 
-    //bool setData(const QModelIndex& index, const QVariant &value, 
-    //             int role=Qt::EditRole);
-    //Qt::ItemFlags flags(const QModelIndex& index) const;
+    bool setData(const QModelIndex& index, const QVariant &value, 
+                 int role=Qt::EditRole);
+    Qt::ItemFlags flags(const QModelIndex& index) const;
 
     //bool insertRows(int row, int count, 
     //                const QModelIndex& parent=QModelIndex());
-    //bool removeRows(int row, int count);
+    //bool removeRows(int row, int count,
     //                const QModelIndex& parent=QModelIndex());
     //! \@}
   private: