very basic, but safe putting down " "

actorid
Marek Kochanowicz 11 years ago
parent 17af865a9f
commit 3cc23a9cb3

@ -1,6 +1,10 @@
#include "scriptedit.hpp"
#include <algorithm>
#include <QDragEnterEvent>
#include <QRegExp>
#include <QString>
#include "../../model/world/universalid.hpp"
#include "../../model/world/tablemimedata.hpp"
@ -64,8 +68,21 @@ void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event)
{
if (mAllowedTypes.contains (it->getType()))
{
QString::fromStdString ('"' + it->getId() + '"');
if (stringNeedsQuote(it->getId()))
{
insertPlainText(QString::fromStdString ('"' + it->getId() + '"'));
} else {
insertPlainText(QString::fromStdString (it->getId()));
}
}
}
}
}
}
bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id)
{
QString string(QString::fromStdString(id)); //<regex> is only for c++11, so let's use qregexp for now.
//I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
QRegExp regexp("^[a-z]{1}[a-z|0-9]{0,}$", Qt::CaseInsensitive);
return !(string.contains(regexp));
}

@ -30,6 +30,8 @@ namespace CSVWorld
void dropEvent (QDropEvent* event);
void dragMoveEvent (QDragMoveEvent* event);
bool stringNeedsQuote(const std::string& id);
};
}
#endif // SCRIPTEDIT_H
Loading…
Cancel
Save