Validate motif input
[mussa.git] / 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;