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
#include <QKeyEvent>
#include <QLineEdit>
#include <QPainter>
#include <QKeyEvent>
#include <QLineEdit>
#include <QPainter>
+#include <QRegExp>
+#include <QRegExpValidator>
MotifEditorDelegate::MotifEditorDelegate(QWidget *parent) :
QItemDelegate(parent)
MotifEditorDelegate::MotifEditorDelegate(QWidget *parent) :
QItemDelegate(parent)
const QStyleOptionViewItem & /* option */,
const QModelIndex &index) const
{
const QStyleOptionViewItem & /* option */,
const QModelIndex &index) const
{
+ 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:
switch(index.column()) {
// case MotifModel::EnabledCell is handled in editorEvent
// case MotifModel::ColorCell:
- // both of these should be text boxes
case MotifModel::NameCell:
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));
case MotifModel::SequenceCell:
widget = new QLineEdit(parent);
widget->installEventFilter(const_cast<MotifEditorDelegate*>(this));
+ regex_validator = new QRegExpValidator(iupac, parent);
+ widget->setValidator(regex_validator);