Ejemplo n.º 1
0
void ShellSort::initializeAnimation() {
//    Drawing some nice text to help with gap size:
    m_explanationText= new QGraphicsTextItem("Current gap size is: "+QString::number(arrayElements().size()/2));
    m_explanationText->setFont(QFont("Arial", 16, -1, true));
    m_explanationText->setProperty("pos", QPointF(0, this->height()-m_explanationText->boundingRect().height()));
    this->addItem(m_explanationText);
//    Continuing with animation initialization:
    vector<double> varray= values();
    int n=varray.size();
    for (int gap = n/2; gap > 0; gap /= 2) {
        m_operations.push_back([=, this](){ setCurrentGapText(gap);});
        for (int i = gap; i < n; i++) {
            for (int j=i-gap; j>=0; j-=gap) {
                m_operations.push_back([=,this](){operationCompareElements(j, j+gap); highlightLine(13);});
                if (varray[j] > varray[j+gap]) {
                    m_operations.push_back([=,this](){operationSwapElements(j, j+gap); highlightLine(14);});
                    double tmp=varray[j];
                    varray[j]=varray[j+gap];
                    varray[j+gap]=tmp;
                }
                else
                    break;
            }
        }
    }
    m_animationInitialized=true;
    m_currentStepInAnimation= 0;
    m_numberOfStepsInAnimation= m_operations.size();
}
Ejemplo n.º 2
0
QString TypeInfo::toString() const
{
    QString tmp;

    tmp += m_qualifiedName.join("::");
    if (isConstant())
        tmp += QLatin1String(" const");

    if (isVolatile())
        tmp += QLatin1String(" volatile");

    if (indirections())
        tmp += QString(indirections(), QLatin1Char('*'));

    if (isReference())
        tmp += QLatin1Char('&');

    if (isFunctionPointer()) {
        tmp += QLatin1String(" (*)(");
        for (int i = 0; i < m_arguments.count(); ++i) {
            if (i != 0)
                tmp += QLatin1String(", ");

            tmp += m_arguments.at(i).toString();
        }
        tmp += QLatin1String(")");
    }

    foreach(QString elt, arrayElements()) {
        tmp += QLatin1String("[");
        tmp += elt;
        tmp += QLatin1String("]");
    }