Beispiel #1
0
int Parser::stackPushAt(char *cStr) {
    int len = strlen(cStr) - 6;
    memcpy(tmpStr, cStr + 6, len);
    tmpStr[len] = '\0';

    char *identifyType = strstr(cStr, "\"");
    char *comma = strstr(cStr, ",");

    int success = 0;
    if (comma) {
        Alias_s alias = { NULL, NULL, NULL, 0 };
        int len = strlen(tmpStr) - strlen(comma);
        memcpy(tmpLhs, tmpStr, len);
        tmpLhs[len] = '\0';

        char *resLhs = regularExpression(tmpLhs);
        int index;
        if (checkForDigits(resLhs) == 1 && identifyType == NULL) {
            index = atoi(resLhs);
        }

        len = strlen(comma) -1;
        memcpy(tmpRhs, comma +1, len);
        tmpRhs[len] = '\0';

        char *resRhs = regularExpression(tmpRhs);
        len = strlen(resRhs);

        if (identifyType) {
            memcpy(alias.type, "string", 6);
            alias.type[len] = '\0';
            alias.len = len;

        } else if (checkForDigits(resRhs) == 1 && identifyType == NULL) {
            memcpy(alias.type, "int", 3);
            alias.type[3] = '\0';
            alias.len = len;
        } else {
            //Syntax is wrong, DO CRASH!!
        }
        memcpy(alias.value, resRhs, alias.len);
        alias.value[alias.len] = '\0';

        success = heap.pushAt(index, alias);

    } else {
        //Only one parameter, DO CRASH!!
    }
    return success;
}
Beispiel #2
0
int Parser::stackPushTop(char *cStr) {
    int len = strlen(cStr) - 7;
    memcpy(tmpStr, cStr + 7, len);
    tmpStr[len] = '\0';

    char *identifyType = strstr(cStr, "\"");
    char *res = regularExpression(tmpStr);
    len = strlen(res);

    Alias_s alias;
    if (checkForAlpha(res) == 1 && identifyType) {
        memcpy(alias.type, "string", 6);
        alias.type[6] = '\0';

        alias.len = len;
    } else if (checkForDigits(res) == 1 && identifyType == NULL) {
        memcpy(alias.type, "int", 3);
        alias.type[3] = '\0';

        alias.len = len;
    } else {
        //Syntax is wrong, DO CRASH!!
    }
    memcpy(alias.name, "\0", 1);
    memcpy(alias.value, res, alias.len);
    alias.value[alias.len] = '\0';

    return heap.pushTop(alias);
}
Beispiel #3
0
char* Parser::regularExpression(char *expression) {
    trimBothParanthesis(expression);

    //If there is no operators return expression(end condition).
    operator_s op0 = findOperator(expression, 0);
    if (op0.pos == -1) {
        Alias_s a;
        //Is it a stack call?
        a = parseKeywords(expression);

        if (strlen(a.value) == 0) {
            memcpy(a.value, expression, a.len);
        }
        return a.value;
    }

    int len = strlen(expression);
    operator_s op1 = findOperator(expression, op0.pos + op0.len);
    if (op1.pos != -1) {

        //Negative number.
        if (op0.pos != -1 && op1.op[0] == '-' && op1.pos == op0.pos +1) {
            int len = strlen(expression);
        } else {
            //If there is a second operator set len = operator.
            len = op1.pos;
        }
    }

    memcpy(tmpLhs, expression, len);
    tmpLhs[len] = '\0';

    int rhsLen = strlen(expression) - len;
    memcpy(tmpRhs, expression + len, rhsLen);
    tmpRhs[rhsLen] = '\0';

    char *res = calculateResult(tmpLhs);

    len = strlen(res);
    memcpy(tmpStr, res, len);
    tmpStr[len] = '\0';

    strcat(tmpStr, tmpRhs);
    tmpStr[len + strlen(tmpRhs)] = '\0';

    //Negative number.
    if (isNegativeNumber(tmpStr)) {
        return tmpStr;
    }

    //recursion.
    regularExpression(tmpStr);

    return tmpStr;
}
Beispiel #4
0
    bool _nameMatchesFilter(const std::string& name, const std::string& filter)
    {
        if(filter.empty())
        {
            return true;
        }

        std::regex regularExpression(filter);
        std::smatch matches;

        return std::regex_match(name, matches, regularExpression);
    }
