本文整理汇总了C++中QRegExp类的典型用法代码示例。如果您正苦于以下问题:C++ QRegExp类的具体用法?C++ QRegExp怎么用?C++ QRegExp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QRegExp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isSameFormat
bool DocumentNumeratorController::isSameFormat()
{
QRegExp rx;
rx.setPattern(formatPattern);
return rx.exactMatch(previousSymbolStr);
}
示例2: subgroup
bool StyleData::setStyle(const char* s, const char* styleName)
{
static const QRegExp subgroup("^{[^}]*}\\s*");
static const QRegExp any_clause("^\\\\[a-z][a-z0-9-]*\\s*");
int len = 0; // length of a particular RTF formatting control
int ref_len = 0; // length of the whole formatting section of a style
int start = s_clause.match(s, 0, &len);
if (start < 0)
{
err("Style sheet '%s' contains no '\\s' clause.\n{%s}\n", styleName, s);
return FALSE;
}
s += start;
index = (int)atol(s + 2); ASSERT(index > 0);
// search for the end of pure formatting codes
const char* end = s + len;
ref_len = len;
bool haveNewDefinition = TRUE;
for(;;)
{
if (*end == '{')
{
// subgroups are used for \\additive
if (0 != subgroup.match(end, 0, &len))
break;
else
{
end += len;
ref_len += len;
}
}
else if (*end == '\\')
{
if (0 == qstrncmp(end, "\\snext", 6))
break;
if (0 == qstrncmp(end, "\\sbasedon", 9))
break;
if (0 != any_clause.match(end, 0, &len))
break;
end += len;
ref_len += len;
}
else if (*end == 0)
{ // no style-definition part, keep default value
haveNewDefinition = FALSE;
break;
}
else // plain name without leading \\snext
break;
}
delete[] reference;
reference = new char[ref_len + 1];
memcpy(reference, s, ref_len);
reference[ref_len] = 0;
if (haveNewDefinition)
{
delete[] definition;
size_t size = 1 + strlen(end);
definition = new char[size];
memcpy(definition, end, size);
}
return TRUE;
}
示例3: parseGenerics
// -------------------------------------------------------
QString VHDL_File_Info::parseGenerics(QString s, int j)
{
QRegExp Expr;
Expr.setCaseSensitive(false);
int i, p, l, k, n;
Expr.setPattern("\\bgeneric\\b");
i = s.find(Expr, j+1);
if(i < 0)
return QString("");
// find opening (
i = s.find('(', i+4) + 1;
if(i <= 0)
return QString("");
// find closing (
p = i;
j = i-1;
do {
j = s.find(')', j+1);
if(j < 0)
return QString("");
p = s.find('(', p+1);
if(p >= 0 && p > j) p = -1;
} while (p >= 0);
s = s.mid(i, j-i);
s.remove('\n');
s.remove('\t');
// find generic names, types and defaults in parameter specification
l = i = 0;
QString types = "", t, defs = "", d;
while((i=s.find(':', i)) >= 0) {
j = s.find(';', i+2);
n = s.find(":=", i+2);
d = "";
if(n >= 0 && (n < j || j < 0) ) {
j = s.find(';', n+2);
if(j < 0) {
d = s.mid(n+2);
d = d.simplifyWhiteSpace();
s = s.left(n);
} else {
d = s.mid(n+2, j-n-1);
d.remove(';');
d = d.simplifyWhiteSpace();
s.remove(n, j-n);
}
j = s.find(';', n);
}
if(j < 0) {
t = s.mid(i+1);
t.remove(';');
t = t.simplifyWhiteSpace();
s = s.left(i);
} else {
t = s.mid(i+1, j-i);
t.remove(';');
t = t.simplifyWhiteSpace();
s.remove(i, j-i);
}
if ((k = t.find(' ')) >= 0)
t = t.mid(k+1);
t = t.simplifyWhiteSpace();
k = s.find(';',l+2);
k = (s.mid(l,k-l).count(',')) + 1;
while (k-->0) {
types = types + t + ",";
defs = defs + d + ",";
}
i--;
l = i;
}
s.remove(' ');
s.replace(';', ',');
GenTypes=types=types.left(types.length()-1);
GenDefs=defs=defs.left(defs.length()-1);
return s;
}
示例4: idContainsWrongLetter
static bool idContainsWrongLetter(const QString& id)
{
static QRegExp idExpr(QStringLiteral("[a-z_][a-zA-Z0-9_]*"));
return !idExpr.exactMatch(id);
}
示例5: QRegExp
void AlbumPropsEdit::slotTitleChanged(const QString& newtitle)
{
QRegExp emptyTitle = QRegExp("^\\s*$");
bool enable = (!emptyTitle.exactMatch(newtitle) && !newtitle.isEmpty());
enableButtonOk(enable);
}
示例6: f
// -------------------------------------------------------
VHDL_File_Info::VHDL_File_Info(QString File, bool isfile)
{
if (isfile) {
QFile f(File);
if(!f.open(QIODevice::ReadOnly))
File = "";
else {
QByteArray FileContent = f.readAll();
File = QString(FileContent);
}
f.close();
}
QString s;
PortNames = "";
int i=0, j, k=0;
while((i=File.find("--", i)) >= 0) { // remove all VHDL comments
j = File.find('\n', i+2); // This also finds "--" within a ...
if(j < 0) // string, but as no strings are ...
File = File.left(i); // allowed in entity headers, it ...
else // does not matter.
File.remove(i, j-i);
}
QRegExp Expr;
Expr.setCaseSensitive(false);
for(;;) {
k--;
Expr.setPattern("\\bentity\\b"); // start of last entity
k = File.findRev(Expr, k);
if(k < 0)
return;
Expr.setPattern("\\bend\\b"); // end of last entity
i = File.find(Expr, k+7);
if(i < 0)
return;
s = File.mid(k+7, i-k-7); // cut out entity declaration
Expr.setPattern("\\b");
i = s.find(Expr);
if(i < 0)
return;
j = s.find(Expr, i+1);
if(j < 0)
return;
EntityName = s.mid(i, j-i); // save entity name
i = s.find(Expr, j+1);
if(i < 0)
return;
j = s.find(Expr, i+1);
if(j < 0)
return;
if(s.mid(i, j-i).lower() == "is") // really found start of entity ?
break;
if(k < 1) // already searched the whole text
return;
}
// parse ports, i.e. network connections; and generics, i.e. parameters
GenNames = parseGenerics(s,j);
PortNames = parsePorts(s,j);
}
示例7: defined
QgsProviderRegistry::QgsProviderRegistry( const QString& pluginPath )
{
// At startup, examine the libs in the qgis/lib dir and store those that
// are a provider shared lib
// check all libs in the current plugin directory and get name and descriptions
//TODO figure out how to register and identify data source plugin for a specific
//TODO layer type
#if 0
char **argv = qApp->argv();
QString appDir = argv[0];
int bin = appDir.findRev( "/bin", -1, false );
QString baseDir = appDir.left( bin );
QString mLibraryDirectory = baseDir + "/lib";
#endif
mLibraryDirectory = pluginPath;
mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
#if defined(Q_OS_WIN) || defined(__CYGWIN__)
mLibraryDirectory.setNameFilters( QStringList( "*.dll" ) );
#elif ANDROID
mLibraryDirectory.setNameFilters( QStringList( "*provider.so" ) );
#else
mLibraryDirectory.setNameFilters( QStringList( "*.so" ) );
#endif
QgsDebugMsg( QString( "Checking %1 for provider plugins" ).arg( mLibraryDirectory.path() ) );
if ( mLibraryDirectory.count() == 0 )
{
QString msg = QObject::tr( "No QGIS data provider plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() );
msg += QObject::tr( "No vector layers can be loaded. Check your QGIS installation" );
QgsMessageOutput* output = QgsMessageOutput::createMessageOutput();
output->setTitle( QObject::tr( "No Data Providers" ) );
output->setMessage( msg, QgsMessageOutput::MessageText );
output->showMessage();
return;
}
// provider file regex pattern, only files matching the pattern are loaded if the variable is defined
QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
QRegExp fileRegexp;
if ( !filePattern.isEmpty() )
{
fileRegexp.setPattern( filePattern );
}
QListIterator<QFileInfo> it( mLibraryDirectory.entryInfoList() );
while ( it.hasNext() )
{
QFileInfo fi( it.next() );
if ( !fileRegexp.isEmpty() )
{
if ( fileRegexp.indexIn( fi.fileName() ) == -1 )
{
QgsDebugMsg( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern );
continue;
}
}
QLibrary myLib( fi.filePath() );
if ( !myLib.load() )
{
QgsDebugMsg( QString( "Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName() ).arg( myLib.errorString() ) );
continue;
}
//MH: Added a further test to detect non-provider plugins linked to provider plugins.
//Only pure provider plugins have 'type' not defined
isprovider_t *hasType = ( isprovider_t * ) cast_to_fptr( myLib.resolve( "type" ) );
if ( hasType )
{
QgsDebugMsg( QString( "Checking %1: ...invalid (has type method)" ).arg( myLib.fileName() ) );
continue;
}
// get the description and the key for the provider plugin
isprovider_t *isProvider = ( isprovider_t * ) cast_to_fptr( myLib.resolve( "isProvider" ) );
if ( !isProvider )
{
QgsDebugMsg( QString( "Checking %1: ...invalid (no isProvider method)" ).arg( myLib.fileName() ) );
continue;
}
// check to see if this is a provider plugin
if ( !isProvider() )
{
QgsDebugMsg( QString( "Checking %1: ...invalid (not a provider)" ).arg( myLib.fileName() ) );
continue;
}
// looks like a provider. get the key and description
description_t *pDesc = ( description_t * ) cast_to_fptr( myLib.resolve( "description" ) );
if ( !pDesc )
{
QgsDebugMsg( QString( "Checking %1: ...invalid (no description method)" ).arg( myLib.fileName() ) );
continue;
}
//.........这里部分代码省略.........
示例8: applyCommentStyle
void ScenarioHighlighter::applyCommentStyle(const QString &, const QRegExp ®)
{
this->setFormat(0, reg.cap(0).size(), QColor("#228b22"));
this->setCurrentBlockState(STATE_COMMENT);
}
示例9: previousBlockState
void SourceHighlighter::highlightBlock(const QString &text)
{
int state = previousBlockState();
int len = text.length();
int start = 0;
int pos = 0;
QRegExp regex;
while (pos >= 0 && pos < len && len > 0) {
switch (state) {
default:
case Normal:
regex.setPattern(QLatin1String("[<&]"));
pos = regex.indexIn(text, pos);
if (pos >= 0) {
if (text.at(pos) == QLatin1Char('<')) {
start = pos;
if (text.mid(pos, 4) == QLatin1String("<!--")) {
state = InComment;
} else {
state = InTag;
}
++pos;
} else if (text.at(pos) == QLatin1Char('&')) {
regex.setPattern(QLatin1String("&[a-zA-Z0-9]+;"));
if (regex.indexIn(text, pos) == pos) {
setFormat(pos, regex.matchedLength(), formats[Entity]);
}
++pos;
}
}
break;
case InComment:
regex.setPattern(QLatin1String("-->"));
pos = regex.indexIn(text, pos);
if (pos >= 0) {
state = Normal;
pos += 3;
setFormat(start, pos - start, formats[Comment]);
++pos;
} else {
setFormat(start, len - start, formats[Comment]);
}
break;
case InTag:
regex.setPattern(QLatin1String("[>\"]"));
pos = regex.indexIn(text, pos);
if (pos >= 0) {
if (text.at(pos) == QLatin1Char('>')) {
state = Normal;
++pos;
setFormat(start, pos - start, formats[Tag]);
} else if (text.at(pos) == QLatin1Char('"')) {
setFormat(start, pos - start, formats[Tag]);
start = pos;
state = InAttribute;
++pos;
}
} else {
setFormat(start, len-start, formats[Tag]);
}
break;
case InAttribute:
regex.setPattern(QLatin1String("\""));
pos = regex.indexIn(text, pos);
if (pos >= 0) {
setFormat(start, pos - start, formats[Attribute]);
state = InTag;
start = ++pos;
} else {
setFormat(start, len - start, formats[Attribute]);
}
break;
}
}
setCurrentBlockState(state);
}
示例10: config
bool StringReplacerProc::init(KConfig* c, const QString& configGroup){
//kDebug() << "StringReplacerProc::init: Running";
QString wordsFilename =
KGlobal::dirs()->saveLocation( "data" ,QLatin1String( "kttsd/stringreplacer/" ), false );
if ( wordsFilename.isEmpty() ) return false;
wordsFilename += configGroup;
KConfigGroup config( c, configGroup );
wordsFilename = config.readEntry( "WordListFile", wordsFilename );
// Open existing word list.
QFile file( wordsFilename );
if ( !file.open( QIODevice::ReadOnly ) )
{
//kDebug() << "StringReplacerProc::init: couldn't open file " << wordsFilename;
return false;
}
QDomDocument doc( QLatin1String( "" ) );
if ( !doc.setContent( &file ) ) {
//kDebug() << "StringReplacerProc::init: couldn't get xml from file " << wordsFilename;
file.close();
return false;
}
file.close();
// Clear list.
m_matchList.clear();
m_substList.clear();
// Name setting.
// QDomNodeList nameList = doc.elementsByTagName( "name" );
// QDomNode nameNode = nameList.item( 0 );
// m_widget->nameLineEdit->setText( nameNode.toElement().text() );
// Language Codes setting. List may be single element of comma-separated values,
// or multiple elements.
m_languageCodeList.clear();
QDomNodeList languageList = doc.elementsByTagName( QLatin1String( "language-code" ) );
for ( int ndx=0; ndx < languageList.count(); ++ndx )
{
QDomNode languageNode = languageList.item( ndx );
m_languageCodeList += languageNode.toElement().text().split( QLatin1Char(','), QString::SkipEmptyParts);
}
// AppId. Apply this filter only if DCOP appId of application that queued
// the text contains this string. List may be single element of comma-separated values,
// or multiple elements.
m_appIdList.clear();
QDomNodeList appIdList = doc.elementsByTagName( QLatin1String( "appid" ) );
for ( int ndx=0; ndx < appIdList.count(); ++ndx )
{
QDomNode appIdNode = appIdList.item( ndx );
m_appIdList += appIdNode.toElement().text().split( QLatin1Char( ',' ), QString::SkipEmptyParts);
}
// Word list.
QDomNodeList wordList = doc.elementsByTagName(QLatin1String( "word" ) );
const int wordListCount = wordList.count();
for (int wordIndex = 0; wordIndex < wordListCount; ++wordIndex)
{
QDomNode wordNode = wordList.item(wordIndex);
QDomNodeList propList = wordNode.childNodes();
QString wordType;
QString matchCase = QLatin1String( "No" ); // Default for old (v<=3.5.3) config files with no <case/>.
QString match;
QString subst;
const int propListCount = propList.count();
for (int propIndex = 0; propIndex < propListCount; ++propIndex)
{
QDomNode propNode = propList.item(propIndex);
QDomElement prop = propNode.toElement();
if (prop.tagName() == QLatin1String( "type" )) wordType = prop.text();
if (prop.tagName() == QLatin1String( "case" )) matchCase = prop.text();
if (prop.tagName() == QLatin1String( "match" ))
{
match = prop.text();
cdataUnescape( &match );
}
if (prop.tagName() == QLatin1String( "subst" ))
{
subst = prop.text();
cdataUnescape( &subst );
}
}
// Build Regular Expression for each word's match string.
QRegExp rx;
rx.setCaseSensitivity(matchCase == QLatin1String( "Yes" )?Qt::CaseInsensitive:Qt::CaseSensitive);
if ( wordType == QLatin1String( "Word" ) )
{
// TODO: Does \b honor strange non-Latin1 encodings?
rx.setPattern( QLatin1String( "\\b" ) + match + QLatin1String( "\\b" ) );
}
else
{
rx.setPattern( match );
}
// Add Regular Expression to list (if valid).
if ( rx.isValid() )
{
m_matchList.append( rx );
m_substList.append( subst );
//.........这里部分代码省略.........
示例11: clearConfiguration
void SyntaxHighlighter::loadConfiguration(const QString &filename)
{
if(filename!="")
{
attribs_map attribs;
QString elem, expr_type, group;
bool groups_decl=false, chr_sensitive=false,
bold=false, italic=false,
underline=false, partial_match=false;
QTextCharFormat format;
QRegExp regexp;
QColor bg_color, fg_color;
vector<QString>::iterator itr, itr_end;
try
{
clearConfiguration();
XMLParser::restartParser();
XMLParser::setDTDFile(GlobalAttributes::CONFIGURATIONS_DIR +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::OBJECT_DTD_DIR +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::CODE_HIGHLIGHT_CONF +
GlobalAttributes::OBJECT_DTD_EXT,
GlobalAttributes::CODE_HIGHLIGHT_CONF);
XMLParser::loadXMLFile(filename);
if(XMLParser::accessElement(XMLParser::CHILD_ELEMENT))
{
do
{
if(XMLParser::getElementType()==XML_ELEMENT_NODE)
{
elem=XMLParser::getElementName();
if(elem==ParsersAttributes::WORD_SEPARATORS)
{
XMLParser::getElementAttributes(attribs);
word_separators=attribs[ParsersAttributes::VALUE];
}
else if(elem==ParsersAttributes::WORD_DELIMITERS)
{
XMLParser::getElementAttributes(attribs);
word_delimiters=attribs[ParsersAttributes::VALUE];
}
else if(elem==ParsersAttributes::IGNORED_CHARS)
{
XMLParser::getElementAttributes(attribs);
ignored_chars=attribs[ParsersAttributes::VALUE];
}
else if(elem==ParsersAttributes::COMPLETION_TRIGGER)
{
XMLParser::getElementAttributes(attribs);
if(attribs[ParsersAttributes::VALUE].size() >= 1)
completion_trigger=attribs[ParsersAttributes::VALUE].at(0);
}
/* If the element is what defines the order of application of the groups
highlight in the (highlight-order). Is in this block that are declared
the groups used to highlight the source code. ALL groups
in this block must be declared before they are built
otherwise an error will be triggered. */
else if(elem==ParsersAttributes::HIGHLIGHT_ORDER)
{
//Marks a flag indication that groups are being declared
groups_decl=true;
XMLParser::savePosition();
XMLParser::accessElement(XMLParser::CHILD_ELEMENT);
elem=XMLParser::getElementName();
}
if(elem==ParsersAttributes::GROUP)
{
XMLParser::getElementAttributes(attribs);
group=attribs[ParsersAttributes::NAME];
/* If the parser is on the group declaration block and not in the build block
some validations are made. */
if(groups_decl)
{
//Raises an error if the group was declared before
if(find(groups_order.begin(), groups_order.end(), group)!=groups_order.end())
{
throw Exception(Exception::getErrorMessage(ERR_REDECL_HL_GROUP).arg(group),
ERR_REDECL_HL_GROUP,__PRETTY_FUNCTION__,__FILE__,__LINE__);
}
//Raises an error if the group is being declared and build at the declaration statment (not permitted)
else if(attribs.size() > 1 || XMLParser::hasElement(XMLParser::CHILD_ELEMENT))
{
throw Exception(Exception::getErrorMessage(ERR_DEF_INV_GROUP_DECL)
.arg(group).arg(ParsersAttributes::HIGHLIGHT_ORDER),
ERR_REDECL_HL_GROUP,__PRETTY_FUNCTION__,__FILE__,__LINE__);
}
groups_order.push_back(group);
}
//Case the parser is on the contruction block and not in declaration of groups
else
//.........这里部分代码省略.........
示例12: while
QString SyntaxHighlighter::identifyWordGroup(const QString &word, const QChar &lookahead_chr, int idx, int &match_idx, int &match_len)
{
QRegExp expr;
vector<QString>::iterator itr, itr_end;
vector<QRegExp>::iterator itr_exp, itr_exp_end;
vector<QRegExp> *vet_expr=nullptr;
QString group;
bool match=false, part_mach=false;
MultiLineInfo *info=nullptr;
//Try to get the multiline info for the current block
info=getMultiLineInfo(idx, idx, current_block);
/* Case the highlighter is in the middle of a multiline code block,
a different action is executed: check if the current word does not
matches with one of final expresion of the group indicating that the
group highlighting must be interrupted after the current word */
if(info)
{
group=info->group;
//Checking if the word is not a highlight ending for the group
itr_exp=final_exprs[group].begin();
itr_exp_end=final_exprs[group].end();
part_mach=partial_match[group];
while(itr_exp!=itr_exp_end && !match)
{
expr=(*itr_exp);
if(part_mach)
{
match_idx=word.indexOf(expr);
match_len=expr.matchedLength();
match=(match_idx >= 0);
}
else
{
if(expr.patternSyntax()==QRegExp::FixedString)
match=((expr.pattern().compare(word, expr.caseSensitivity())==0));
else
match=expr.exactMatch(word);
if(match)
{
match_idx=0;
match_len=word.length();
}
}
if(match && lookahead_char.count(group) > 0 && lookahead_chr!=lookahead_char.at(group))
match=false;
itr_exp++;
}
/* If the word matches configures a multiline info with the
values retrieved from the regexp matching */
if(match)
{
info->end_col=idx + match_idx + match_len-1;
info->end_block=current_block;
}
else
{
match_idx=0;
match_len=word.length();
}
return(group);
}
else
{
itr=groups_order.begin();
itr_end=groups_order.end();
while(itr!=itr_end && !match)
{
group=(*itr);
vet_expr=&initial_exprs[group];
itr++;
itr_exp=vet_expr->begin();
itr_exp_end=vet_expr->end();
part_mach=partial_match[group];
while(itr_exp!=itr_exp_end && !match)
{
expr=(*itr_exp);
if(part_mach)
{
match_idx=word.indexOf(expr);
match_len=expr.matchedLength();
match=(match_idx >= 0);
}
else
{
if(expr.patternSyntax()==QRegExp::FixedString)
match=((expr.pattern().compare(word, expr.caseSensitivity())==0));
//.........这里部分代码省略.........
示例13: QRegExp
// Check if the current block is inside a "here document" and format it accordingly.
bool Highlighter::isHereDocument (const QString &text)
{
QTextCharFormat blockFormat;
blockFormat.setForeground (QColor (126, 0, 230));
QTextCharFormat delimFormat = blockFormat;
delimFormat.setFontWeight (QFont::Bold);
QString delimStr;
/* Kate uses something like "<<(?:\\s*)([\\\\]{,1}[^\\s]+)" */
QRegExp delim = QRegExp ("<<(?:\\s*)([\\\\]{,1}[A-Za-z0-9_]+)|<<(?:\\s*)(\'[A-Za-z0-9_]+\')|<<(?:\\s*)(\"[A-Za-z0-9_]+\")");
int pos, i;
/* format the start delimiter */
if (previousBlockState() != delimState - 1
&& currentBlockState() != delimState - 1
&& (pos = delim.indexIn (text)) >= 0)
{
i = 1;
while ((delimStr = delim.cap (i)).isEmpty() && i <= 3)
{
++i;
delimStr = delim.cap (i);
}
/* remove quotes */
if (delimStr.contains ('\''))
delimStr = delimStr.split ('\'').at (1);
if (delimStr.contains ('\"'))
delimStr = delimStr.split ('\"').at (1);
/* remove the start backslash if it exists */
if (QString (delimStr.at (0)) == "\\")
delimStr = delimStr.remove (0, 1);
if (!delimStr.isEmpty())
{
setCurrentBlockState (delimState);
setFormat (text.indexOf (delimStr, pos),
delimStr.length(),
delimFormat);
TextBlockData *data = static_cast<TextBlockData *>(currentBlock().userData());
data->insertInfo (delimStr);
data->insertInfo (true);
setCurrentBlockUserData (data);
return false;
}
}
if (previousBlockState() == delimState - 1 || previousBlockState() == delimState)
{
QTextBlock block = currentBlock().previous();
TextBlockData *data = static_cast<TextBlockData *>(block.userData());
delimStr = data->delimiter();
if (text == delimStr
|| (text.startsWith (delimStr)
&& text.indexOf (QRegExp ("\\s+")) == delimStr.length()))
{
/* format the end delimiter */
setFormat (0,
delimStr.length(),
delimFormat);
/* we need this in docChanged() */
data = static_cast<TextBlockData *>(currentBlock().userData());
data->insertInfo (true);
setCurrentBlockUserData (data);
return false;
}
else
{
/* format the contents */
TextBlockData *data = static_cast<TextBlockData *>(currentBlock().userData());
data->insertInfo (delimStr);
setCurrentBlockUserData (data);
setCurrentBlockState (delimState - 1);
setFormat (0, text.length(), blockFormat);
return true;
}
}
return false;
}
示例14: file
void ScriptExtender::scanFile(const QString& filename){
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text )){
qDebug() << "Error launching script";
return;
}
QString in = file.readAll();
QRegExp rx;
rx = QRegExp( "<FILTER>(.+)</FILTER>" );
rx.setMinimal(true);
if (!rx.indexIn(in,0))return;
QString filter = rx.cap(1);
//for each found function
rx = QRegExp( "<FUNCTION>(.+)</FUNCTION>" );
rx.setMinimal(true);
for (int pos = 0; (pos = rx.indexIn(in, pos)) != -1; pos += rx.matchedLength()) {
QStringList split = rx.cap(1).split(" ");
switch (split.size()){
case 1:
slotlist << SSlot("",split.at(0), slotlist.size(), QRegExp(filter),filename );
break;
case 2:
slotlist << SSlot(split.at(0), split.at(1),slotlist.size(), QRegExp(filter),filename );
break;
default:
qDebug() << "<FUNCTION>....</FUNCTION> with illegal content";
}
}
rx = QRegExp( "<ACTION>(.+)</ACTION>" );
rx.setMinimal(true);
for (int pos = 0; (pos = rx.indexIn(in, pos)) != -1; pos += rx.matchedLength()) {
QRegExp tx;
tx = QRegExp( "<TEXT>(.+)</TEXT>" );
if (!tx.indexIn(rx.cap(1),0))return;
QString text = tx.cap(1);
tx = QRegExp( "<SLOT>(.+)</SLOT>" );
if (!tx.indexIn(rx.cap(1),0))return;
QString slot = tx.cap(1);
const char** icon = xpm(rx.cap(1));
actionlist << SAction(icon,text,QString("1%1").arg(slot),QRegExp(filter));
}
//qDebug() << " sssssss" << SLOT(test());
}
示例15: QLineEdit
QWidget *VariantDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & /* option */,
const QModelIndex &index) const
{
if (index.column() != 2)
return 0;
QVariant originalValue = index.model()->data(index, Qt::UserRole);
if (!isSupportedType(originalValue.type()))
return 0;
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
QRegExp regExp;
switch (originalValue.type()) {
case QVariant::Bool:
regExp = boolExp;
break;
case QVariant::ByteArray:
regExp = byteArrayExp;
break;
case QVariant::Char:
regExp = charExp;
break;
case QVariant::Color:
regExp = colorExp;
break;
case QVariant::Date:
regExp = dateExp;
break;
case QVariant::DateTime:
regExp = dateTimeExp;
break;
case QVariant::Double:
regExp = doubleExp;
break;
case QVariant::Int:
case QVariant::LongLong:
regExp = signedIntegerExp;
break;
case QVariant::Point:
regExp = pointExp;
break;
case QVariant::Rect:
regExp = rectExp;
break;
case QVariant::Size:
regExp = sizeExp;
break;
case QVariant::Time:
regExp = timeExp;
break;
case QVariant::UInt:
case QVariant::ULongLong:
regExp = unsignedIntegerExp;
break;
default:
;
}
if (!regExp.isEmpty()) {
QValidator *validator = new QRegExpValidator(regExp, lineEdit);
lineEdit->setValidator(validator);
}
return lineEdit;
}