Example #1
0
void
RCanvas::text(double x, double y, QString s, double rot, double , QPen p, QFont f)
{
    // add height too
    QFontMetrics fm(f);

    QGraphicsTextItem *t = new QGraphicsTextItem(s);
    t->setFont(f);
    t->setPos(x,-y-fm.height());
    t->setRotation(rot);
    t->setDefaultTextColor(p.color());

    scene->addItem(t);

}
Example #2
0
//=========================================================================
void BubbleChartView::prepareScene()
{
    QPen peng(Qt::black);
    peng.setWidth(1.5);
    QBrush brushg(Qt::transparent);
    chartRectGI = scene()->addRect(chartRect, peng, brushg);
    gGrid.addToGroup(chartRectGI);
    setHeader(/*chartData.header*/ "Chart header");
    ChartDataProvider *dp = dataProvider();
    if ( dp->data.size() == 0 )
        return;
    QPen pen(Qt::lightGray);
    pen.setWidth(0.05);
    QBrush brush(Qt::transparent);
    quint32 swidth = (int)this->sceneRect().height()*0.8;
    quint32 columnWidth = qMin((quint32)getConfig()->bubbleSize, swidth/dp->providers->count());
    grid.clear();
    for ( int i = 0; i < dp->providers->size(); i++ )
    {
        BlastTaxDataProvider *provider = dp->providers->at(i);
        for ( int j = 0; j < dp->data.count(); j++)
        {
            if ( !dp->data.at(j).checked )
                continue;
            const BlastTaxNodes &btns = dp->data.at(j).tax_nodes;
            BlastTaxNode *node = btns.at(i);
            if ( node != NULL )
            {
                quint32 sum = node->sum();
                if ( sum == 0 )
                    continue;
                CreateGraphNode(node, provider);
            }
        }
        qreal x1 = i*columnWidth;
        QGraphicsRectItem *gridItem  = scene()->addRect(chartRect.x()+x1, chartRect.y(), columnWidth, chartRect.height(), pen, brush);
        grid.append(gridItem);
        gGrid.addToGroup(gridItem);
        scene()->addItem(&gGrid);
        gGrid.setVisible(getConfig()->showGrid);
        // Create horizontal axe labels
        BlastTaxDataProvider *p = dp->providers->at(i);
        QString stxt = p->name;
        if ( stxt.length() > 30 )
        {
            stxt.truncate(27);
            stxt.append("...");
        }
        QGraphicsTextItem *item = scene()->addText(stxt);
        item->setToolTip(p->name);
        item->setRotation(45);
        horizontalLegend.append(item);
    }
    for ( int j = 0; j < dp->data.count(); j++)
    {
        const BlastTaxNodes &btns = dp->data.at(j).tax_nodes;
        QString txt;
        for ( int i = 0 ; i < btns.size(); i++ )
        {
            if ( btns[i] == NULL )
                continue;
            txt = btns[i]->getText();
            break;
        }
        QString stxt = txt;
        if ( stxt.length() > 30 )
        {
            stxt.truncate(27);
            stxt.append("...");
        }
        QGraphicsTextItem *item = scene()->addText(stxt);
        item->installEventFilter(this);
        item->setToolTip(txt);
        item->setVisible(dp->data.at(j).checked);
        verticalLegend.append(item);
    }

    header->setPos(0, 10-MARGIN);
    quint32 tw = header->textWidth();
    header->setTextWidth(qMax(tw, dp->providers->count()*columnWidth));
}
Example #3
0
void PSV_AxisDownItem::updateItem()
{
//    m_markFont.setPointSizeF(m_rect.width() * m_rect.height() * 0.0005);
    updateLabels();
    QPen linePen(QBrush(m_lineColor), m_lineWidth);
    QPen barPen(QBrush(m_markColor), m_markWidth);
    {
        QGraphicsLineItem* lineItem = new QGraphicsLineItem(this);
        lineItem->setPen(linePen);
        lineItem->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.top()
                          , m_rect.left(), m_rect.top());
        lineItem->setZValue(1);

        QGraphicsLineItem* arrowsItem_up = new QGraphicsLineItem(this);
        arrowsItem_up->setPen(linePen);
        arrowsItem_up->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.y()
                                 , m_rect.right() + m_arrowsLength, m_rect.y()- 0.5 * m_arrowsLength);
        arrowsItem_up->setZValue(1);

        QGraphicsLineItem* arrowsItem_right = new QGraphicsLineItem(this);
        arrowsItem_right->setPen(linePen);
        arrowsItem_right->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.y()
                                  , m_rect.right() + m_arrowsLength, m_rect.y() + 0.5 * m_arrowsLength);
        arrowsItem_right->setZValue(1);
    }
    int count = m_labelList.count();
    if(count <= 1)
    {
        return;
    }
    double dx = 0.0;
    double dy = 0.0;
    if(m_isCenter && m_isList)
    {
        dx = 0.5 * m_rect.width() / count;
    }
    else
    {
        count--;
    }

    double oneSpace = m_rect.width() / count;
    m_markPointList.clear();
    bool isRotate = false;
    qreal maxHeight = 0.0;;
    qreal maxWidth = 0.0;;
    if(m_isCenter && m_isList)
    {
        count = m_labelList.count() + 1;
    }
    else
    {
        count = m_labelList.count();
    }

    for(int index = 0; index < m_labelList.count(); ++index)
    {
        QPair<QVariant, QString> labelPair = m_labelList.at(index);
        QGraphicsTextItem* textItem = new QGraphicsTextItem(labelPair.second, this);
        textItem->setDefaultTextColor(m_defaultColor);
        textItem->setFont(m_markFont);
        qreal height = textItem->boundingRect().height();
        qreal width = textItem->boundingRect().width();
        if(index == 0)
        {
            if(width > oneSpace && height < 2*oneSpace)//ФЭК±ґ¦Ан
            {
               isRotate = true;
               maxHeight = width;
               maxWidth = height;
            }
            else
            {
                maxHeight = height;
                maxWidth = width;
            }
        }
        qreal x = m_rect.left() + (index * (m_rect.width())) / (count - 1);
        qreal y = m_rect.top() + m_markLength;
        if(isRotate)
        {
#if QT_VERSION > QT_VERSION_CHECK(4, 6, 0)
            textItem->setRotation(90);
#else
            textItem->rotate(90);
#endif

            textItem->setPos(x + 0.5 * height, y);
            if(maxHeight < width)
            {
                maxHeight = width;
            }
            if(maxWidth < height)
            {
                maxWidth = height;
            }
        }
        else
        {
            textItem->setPos(x - 0.5 * width, y);
            if(maxHeight < height)
            {
                maxHeight = height;
            }
            if(maxWidth < width)
            {
                maxWidth = width;
            }
        }
        textItem->moveBy(dx,dy);
        QGraphicsLineItem *lineItem = new QGraphicsLineItem(this);
        lineItem->setPen(barPen);
        if(index != 0 && index != count -1)
        {
            lineItem->setLine(x - 0.5 * barPen.width(), m_rect.top(), x - 0.5 * barPen.width(), m_rect.top() + m_markLength);
        }
        else
        {
            lineItem->setLine(x, m_rect.top(), x, m_rect.top() + m_markLength);
        }
        m_markPointList.append(QPointF(x - 0.5 * barPen.width(), m_rect.top()));
    }
    //=================
    m_validRect =  QRectF(m_rect.x() - 0.5 * maxWidth
                          ,m_rect.y()
                          ,m_rect.width() + maxWidth
                          ,m_markLength + maxHeight);
