Validate motif input
authorDiane Trout <diane@caltech.edu>
Wed, 11 Oct 2006 22:52:45 +0000 (22:52 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 11 Oct 2006 22:52:45 +0000 (22:52 +0000)
ticket:149
To reduce the chances that someone will manage to make an unloadable
motif file, prevent the user from entering bad data.
e.g. " in motif names, or non-iupac symbols in the sequence in
MotifEditorDelegate::createEditor

qui/motif_editor/MotifEditorDelegate.cpp

index 61c5713c969240804dab0c17e7cd23a897f7c294..afc2dcd9ee38eb803ea451208dd3e07a5584977c 100644 (file)
@@ -7,6 +7,8 @@
 #include <QKeyEvent>
 #include <QLineEdit>
 #include <QPainter>
+#include <QRegExp>
+#include <QRegExpValidator>
 
 MotifEditorDelegate::MotifEditorDelegate(QWidget *parent) :
   QItemDelegate(parent)
@@ -18,15 +20,25 @@ QWidget *MotifEditorDelegate::createEditor(
   const QStyleOptionViewItem & /* option */,
   const QModelIndex &index) const
 {
-  QWidget *widget = 0;
+  static const QRegExp no_quotes("[^\"]*");
+  // grabbed from Alphabet::nucleic_alphabet
+  static const QRegExp iupac("[AaCcGgTtUuRrYyMmKkSsWwBbDdHhVvNn-~.?]*");
+  QRegExpValidator *regex_validator;
+  QLineEdit *widget = 0;
   switch(index.column()) {
     // case MotifModel::EnabledCell is handled in editorEvent
     // case MotifModel::ColorCell:
-    // both of these should be text boxes
     case MotifModel::NameCell:
+      widget = new QLineEdit(parent);
+      widget->installEventFilter(const_cast<MotifEditorDelegate*>(this));
+      regex_validator = new QRegExpValidator(no_quotes, parent);
+      widget->setValidator(regex_validator);
+      break;
     case MotifModel::SequenceCell:
       widget = new QLineEdit(parent);
       widget->installEventFilter(const_cast<MotifEditorDelegate*>(this));
+      regex_validator = new QRegExpValidator(iupac, parent);
+      widget->setValidator(regex_validator);
       break;
     default:
       break;