Beispiel #5
0
QTextCursor FindDialog::find(const QTextCursor &start, const QTextDocument *doc) {
   if (start.isNull())
      return start;

   const QString &searchString = getSearchString();
   
   QTextDocument::FindFlags findFlags = 0;
   if (findBackwards())
      findFlags |= QTextDocument::FindBackward;
   if (caseSensitive())
      findFlags |= QTextDocument::FindCaseSensitively;
   if (wholeWordsOnly())
      findFlags |= QTextDocument::FindWholeWords;
   
   if (regularExpression())
      return doc->find(QRegExp(searchString), start, findFlags);

   // plain-text search
   return doc->find(searchString, start, findFlags);
}
QValidator::State RegularExpressionValidator::validate(QString &input, int &) const
{
    return regularExpression().match(input).hasMatch() ? QValidator::Acceptable : QValidator::Intermediate;
}
void ThreadRemoveExifDatas::run() {
    QTableWidgetItem *item;
 
    Exiv2::ExifData::iterator keyIteratorRemove;
    Exiv2::ExifKey *keyRemove;

    QVector<QString> listErrorRemoveFile;
    QVector<int> listErrorRemoveFilePosition;

    connect(this, SIGNAL(progressBarValue(int)), progressBar, SLOT(setValue(int)));
    connect(this, SIGNAL(progressBarSetVisible(bool)), progressBar, SLOT(setVisible(bool)));
    emit progressBarSetVisible(true);
    progressBar->setRange(0, tableWidgetJpeg->rowCount());

    for (int i = 0; i < tableWidgetJpeg->rowCount(); i++) {
        try {
            emit progressBarValue(i);
            Exiv2::Image::AutoPtr image;

            image = Exiv2::ImageFactory::open(tableWidgetJpeg->item(i, 7)->text().toStdString().c_str());

            if (tableWidgetJpeg->item(i, 3) != 0 || tableWidgetJpeg->item(i, 4) != 0 || tableWidgetJpeg->item(i, 5) != 0) {
                bool exifRemovido = false;
                assert(image.get() != 0);
                image->readMetadata();
                Exiv2::ExifData &exifData = image->exifData();

                Exiv2::ExifKey keyLatitude = Exiv2::ExifKey("Exif.GPSInfo.GPSLatitude");
                keyIteratorRemove = exifData.findKey(keyLatitude);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSTimeStamp");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSDateStamp");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSMapDatum");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSLatitudeRef");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSLongitude");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSLongitudeRef");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSAltitude");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSAltitudeRef");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSImgDirectionRef");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }
                
                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSImgDirection");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }

                keyRemove = new Exiv2::ExifKey("Exif.GPSInfo.GPSProcessingMethod");
                keyIteratorRemove = exifData.findKey(*keyRemove);
                if (keyIteratorRemove != exifData.end()) {
                    exifData.erase(keyIteratorRemove);
                    exifRemovido = true;
                }                
                
                if (exifRemovido) {
                    QString softwareTag = QApplication::applicationName();
                    softwareTag += " ";
                    softwareTag += QApplication::applicationVersion();
                    exifData["Exif.Image.Software"] = softwareTag.toStdString();
                }
                image->setExifData(exifData);
                image->writeMetadata();
                QString itemStatus = QString::fromUtf8("Dados Removidos");
                item = new QTableWidgetItem();
                item->setText(itemStatus);
                delete tableWidgetJpeg->takeItem(i, 3);
                delete tableWidgetJpeg->takeItem(i, 4);
                delete tableWidgetJpeg->takeItem(i, 5);
                tableWidgetJpeg->setItem(i, 6, item);
            } else {
                QString itemStatus = QString::fromUtf8("Não Há Dados Para Remover");
                item = new QTableWidgetItem();
                item->setText(itemStatus);
                tableWidgetJpeg->setItem(i, 6, item);
            }
        }
        catch (Exiv2::AnyError& e) {
            QString itemMsg;
            switch (e.code()) {
                case 2:
                    itemMsg = QString::fromUtf8("Erro ao Remover Arquivo");
                    // Quando ocorrer erro na remoção do arquivo, ele será colocado numa lista para
                    // que ao fim da execução seja tentado mais uma vez a sua remoção.
                    listErrorRemoveFile.push_back(tableWidgetJpeg->item(i, 7)->text());
                    listErrorRemoveFilePosition.push_back(i);
                    break;
                case 9:
                    itemMsg = QString::fromUtf8("Erro de Acesso ao Arquivo");
                    break;
                case 10:
                    itemMsg = QString::fromUtf8("Arquivo Somente Leitura");
                    break;
                case 11:
                    itemMsg = QString::fromUtf8("Arquivo Inválido");
                    break;
            }
            item = new QTableWidgetItem();
            item->setForeground(QColor(255, 0, 0));
            item->setText(itemMsg);
            tableWidgetJpeg->setItem(i, 6, item);
        }
    }

    for (int i = 0; i < listErrorRemoveFile.size(); i++) {
        //precisa pesquisar no disco se tem outro arquivo com o nome igual mas com a extensão diferente
        // se achar, tem que remover o atual e renomear o outro arquivo.
        QString fileName;
        QString filePath;
        QString itemMsg;
        int pos;

        pos = listErrorRemoveFile.at(i).lastIndexOf("/");
        fileName.operator =(QString::fromUtf8(listErrorRemoveFile.at(i).right(listErrorRemoveFile.at(i).size() - pos - 1).toStdString().c_str()));
        filePath = listErrorRemoveFile.at(i).left(pos);
        QDir directory(filePath);
        QStringList filesOnDirectory = directory.entryList(QDir::Files);
        QString regularExpression(fileName);
        regularExpression.append("[0-9]{1,4}");
        QRegExp fileRegExp(regularExpression, Qt::CaseSensitive, QRegExp::RegExp);
        QStringList filesLocated = filesOnDirectory.filter(fileRegExp);
        for (int j = 0; j < filesLocated.size(); j++) {
            itemMsg = QString::fromUtf8("Não Foi Possível Corrigir o Arquivo, Verifique Manualmente");
            QFileInfo fileTemp(directory, filesLocated.at(j));
            QFileInfo fileCurrent(directory, fileName);
            if (fileTemp.size() > fileCurrent.size()) {
                if (directory.remove(fileName)) {
                    if (directory.rename(filesLocated.at(j), fileName)) {
                        itemMsg = QString::fromUtf8("O Erro no Arquivo foi Corrigido");
                        delete tableWidgetJpeg->takeItem(listErrorRemoveFilePosition.at(i), 3);
                        delete tableWidgetJpeg->takeItem(listErrorRemoveFilePosition.at(i), 4);
                        delete tableWidgetJpeg->takeItem(listErrorRemoveFilePosition.at(i), 5);
                    }
                }
            } else {
                if (directory.remove(filesLocated.at(j)))
                    itemMsg = QString::fromUtf8("O Erro no Arquivo foi Corrigido");
            }
            item = new QTableWidgetItem();
            item->setForeground(QColor(0, 110, 0));
            item->setText(itemMsg);
            tableWidgetJpeg->setItem(listErrorRemoveFilePosition.at(i), 6, item);
        }
    }
    emit progressBarValue(tableWidgetJpeg->rowCount());
    sleep(1);
    emit progressBarSetVisible(false);
}
/****************************************************************************
**
** Copyright (C) 2016
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

#include <QComboBox>
#include <QStringListModel>
#include <QLabel>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QLineEdit>
#include "tb_transformationwidget.h"

namespace Magus
{
    //****************************************************************************/
    TransformationWidget::TransformationWidget(QWidget* parent) : QWidget(parent)
    {
        selectionChanged = false;
        mPrecision = 2;
        mPosition = QVector3D(0, 0, 0);
        mRotation = QVector3D(0, 0, 0);
        mScale = QVector3D(0, 0, 0);
        mTransformation = POSITION;
        QHBoxLayout* transformationLayout = new QHBoxLayout;
        QHBoxLayout* xLayout = new QHBoxLayout;
        QHBoxLayout* yLayout = new QHBoxLayout;
        QHBoxLayout* zLayout = new QHBoxLayout;

        // Combobox
        QStringList list;
        list << QString("Position") << QString("Rotation") << QString("Scale");
        mModel = new QStringListModel(list);
        mTransformationCombobox = new QComboBox(parent);
        mTransformationCombobox->setModel(mModel);
        mTransformationCombobox->setMaxVisibleItems(3);

        // X, Y, Z
        QString s;
        QLabel* xLabel = new QLabel(QString("<b>X</b>"));
        xLabel->setMaximumWidth(24);
        xLabel->setAutoFillBackground(true);
        xLabel->setStyleSheet("QLabel {background-color : rgb(255, 0, 0); margin-left: 0px; margin-right: 0px; spacing: 0px;}");
        QRegExp regularExpression("[+-]?([0-9]+\\.([0-9]+)?|\\.[0-9]+)([eE][+-]?[0-9]+)?"); // floating point
        QRegExpValidator* validator = new QRegExpValidator(regularExpression);
        mXedit = new QLineEdit;
        mXedit->setValidator(validator);
        s = QVariant(mPosition.x()).toString();
        s = s.left(getLeftStringIndex(s));
        mXedit->setText(s);
        mXedit->setStyleSheet("QLineEdit {margin-right: 0px; margin-left: 5px; width: 32px; spacing: 0px;}");

        QLabel* yLabel = new QLabel(QString("<b>Y</b>"));
        yLabel->setMaximumWidth(24);
        yLabel->setAutoFillBackground(true);
        yLabel->setStyleSheet("QLabel {background-color : rgb(0, 255, 0); margin-left: 0px; margin-right: 0px;}");
        mYedit = new QLineEdit;
        mYedit->setValidator(validator);
        s = QVariant(mPosition.y()).toString();
        s = s.left(getLeftStringIndex(s));
        mYedit->setText(s);
        mYedit->setStyleSheet("QLineEdit {margin-right: 0px; margin-left: 0px; width: 32px; spacing: 0px;}");

        QLabel* zLabel = new QLabel(QString("<b>Z</b>"));
        zLabel->setMaximumWidth(24);
        zLabel->setAutoFillBackground(true);
        zLabel->setStyleSheet("QLabel {background-color : rgb(100, 100, 255); margin-left: 0px; margin-right: 0px;}");
        mZedit = new QLineEdit;
        mZedit->setValidator(validator);
        s = QVariant(mPosition.z()).toString();
        s = s.left(getLeftStringIndex(s));
        mZedit->setText(s);
        mZedit->setStyleSheet("QLineEdit {margin-right: 0px; margin-left: 0px; width: 32px; spacing: 0px;}");

        // Layout
        transformationLayout->addWidget(mTransformationCombobox);
        xLayout->addWidget(xLabel, 0, Qt::AlignRight);
        xLayout->addWidget(mXedit, 100, Qt::AlignLeft);
        yLayout->addWidget(yLabel, 0, Qt::AlignRight);
        yLayout->addWidget(mYedit, 0, Qt::AlignLeft);
        zLayout->addWidget(zLabel, 0, Qt::AlignRight);
        zLayout->addWidget(mZedit, 0, Qt::AlignLeft);
        transformationLayout->addLayout(xLayout);
        transformationLayout->addLayout(yLayout);
        transformationLayout->addLayout(zLayout);
        setLayout(transformationLayout);
        connect(mTransformationCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
        connect(mXedit, SIGNAL(textEdited(const QString &)), this, SLOT(handleXchanged(const QString &)));
        connect(mYedit, SIGNAL(textEdited(const QString &)), this, SLOT(handleYchanged(const QString &)));
        connect(mZedit, SIGNAL(textEdited(const QString &)), this, SLOT(handleZchanged(const QString &)));
    }
Beispiel #9
0
void FindDialog::replaceAll() {
   TextEditor *current = m_parent->m_activeEditor;
   QTextDocument *doc  = current->getTextDocument();
   QTextCursor start   = current->textCursor();
   QTextCursor result, last;
   int noOccurrences = 0, startPos = -1, endPos = -1;
   m_searching = false;
   
   // search within a selection
   if (start.hasSelection() && searchSelection()) {
      startPos = start.selectionStart();
      endPos = start.selectionEnd();
      
      // get rid of selection
      if (findBackwards())
         start.setPosition(endPos);
      else start.setPosition(startPos);
   } else start.movePosition(QTextCursor::Start);
   
   start.beginEditBlock();
   result = start;
   
   do {
      last   = result;
      result = replace(result, doc, startPos, endPos);
      if (result.isNull())
         break;
      
      // disallow infinite replacements of similar terms ('life' w/ 'LIFE')
      result.setPosition(result.selectionEnd());
      ++noOccurrences;
   } while(true);
   
   start.endEditBlock();
   if (noOccurrences <= 0) {
      STATUS_BAR->showMessage(QString("%1 '%2' not found with the Options given").arg((regularExpression() ? QString("RegExp") : QString("String")), getSearchString()));
   } else {
      current->changeTextCursor(last);
      STATUS_BAR->showMessage(QString("Replaced %1 occurence%2.").arg(QString::number(noOccurrences), (noOccurrences != 1 ? QString("s") : QString(""))));
   }
   
   updateReplace(true);
}
Beispiel #10
0
void FindDialog::accept() {
   TextEditor *current = m_parent->m_activeEditor;
   QTextDocument *doc  = current->getTextDocument();
   QTextCursor start   = current->textCursor();
   QTextCursor result;
   int startPos = -1, endPos = -1;
   
   // see if we're supposed to search within a selection
   if (start.hasSelection() && searchSelection()) {
      startPos = start.selectionStart();
      endPos = start.selectionEnd();
      
      // get rid of selection
      if (findBackwards())
         start.setPosition(endPos);
      else start.setPosition(startPos);
   } else if (!fromCursor() && !m_searching)
      start.movePosition(QTextCursor::Start);
   
   if (isFind()) {
      result = find(start, doc);
      
      // test if result was outside of selection
      if (!result.isNull() && 
          ((endPos > 0 && result.selectionEnd() > endPos) || 
          (startPos > 0 && result.selectionStart() < startPos)))
         result = QTextCursor(); // null cursor
   } else result = replace(start, doc, endPos);
   
   if (result.isNull()) {
      STATUS_BAR->showMessage(QString("%1 '%2' not found with the Options given").arg((regularExpression() ? QString("RegExp") : QString("String")), getSearchString()));
      
      m_searching = false;
      updateReplace(isReplace());
   } else {
      current->changeTextCursor(result);
      STATUS_BAR->clearMessage();
      
      m_searching = true;
      updateReplace(isReplace());
   }
}