//    QGraphicsRectItem *item = new QGraphicsRectItem(m_validRect,this);
}
Example #4
0
void MainWindow::create_graphic()
{
    ui->graphicsView->setRenderHint(QPainter::Antialiasing, true);
   /* int sizew=1536;//1400;
    int sizeh=668;
    int space=40;

    int const_for_ky=25.5;
    int const_for_kx=10.971;*/

    int sizew=1036;//1400;
    int sizeh=536;
    int space=40;

    int const_for_ky=20.5;
    int const_for_kx=10.971;

    int shift_y=300;




    sc=new QGraphicsScene(0,0,sizew,sizeh,ui->graphicsView);

    QPen pen(QBrush(QColor(139,134,130),Qt::SolidPattern),4,Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin);
    pen.setColor(QColor(139,119,101));
    sc->addLine(space,space,space,sizeh-space,pen);
    sc->addLine(space,sizeh-space,sizew-space,sizeh-space,pen);

    float ky=sizeh*const_for_ky;//18000;
    float kx=sizew/const_for_kx;//140;
    float x1,y1,x2,y2;



    //mu_lines
    int max_len=45;
    QMap<int,QString> mu_text;
    for(int i=0;i<periods.size();i++)
    {
        if(mu_text[periods[i].nod].length()>max_len)
        {
            if(mu_text[periods[i].nod][mu_text[periods[i].nod].length()-1]!='.')
                mu_text[periods[i].nod]+=" ...";
            continue;
        }

        if(mu_text[periods[i].nod].length()==0)
            mu_text[periods[i].nod]+=periods[i].substr;//+QString().sprintf("(%d)",periods[i].indexes.size());
        else
            mu_text[periods[i].nod]+="," + periods[i].substr;//+QString().sprintf("(%d)",periods[i].indexes.size());
    }


    QMap<int,int> temp;
    for(int i=periods.size()-1;i>=0;i--)
    {
        if(temp[periods[i].nod]==0)
        {
            temp[periods[i].nod]=1;
            x1 = space + (periods[i].nod-1)*kx;
            y1 = (temp.size()+1)*space;

            x2 = space + (periods[i].nod-1)*kx;
            if(periods[i].nod-1<corr_table.size())
                y2 = sizeh + shift_y - space - (float)(corr_table[periods[i].nod-1][1]*ky);
            else
                y2 = sizeh + shift_y - space - (float)(corr_table[corr_table.size()-1][1]*ky);

            QPen p(QColor(139,119,101,200),2,Qt::DotLine);
            if(i==mu)
                p.setColor(QColor(102,205,0));

            int ind=(periods[i].nod>7)?(corr_table.size()-1):(periods[i].nod-1);
            if(icx>corr_table[ind][3] && icx<corr_table[ind][2])
                p.setColor(QColor(102,205,0));
            else
            {
                if(icx>corr_table[ind][1] && icx<corr_table[ind][3])
                    p.setColor(QColor(255,215,0));
                else
                    p.setColor(QColor(178,34,34));
            }



            sc->addLine(x1,y1,x2,y2,p);
            sc->addLine(x1-space/4,y1+space/4,(x1-space/4)+30+(mu_text[periods[i].nod].length()*7),y1+space/4,p);



            QGraphicsTextItem *t;
            t=new QGraphicsTextItem(mu_text[periods[i].nod]);
            t->setDefaultTextColor(QColor(p.color().red()-30,p.color().green()-30,p.color().blue()));//(238,130,98));
            t->setPos(x1,y1+space/4-22);
            sc->addItem(t);



        }
    }




    //icx
    x1=space;
    y1=sizeh + shift_y - space - (float)(icx*ky);
    x2=sizew-space;
    y2=sizeh + shift_y - space - (float)(icx*ky);
    sc->addLine(x1,y1,x2,y2,QPen(QColor(139,119,101,200),2,Qt::DashLine));


    int per_lim;
    if(periods.size()!=0 && corr_table.size()<periods[0].nod)
    {
        per_lim=periods[0].nod-1;
    }
    else
        per_lim=corr_table.size()-1;

    //оси и точки и icmni sr max
    pen.setColor(QColor(205,175,149));
    for(int j=1;j<corr_table[0].size();j++)
    {
        for(int i=0;i<per_lim;i++)
        {
            if(i>=corr_table.size()-1)
            {
                x1 = x2;
                y1 = y2;

                x2 = space + (i+1)*kx;
                y2 = y2;
            }
            else
            {
                x1 = space + (corr_table[i][0]-1)*kx;
                y1 = sizeh + shift_y - space - (float)(corr_table[i][j]*ky);

                x2 = space + (corr_table[i+1][0]-1)*kx;
                y2 = sizeh + shift_y - space - (float)(corr_table[i+1][j]*ky);
            }
            sc->addLine(x1,y1,x2,y2,QPen(QBrush(QColor(205,175,149),Qt::SolidPattern),4,Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
            sc->addEllipse(x1-4,y1-4,8,8,QPen(QColor(139,119,101),2),QBrush(QColor(205,175,149)));


            sc->addLine(x2,sizeh-space-5,x2,sizeh-space+5,QPen(QBrush(QColor(139,134,130),Qt::SolidPattern),4,Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));

            QGraphicsTextItem *t;
            t=new QGraphicsTextItem(QString().sprintf("%d",i+2));
            t->setDefaultTextColor(QColor(139,134,130));
            t->setPos(x2-7,sizeh-space+3);
            sc->addItem(t);


            if(i==0)
            {
                sc->addEllipse(x1-5,sizeh-space-5,10,10,QPen(QColor(139,119,101),2),QBrush(QColor(139,134,130)));
                t=new QGraphicsTextItem(QString().sprintf("%d",i+1));
                t->setDefaultTextColor(QColor(139,134,130));
                t->setPos(x1-7,sizeh-space+3);
                sc->addItem(t);
            }

        }

    }

    sc->addEllipse(x2-4,y2-4,8,8,QPen(QColor(139,119,101),2),QBrush(QColor(205,175,149)));


    //подписи графиков

    for(int i=1;i<corr_table[0].size();i++)
    {
        x1=(corr_table[1][0]-1)*kx;
        y1 = sizeh + shift_y - space - (float)(corr_table[1][i]*ky);
        x2 = space + (corr_table[2][0]-1)*kx;
        y2 = sizeh + shift_y - space - (float)(corr_table[2][i]*ky);
        float xs,ys;
        xs=(x1+x2)/2;
        ys=(y1+y2)/2;

        QGraphicsTextItem *t;

        switch(i)
        {
        case 1:
            t=new QGraphicsTextItem("Ic(x)min");
            t->setPos(xs-15,ys-55);
            t->setRotation(23);
            break;
        case 2:
            t=new QGraphicsTextItem("Ic(x)max");
            t->setPos(xs+11,ys-70);
            t->setRotation(52);
            break;
        case 3:
            t=new QGraphicsTextItem("Ic(x)sr.");
            t->setPos(xs+11,ys-50);
            t->setRotation(34);
            break;
        }


        t->setDefaultTextColor(QColor(139,134,130));
        t->setFont(QFont(t->font().family(),15,11,true));

        sc->addItem(t);

    }

    QGraphicsTextItem *t;
    t=new QGraphicsTextItem("Ic(x)=" + QString().sprintf("%0.4f",icx));
    t->setDefaultTextColor(QColor(139,134,130));
    t->setFont(QFont(t->font().family(),15,11,true));
    t->setPos(sizew-5*space,sizeh + shift_y - space - (icx*ky)-40);
    sc->addItem(t);

    t=new QGraphicsTextItem("μ");
    t->setDefaultTextColor(QColor(139,134,130));
    t->setFont(QFont(t->font().family(),15,11,true));
    t->setPos(sizew-space-2,sizeh - space-2);
    sc->addItem(t);
    pen.setColor(QColor(139,119,101));
    sc->addLine(sizew-space,sizeh - space,sizew-space-10,sizeh - space-8,pen);
    sc->addLine(sizew-space,sizeh - space,sizew-space-10,sizeh - space+8,pen);
    t=new QGraphicsTextItem("Ic(x)");
    t->setDefaultTextColor(QColor(139,134,130));
    t->setFont(QFont(t->font().family(),15,11,true));
    t->setPos(space+2,space+2);
    sc->addItem(t);
    pen.setColor(QColor(139,119,101));
    sc->addLine(space,space,space-8,space+10,pen);
    sc->addLine(space,space,space+8,space+10,pen);


    for(int i=1;i<corr_table[0].size();i++)
    {
        t=new QGraphicsTextItem(QString().sprintf("%0.3f",corr_table[0][i]));
        t->setDefaultTextColor(QColor(139,134,130));
        t->setFont(QFont(t->font().family(),10,11,true));
        t->setPos(space + (corr_table[0][0]-1)*kx-52,sizeh + shift_y - space - (float)(corr_table[0][i]*ky)+25);
        t->setRotation(-45);
        sc->addItem(t);
    }




    ui->graphicsView->setScene(sc);
    //ui->graphicsView->fitInView(0,0,sizew,sizeh);
    // ui->graphicsView->scale(10,-1);
}