Exemple #1
0
QStringList::iterator
CLArgsPrivate::hasOutputToken(QString& indexStr)
{
    QString outputLong( QString::fromUtf8("--output") );
    QString outputShort( QString::fromUtf8("-o") );

    for (QStringList::iterator it = args.begin(); it != args.end(); ++it) {
        int indexOf = it->indexOf(outputLong);
        if (indexOf != -1) {
            indexOf += outputLong.size();
            if ( indexOf < it->size() ) {
                indexStr = it->mid(indexOf);
                bool ok;
                indexStr.toInt(&ok);
                if (!ok) {
                    error = 1;
                    std::cout << QObject::tr("Wrong formating for the -o option").toStdString() << std::endl;

                    return args.end();
                }
            } else {
                indexStr = QChar::fromLatin1('1');
            }

            return it;
        } else {
            indexOf = it->indexOf(outputShort);
            if (indexOf != -1) {
                if ( (it->size() > 2) && !it->at(2).isDigit() ) {
                    //This is probably the --onload option
                    return args.end();
                }
                indexOf += outputShort.size();
                if ( indexOf < it->size() ) {
                    indexStr = it->mid(indexOf);
                    bool ok;
                    indexStr.toInt(&ok);
                    if (!ok) {
                        error = 1;
                        std::cout << QObject::tr("Wrong formating for the -o option").toStdString() << std::endl;

                        return args.end();
                    }
                } else {
                    indexStr = QChar::fromLatin1('1');
                }

                return it;
            }
        }
    }

    return args.end();
} // CLArgsPrivate::hasOutputToken
Exemple #2
0
QString MainWindow::searchFreeNumber(QList<QString> sl, QString word)
{
    int number = 0;
    QStringList::iterator elem = sl.begin();
    while (elem != sl.end()) {
        QStringRef l = elem->leftRef(word.size());
        if (l == word) {
         QStringRef r = elem->rightRef(elem->size() - word.size());
         number = r.toInt();
        }
        elem++;
    }
    return QString::number(number + 1);
}
bool synaxErrorJudger::isAlldataTypeValid(QStringList &data,  vector<pair<int, size_t>> &dataTypeInfo)
{
	QStringList::iterator it;
	for (it = data.begin(); it != data.end(); ++it) {
		*it = it->trimmed();
		if (*it == "") {
			return false;
		}
		bool ok;
		if (it->indexOf('\'') != -1) { //引号'应该是字符或字符串
			it->remove(0, 1).remove(QRegExp("'$"));
			size_t len = it->size();
			if (len < 1 || len > 255) {
				return false;
			}
			else if (len == 1) {
				dataTypeInfo.push_back(pair<int, size_t>(_CHAR, sizeof(char)));
			}
			else {
				dataTypeInfo.push_back(pair<int, size_t>(_STRING, len * sizeof(char)));
			}
		}
		else if (it->indexOf('.') != -1) { //有小数点且不是字符串,应该是float
			it->toFloat(&ok);
			if (!ok) {
				return false;
			}
			else {
				dataTypeInfo.push_back(pair<int, size_t>(_FLOAT, sizeof(float)));
			}
		}
		else { //剩下的应该是int类型
			it->toInt(&ok);
			if (!ok) {
				return false;
			}
			else {
				dataTypeInfo.push_back(pair<int, size_t>(_INT, sizeof(int)));
			}
		}
	}
	return true;
}
void synaxErrorJudger::generateCondition()
{
	int begin = sqlExp.indexOf("where") + 5;
	int end = sqlExp.indexOf(QRegExp(";$")) - 1;
	QStringList conditions = sqlExp.mid(begin, end - begin + 1).split("and");
	QStringList::iterator it;
	pair<int, size_t> dataType;
	int logicType;
	string rightSide, leftSide;
	for (it = conditions.begin(); it != conditions.end(); ++it) {	
		*it = it->trimmed();
		if (*it == "") {
			throw QString("Synax Error: Conditions' format is incorrect.");
		}
		int begin = 0;
		int end = it->indexOf(QRegExp("[=><]"))-1;
		rightSide = it->mid(begin, end - begin + 1).trimmed().toStdString();
		begin = end + 1;
		end = it->indexOf(QRegExp("[=><]"), begin + 1);
		if (end - begin > 1 || end == -1) { //如果下一个"=",">","<"号出现在较远处
			end = begin; //说明这个逻辑关系是"=",">","<"而非">=", "<=", "<>" 
		}
		logicType = condition::getLogicTypeFromStr(it->mid(begin, end - begin + 1).toStdString());
		if (logicType == _ERROR) {
			throw QString("Synax Error: The logic arithemtic is invalid.");
		}
		bool ok;
		*it = it->mid(end + 1).trimmed();
		if (it->indexOf(QRegExp("^'")) != -1) { //引号'应该是字符或字符串
			it->remove(0, 1).remove(QRegExp("'$"));
			size_t len = it->size();
			pair<int, size_t> dType;
			Api::cManager.getAttributeDataType(*tblName, rightSide, dType);
			if (len < 1 || len > 255 || len > dType.second) {
				throw QString("Synax Error: The length of string is overflow.");
			}
			else if (len == 1) {
				dataType = pair<int, size_t>(_CHAR, sizeof(char));
			}
			else {
				dataType = pair<int, size_t>(_STRING, dType.second * sizeof(char));
			}
		}
		else if (it->indexOf('.') != -1) { //有小数点且不是字符串,应该是float
			it->toFloat(&ok);
			if (!ok) {
				;
			}
			else {
				dataType = pair<int, size_t>(_FLOAT, sizeof(float));
			}
		}
		else { //剩下的应该是int类型
			it->toInt(&ok);
			if (!ok) {
				;
			}
			else {
				dataType = pair<int, size_t>(_INT, sizeof(int));
			}
		}
		leftSide = it->toStdString();
		if (cond == 0) {
			cond = new vector<condition>;
		}
		cond->push_back(condition(rightSide, logicType, dataType, leftSide));
	}
}
DirectoryTree *InstallationManager::createFilesTree()
{
  FileData* const *data;
  size_t size;
  m_CurrentArchive->getFileList(data, size);

  QScopedPointer<DirectoryTree> result(new DirectoryTree);

  for (size_t i = 0; i < size; ++i) {
    // the files are in a flat list where each file has a a full path relative to the archive root
    // to create a tree, we have to iterate over each path component of each. This could be sped up by
    // grouping the filenames first, but so far there doesn't seem to be an actual performance problem
    DirectoryTree::Node *currentNode = result.data();

    QString fileName = ToQString(data[i]->getFileName());
    QStringList components = fileName.split("\\");

    // iterate over all path-components of this filename (including the filename itself)
    for (QStringList::iterator componentIter = components.begin(); componentIter != components.end(); ++componentIter) {
      if (componentIter->size() == 0) {
        // empty string indicates fileName is actually only a directory name and we have
        // completely processed it already.
        break;
      }

      bool exists = false;
      // test if this path is already in the tree
      for (DirectoryTree::node_iterator nodeIter = currentNode->nodesBegin(); nodeIter != currentNode->nodesEnd(); ++nodeIter) {
        if ((*nodeIter)->getData().name == *componentIter) {
          currentNode = *nodeIter;
          exists = true;
          break;
        }
      }

      if (!exists) {
        if (componentIter + 1 == components.end()) {
          // last path component. directory or file?
          if (data[i]->isDirectory()) {
            // this is a bit problematic. archives will often only list directories if they are empty,
            // otherwise the dir only appears in the path of a file. In the UI however we allow the user
            // to uncheck all files in a directory while keeping the dir checked. Those directories are
            // currently not installed.
            DirectoryTree::Node *newNode = new DirectoryTree::Node;
            newNode->setData(DirectoryTreeInformation(*componentIter, i));
            currentNode->addNode(newNode, false);
            currentNode = newNode;
          } else {
            currentNode->addLeaf(FileTreeInformation(*componentIter, i));
          }
        } else {
          DirectoryTree::Node *newNode = new DirectoryTree::Node;
          newNode->setData(DirectoryTreeInformation(*componentIter, -1));
          currentNode->addNode(newNode, false);
          currentNode = newNode;
        }
      }
    }
  }

  return result.take();
}
void
ExportGroupTemplateDialog::onOkClicked()
{
    QString dirPath = _imp->fileEdit->text();

    if ( !dirPath.isEmpty() && ( dirPath[dirPath.size() - 1] == QLatin1Char('/') ) ) {
        dirPath.remove(dirPath.size() - 1, 1);
    }
    QDir d(dirPath);

    if ( !d.exists() ) {
        Dialogs::errorDialog( tr("Error").toStdString(), tr("You must specify a directory to save the script").toStdString() );

        return;
    }
    QString pluginLabel = _imp->labelEdit->text();
    if ( pluginLabel.isEmpty() ) {
        Dialogs::errorDialog( tr("Error").toStdString(), tr("You must specify a label to name the script").toStdString() );

        return;
    } else {
        pluginLabel = QString::fromUtf8( NATRON_PYTHON_NAMESPACE::makeNameScriptFriendly( pluginLabel.toStdString() ).c_str() );
    }

    QString pluginID = _imp->idEdit->text();
    if ( pluginID.isEmpty() ) {
        Dialogs::errorDialog( tr("Error").toStdString(), tr("You must specify a unique ID to identify the script").toStdString() );

        return;
    }

    QString iconPath = _imp->iconPath->text();
    QString grouping = _imp->groupingEdit->text();
    QString description = _imp->descriptionEdit->getText();
    QString filePath = d.absolutePath() + QLatin1Char('/') + pluginLabel + QString::fromUtf8(".py");
    QStringList filters;
    filters.push_back( QString( pluginLabel + QString::fromUtf8(".py") ) );
    if ( !d.entryList(filters, QDir::Files | QDir::NoDotAndDotDot).isEmpty() ) {
        StandardButtonEnum rep = Dialogs::questionDialog(tr("Existing plug-in").toStdString(),
                                                         tr("A group plug-in with the same name already exists "
                                                            "would you like to "
                                                            "override it?").toStdString(), false);
        if  (rep == eStandardButtonNo) {
            return;
        }
    }

    bool foundInPath = false;
    QStringList groupSearchPath = appPTR->getAllNonOFXPluginsPaths();
    for (QStringList::iterator it = groupSearchPath.begin(); it != groupSearchPath.end(); ++it) {
        if ( !it->isEmpty() && ( it->at(it->size() - 1) == QLatin1Char('/') ) ) {
            it->remove(it->size() - 1, 1);
        }
        if (*it == dirPath) {
            foundInPath = true;
        }
    }

    if (!foundInPath) {
        QString message = dirPath + tr(" does not exist in the group plug-in search path, would you like to add it?");
        StandardButtonEnum rep = Dialogs::questionDialog(tr("Plug-in path").toStdString(),
                                                         message.toStdString(), false);

        if  (rep == eStandardButtonYes) {
            appPTR->getCurrentSettings()->appendPythonGroupsPath( dirPath.toStdString() );
        }
    }

    QFile file(filePath);
    if ( !file.open(QIODevice::ReadWrite | QIODevice::Truncate) ) {
        Dialogs::errorDialog( tr("Error").toStdString(), QString(tr("Cannot open ") + filePath).toStdString() );

        return;
    }

    QTextStream ts(&file);
    QString content;
    _imp->group->exportGroupToPython(pluginID, pluginLabel, description, iconPath, grouping, content);
    ts << content;

    accept();
} // ExportGroupTemplateDialog::onOkClicked