Ejemplo n.º 1
0
void ObserverMap::treeLayers_itemChanged(QTreeWidgetItem * item, int /*column*/)
{
    if (obsAttrib.size() == 0)
        return;

    Attributes * attrib = mapAttributes->value(item->text(0));
    if (attrib)
    {
        attrib->setVisible((item->checkState(0) == Qt::Checked) ? true : false);
        painterWidget->calculateResult();
    }
}
Ejemplo n.º 2
0
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);
}