void ObserverMap::setAttributes(QStringList &attribs, QStringList legKeys, QStringList legAttribs) { connectTreeLayerSlot(false); bool complexMap = false; if (itemList.isEmpty()) { itemList << attribs; } else { complexMap = true; foreach(const QString & str, attribs) { if (!itemList.contains(str)) itemList.append(str); } } for (int j = 0; (legKeys.size() > 0 && j < LEGEND_KEYS.size()); j++) { if (legKeys.indexOf(LEGEND_KEYS.at(j)) < 0) { qFatal("Error: Parameter legend \"%s\" not found. Please check it in the model.", qPrintable(LEGEND_KEYS.at(j))); } } int type = 0, mode = 0, slices = 0, precision = 0, stdDeviation = 0, max = 0; int min = 0, colorBar = 0, font = 0, fontSize = 0, symbol = 0, width = 0; QTreeWidgetItem *item = 0; Attributes *attrib = 0; for (int i = 0; i < itemList.size(); i++) { if ((!mapAttributes->contains(itemList.at(i))) && (itemList.at(i) != "x") && (itemList.at(i) != "y")) { obsAttrib.append(itemList.at(i)); attrib = new Attributes(itemList.at(i), width * height, newWidthCellSpace, newHeightCellSpace); attrib->setVisible(true); if (!legKeys.isEmpty()) { type = legKeys.indexOf(TYPE); mode = legKeys.indexOf(GROUP_MODE); slices = legKeys.indexOf(SLICES); precision = legKeys.indexOf(PRECISION); stdDeviation = legKeys.indexOf(STD_DEV); max = legKeys.indexOf(MAX); min = legKeys.indexOf(MIN); colorBar = legKeys.indexOf(COLOR_BAR); font = legKeys.indexOf(FONT_FAMILY); fontSize = legKeys.indexOf(FONT_SIZE); symbol = legKeys.indexOf(SYMBOL); width = legKeys.indexOf(WIDTH); attrib->setDataType((TypesOfData) legAttribs.at(type).toInt()); attrib->setGroupMode((GroupingMode) legAttribs.at(mode).toInt()); attrib->setSlices(legAttribs.at(slices).toInt() - 1); // conta com o zero attrib->setPrecisionNumber(legAttribs.at(precision).toInt() - 1); // conta com o zero attrib->setStdDeviation((StdDev) legAttribs.at(stdDeviation).toInt()); attrib->setMaxValue(legAttribs.at(max).toDouble()); attrib->setMinValue(legAttribs.at(min).toDouble()); attrib->setFontFamily(legAttribs.at(font)); attrib->setFontSize(legAttribs.at(fontSize).toInt()); bool ok = false; int asciiCode = legAttribs.at(symbol).toInt(&ok, 10); if (ok) attrib->setSymbol(QString(QChar(asciiCode))); else attrib->setSymbol(legAttribs.at(symbol)); attrib->setWidth(legAttribs.at(width).toDouble()); std::vector<ColorBar> colorBarVec; std::vector<ColorBar> stdColorBarVec; QStringList labelList, valueList; createColorsBar(legAttribs.at(colorBar), colorBarVec, stdColorBarVec, valueList, labelList); attrib->setColorBar(colorBarVec); attrib->setStdColorBar(stdColorBarVec); attrib->setValueList(valueList); attrib->setLabelList(labelList); for (int j = 0; j < LEGEND_ITENS; j++) { legKeys.removeFirst(); legAttribs.removeFirst(); } } mapAttributes->insert(itemList.at(i), attrib); attrib->makeBkp(); item = new QTreeWidgetItem(treeLayers); item->setCheckState(0, Qt::Checked); item->setText(0, itemList.at(i)); if ((complexMap) && (treeLayers->topLevelItemCount() > 1)) { item = treeLayers->takeTopLevelItem(treeLayers->topLevelItemCount() - 1); treeLayers->insertTopLevelItem(0, item); item->setExpanded(true); } } } if (!legendWindow) legendWindow = new LegendWindow(this); legendWindow->setValues(mapAttributes); zoomWindow(); connectTreeLayerSlot(true); }
void ObserverStateMachine::setAttributes(QStringList &attribs, QStringList legKeys, QStringList legAttribs) { attribList = attribs; #ifdef DEBUG_OBSERVER qDebug() << "\nattribs:\n" << attribs; qDebug() << "\nMapAttributes()->keys(): " << mapAttributes->keys() << "\n"; qDebug() << "LEGEND_ITENS: " << LEGEND_ITENS; qDebug() << "num de legendas: " << (int) legKeys.size() / LEGEND_ITENS; for (int j = 0; j < legKeys.size(); j++) qDebug() << legKeys.at(j) << " = " << legAttrib.at(j); #endif for (int j = 0; (legKeys.size() > 0 && j < LEGEND_KEYS.size()); j++) { if (legKeys.indexOf(LEGEND_KEYS.at(j)) < 0) { qFatal("Error: Parameter legend \"%s\" not found. " "Please check it in the model.", qPrintable( LEGEND_KEYS.at(j) ) ); } } int type = legKeys.indexOf(TYPE); int mode = legKeys.indexOf(GROUP_MODE); int slices = legKeys.indexOf(SLICES); int precision = legKeys.indexOf(PRECISION); int stdDeviation = legKeys.indexOf(STD_DEV); int max = legKeys.indexOf(MAX); int min = legKeys.indexOf(MIN); int colorBar = legKeys.indexOf(COLOR_BAR); int font = legKeys.indexOf(FONT_FAMILY); int fontSize = legKeys.indexOf(FONT_SIZE); int symbol = legKeys.indexOf(SYMBOL); #ifdef DEBUG_OBSERVER qDebug() << "\nattribs:\n" << attribs; qDebug() << "\nlegKeys: \n" << legKeys; qDebug() << "\nlegAttrib: \n" << legAttrib; qDebug() << "\nMapAttributes()->keys(): " << mapAttributes->keys() << "\n"; #endif QTreeWidgetItem *item = 0; Attributes *attrib = 0; for( int i = 0; i < attribs.size(); i++) { if ((! mapAttributes->contains(attribs.at(i))) && (attribs.at(i) != QString("x")) && (attribs.at(i) != QString("y")) ) { obsAttrib.append(attribs.at(i)); attrib = new Attributes(attribs.at(i), 2, 0, 0); // states->size(), 0, 0); //------- Recupera a legenda do arquivo e cria o objeto attrib if (legKeys.size() > 0) { attrib->setDataType( (TypesOfData) legAttribs.at(type).toInt()); attrib->setGroupMode( (GroupingMode) legAttribs.at(mode ).toInt()); attrib->setSlices(legAttribs.at(slices).toInt() - 1); // conta com o zero attrib->setPrecisionNumber(legAttribs.at(precision).toInt() - 1); // conta com o zero attrib->setStdDeviation( (StdDev) legAttribs.at(stdDeviation ).toInt()); attrib->setMaxValue(legAttribs.at(max).toDouble()); attrib->setMinValue(legAttribs.at(min).toDouble()); //Fonte attrib->setFontFamily(legAttribs.at(font)); attrib->setFontSize(legAttribs.at(fontSize).toInt()); //Converte o código ASCII do símbolo em caracter bool ok = false; int asciiCode = legAttribs.at(symbol).toInt(&ok, 10); if (ok) attrib->setSymbol( QString( QChar(asciiCode) )); else attrib->setSymbol(legAttribs.at(symbol)); std::vector<ColorBar> colorBarVec; std::vector<ColorBar> stdColorBarVec; QStringList labelList, valueList; ObserverMap::createColorsBar(legAttribs.at(colorBar), colorBarVec, stdColorBarVec, valueList, labelList); attrib->setColorBar(colorBarVec); attrib->setStdColorBar(stdColorBarVec); attrib->setValueList(valueList); attrib->setLabelList(labelList); #ifdef DEBUG_OBSERVER qDebug() << "valueList.size(): " << valueList.size(); qDebug() << valueList; qDebug() << "\nlabelList.size(): " << labelList.size(); qDebug() << labelList; qDebug() << "\nattrib->toString()\n" << attrib->toString(); #endif } mapAttributes->insert(attribs.at(i), attrib); item = new QTreeWidgetItem(treeLayers); item->setText(0, attribs.at(i)); // item->setCheckState(0, Qt::Checked); } } if (! legendWindow) legendWindow = new LegendWindow(this); legendWindow->setValues(mapAttributes); }