Logo Search packages:      
Sourcecode: kalzium version File versions  Download package

void ElementDataViewer::drawPlot (  ) [slot]

draws the plot

Definition at line 294 of file elementdataviewer.cpp.

References m_xData, m_yData, and AxisData::value().

{
    /*
     * to be 100% safe delete the old list
     */
    ui.plotwidget->removeAllPlotObjects();

    /*
     * spare the next step in case everything is already set and done
     */
    if ( m_yData->currentDataType != ui.KCB_y->currentIndex() )
        initData();

    if ( m_xData->currentDataType != ui.KCB_x->currentIndex() )
        initData();

    /*
     * if the user selected the elements 20 to 30 the list-values are 19 to 29!!!
     */
    const int tmpfrom = ui.from->value();
    const int tmpto = ui.to->value();
    const int from = qMin( tmpfrom, tmpto );
    const int to = qMax( tmpfrom, tmpto );

    /*
     * The number of elements. #20 to 30 are 30-20+1=11 Elements
     */
    int num = to-from+1;

    setLimits();

    QSet<int> metals, metalloids, nonMetals;

    metals << 3 << 4 << 11 << 12 << 13;
    for ( int i = 19; i <= 31 ; i++ )
        metals << i;
    for ( int i = 37; i <= 50 ; i++ )
        metals << i;
    for ( int i = 55; i <= 83 ; i++ )
        metals << i;
    for ( int i = 87; i <= 116; i++ )
        metals << i;

    metalloids << 5 << 14 << 32 << 33 << 51 << 52 << 84 << 85;

    nonMetals << 1 << 2 << 6 << 7 << 8 << 9 << 10 << 15 << 16;
    nonMetals << 17 << 18 << 34 << 35 << 36 << 53 << 54 << 86;

    /*
     * check if the users wants to see the elementnames or not
     */
    int whatShow = ui.comboElementLabels->currentIndex();

    /*
     * Checks what type of element, the user wants to plot.
     * example, metal, non-metal.
     */
    int whichType = ui.comboElementType->currentIndex();

    KPlotObject* dataPointGreen = 0;
    KPlotObject* dataPointRed = 0;

    double av_x = 0.0;
    double max_x = m_xData->value(from);
    double min_x = m_xData->value(from);
    double av_y = 0.0;
    double max_y = m_yData->value(from);
    double min_y = m_yData->value(from);

    /*
     * iterate for example from element 20 to 30 and contruct
     * the KPlotObjects
     */
    dataPointGreen = new KPlotObject(
        Qt::green,
        KPlotObject::Points,
        4,
        KPlotObject::Star );
    dataPointGreen->setLabelPen( QPen( Qt::blue ) );

    dataPointRed = new KPlotObject(
        Qt::red,
        KPlotObject::Points,
        4,
        KPlotObject::Star );  //Star can be replaced with a cross
    dataPointRed->setLabelPen( QPen( Qt::blue ) );

    for ( int i = from; i < to+1 ; i++ )
    {
        double value_y = m_yData->value( i );
        double value_x = m_xData->value( i );

        bool known = ( ( value_y ) > 0.0 ) ? 1 : 0;
        //The element is know if its value is not zero
        bool belongs = 1;
        //The value of belongs is one if it belongs to the particular group

        //See if the particular element belongs to the selected set or not.
        //If a particular group of elements is selected,
        if ( whichType > 0)
        {
            belongs = 0;
            switch (whichType)
            {
            case 1: //Plot only metals
                belongs = metals . contains(i);
                break;
            case 2: //plot only nonmetals and metalloids
                belongs = ( nonMetals.contains(i) || metalloids.contains(i) );
                break;
            case 3: //Plot s block elements
                belongs = ( block [ i - 1 ] == "s");
                break;
            case 4: //Plot p block elements
                belongs = ( block [ i - 1 ] == "p");
                break;
            case 5: //Plot d block elements
                belongs = ( block [ i - 1 ] == "d");
                break;
            case 6: //plot f block elements
                belongs = ( block [ i - 1 ] == "f");
                break;
            case 7: // Noble gases
                belongs = ( ( elecConfig [ i - 1 ] ) . endsWith("p6") );
                belongs |= ( i == 2 );          //Include Helium
                break;
            case 8: // Alkalie metals
                belongs = ( ( elecConfig [ i - 1 ] ) . endsWith("s1") );
                belongs &= ( block [ i - 1 ] == "s" ); //exclude chromium
                belongs &= ( i != 1 );          //exclude Hydrogen
                break;
            case 9: // Alkaline earth metals
                belongs = ( ( elecConfig [ i - 1 ] ) . endsWith("s2") );
                belongs &= ( block [ i - 1 ] == "s" ); //exclude chromium
                belongs &= ( i != 2 );          //exclude Helium
                break;
            case 10: // Lanthanides
                // If element i is an f block element, with
                // electronic configuration containing "f4" in it
                // or the element is Lanthanum
                belongs = ( ( block [ i - 1 ] == "f") && \
                            ( ( elecConfig [ i - 1 ] ) . contains ("4f") ) ) || \
                          ( i == 57 );    //Lanthanum 57
                break;
            case 11: //Actinides
                //If element i is an f block element, with
                // electronic configuration containing "f5" in it
                // or the element is Actinium
                belongs = ( ( ( block [ i - 1 ] == "f") ) && \
                            ( ( elecConfig [ i - 1 ] ) . contains ("5f") ) ) || \
                          ( i == 89 );    //Actinium 89
                break;
            case 12: //Radio active
                belongs = ( ( i == 43 ) || ( i == 61 ) || ( i > 84 ) );
                // Technitium prothomium and then polonium onwards.
                break;
            default:
                whichType = 0;
                belongs = 1;
            }
        }
        if ( belongs )
        {

            if ( known )
            {
                av_x += value_x;
                av_y += value_y;

                if (value_x > max_x) {
                    max_x = value_x;
                }
                if (value_y > max_y) {
                    max_y = value_y;
                }
                if (value_x < min_x) {
                    min_x = value_x;
                }
                if (value_y < min_y) {
                    min_y = value_y;
                }

                QString lbl;
                if ( whatShow > 0 )//The users wants to see the labels
                {
                    lbl = whatShow == 1 ? names[i-1] : symbols[i-1];
                }

                dataPointGreen->addPoint( value_x, value_y, lbl );
            }
            else//unknown value
            {
                //num is required while finding the average, if an element is not
                //known it should not contribute to the average.
                num--;

                QString lbl;
                if ( whatShow > 0 )//The users wants to see the labels
                {
                    lbl = whatShow == 1 ? names[i-1] : symbols[i-1];
                }

                dataPointRed->addPoint( value_x, value_y, lbl );
                //For an Unknown value, use a red point to mark the data-point.
            }
        }

        else//The element does not belong to the set
        {
            //num is required while finding average, if an element is
            //not in the selected set, it should not contribute to the avg.
            num--;
        }
    }

    ui.plotwidget->addPlotObject( dataPointGreen );
    ui.plotwidget->addPlotObject( dataPointRed );


    if ( num > 0 )
    {
        //now set the values for the min, max and avarage value
        ui.av_x->setText( QString::number( av_x / num ).append(m_xData->unit) );
        ui.minimum_x->setText( QString::number( min_x ).append(m_xData->unit) );
        ui.maximum_x->setText( QString::number( max_x ).append(m_xData->unit) );

        ui.av_y->setText( QString::number( av_y / num ).append(m_yData->unit) );
        ui.minimum_y->setText( QString::number( min_y ).append(m_yData->unit) );
        ui.maximum_y->setText( QString::number( max_y ).append(m_yData->unit) );
    }
    else
    {
        ui.av_x->setText( QString::number( 0.0 ) );
        ui.minimum_x->setText( QString::number( 0.0 ) );
        ui.maximum_x->setText( QString::number( 0.0 ) );
        ui.av_y->setText( QString::number( 0.0 ) );
        ui.minimum_y->setText( QString::number( 0.0 ) );
        ui.maximum_y->setText( QString::number( 0.0 ) );
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index