Exemplo n.º 1
0
ParametersConfiguration::ParametersConfiguration(ParametersConfiguration* parentData, const QString& valuesFile, bool resetValues) :
QObject(parentData), parentData_(parentData), saveFileName_(valuesFile){
    empty_ = false;
    if(!parentData) {
        empty_ = true;
        qDebug() << "CRITICAL: Cannot construct from empty cfg data.";
        return;
    }
    
    sections_.clear();
    for (int i = 0; i < parentData_->sections_.size(); i++) {
        ParameterSectionData* parentSection = parentData_->sections_[i];
        ParameterSectionData* localSection = new ParameterSectionData(parentSection->title(), this);
        sections_ << localSection;
        for (unsigned int j = 0; j < parentSection->size(); j++) {
            ParameterElementData* parentElement = parentData_->get((*parentSection)[j]->name());
            ParameterElementData* localElement;
            if (parentElement->syncWithUpperLevel() && parentData_->lookup_.contains(parentElement->name().toLower())) {
                localElement = parentElement;
            } else {
                localElement = new ParameterElementData(parentElement->name(), localSection);
                localElement->setValue(parentElement->value().toString());
                localElement->setLock(parentElement->locked());
                localElement->setIsWrong(parentElement->isWrong());
            }

            localSection->append(localElement);
            lookup_.insert(localElement->name().toLower(), localElement);
        }
    }
    
    setModified(false);
    if(resetValues) resetUserValues(valuesFile);
}
Exemplo n.º 2
0
QWidget* PreferencesDialog::getCfgPage(QString sectionIdentifier) {
    QStringList parameters;
    for (unsigned int ii = 0; ii < userPreferenceData.data()->size(); ii++) {
        if ((*userPreferenceData.data())[ii]->title().trimmed().toLower().contains(sectionIdentifier)) {
            ParameterSectionData* section = (*userPreferenceData.data())[ii];
            for (unsigned int j = 0; j < section->size(); j++) parameters.append((*section)[j]->name());
        }
    }
    
    ParametersWidget* widget = new ParametersWidget(userPreferenceData.data(), parameters, 1);
    return widget;
}
Exemplo n.º 3
0
bool ParametersConfiguration::parseDataFile(const QString& fileName) {
    QFile data(fileName);
    if (!data.open(QIODevice::ReadOnly | QIODevice::Text)) return false;

    sections_.clear();

    QString lineData;
    ParameterSectionData *section = 0;
    qint64 pos = -1;
    bool lock = false;
    bool isWrong = false;
    while (!data.atEnd() && pos != data.pos()) {
        pos = data.pos();
        lineData = data.readLine().trimmed();
        lineData.remove('#');
        lineData = lineData.trimmed();

        if (lineData.toLower().startsWith("section:")) {
            lineData.remove(0, 8);
            section = new ParameterSectionData(lineData.simplified(), this);
            sections_ << section;
        }

        if (lineData.startsWith("LOCKED:")) {
            lineData.remove(0, QString("LOCKED:").size() + 1);
            if (lineData.trimmed().toLower() == "yes" || lineData.trimmed().toLower() == "y") lock = true;
        }
        
        if (lineData.startsWith("ISWRONG:")) {
            lineData.remove(0, QString("ISWRONG:").size() + 1);
            if (lineData.trimmed().toLower() == "yes" || lineData.trimmed().toLower() == "y") isWrong = true;
        }

        if (lineData.toLower().startsWith("set ")) {
            int k = lineData.indexOf('=');
            if (k > 0) {
                QStringList val = lineData.split('=');

                val[0].remove(0, 4);
                val[1].remove('"');

                val[0] = val[0].simplified();
                val[1] = val[1].simplified();
  
                if(parameterMaster.containsParameter(val[0])) {
                    ParameterElementData* element = new ParameterElementData(val[0], section);
                    if (element->syncWithUpperLevel() && parentData_ && parentData_->lookup_.contains(val[0].toLower())) {
                        delete element;
                        element = parentData_->get(val[0]);
                    } else {
                        element->setValue(val[1]);
                        element->setLock(lock);
                        element->setIsWrong(isWrong);
                    }

                    section->append(element);
                    lookup_.insert(element->name().toLower(), element);
                }
                
                //Reset properties
                lock = false;
                isWrong = false;
            }
        }
    }

    data.close();
    return true;
}