From: Diane Trout Date: Wed, 11 Oct 2006 22:52:45 +0000 (+0000) Subject: Validate motif input X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=4127868f4da4a6a87842d637e621724320aefcf2 Validate motif input 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 --- diff --git a/qui/motif_editor/MotifEditorDelegate.cpp b/qui/motif_editor/MotifEditorDelegate.cpp index 61c5713..afc2dcd 100644 --- a/qui/motif_editor/MotifEditorDelegate.cpp +++ b/qui/motif_editor/MotifEditorDelegate.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include 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(this)); + regex_validator = new QRegExpValidator(no_quotes, parent); + widget->setValidator(regex_validator); + break; case MotifModel::SequenceCell: widget = new QLineEdit(parent); widget->installEventFilter(const_cast(this)); + regex_validator = new QRegExpValidator(iupac, parent); + widget->setValidator(regex_validator); break; default: break;