Example #1
0
Marker* readMarkers(const char* path)
{
    Marker* head;
    char name[20];
    double ratio;
    FILE* file;

    file = fopen(path, "r");
    if (!file)
    {
        fprintf(stderr, "Failed to open file (%s).\n", path);
        exit(EXIT_FAILURE);
    }

    head = NULL;
    while (fscanf(file, "%19s%lf", name, &ratio) != EOF)
    {
        fgetc(file); // Skip '\n'
        head = insertMarker(head, makeMarker(strCopy(name), ratio));
    }

    fclose(file);

    return head;
}
/*!
  This function is a shortcut to insert a horizontal or vertical
  line marker, dependent on the specified axis.
  \param label Label
  \param axis Axis to be attached
  \return New key if the marker could be inserted, 0 if not.
*/
long QwtPlot::insertLineMarker(const QString &label, int axis)
{
    QwtMarker::LineStyle lineStyle = QwtMarker::NoLine;
    int xAxis = QwtPlot::xBottom;
    int yAxis = QwtPlot::yLeft;

    switch(axis)
    {
        case yLeft:
        case yRight:
            yAxis = axis;
            lineStyle = QwtMarker::HLine;
            break;
        case xTop:
        case xBottom:
            xAxis = axis;
            lineStyle = QwtMarker::VLine;
            break;
    }

    QwtPlotMarker *marker = new QwtPlotMarker(this);
    if ( marker == 0 )
        return 0;

    marker->setAxis(xAxis, yAxis);
    marker->setLabel(label);
    marker->setLineStyle(lineStyle);
    marker->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);

    long key = insertMarker(marker);
    if ( key == 0 )
        delete marker;

    return key;
}
Example #3
0
Marker* distribute(File* hw, Marker* markers)
{
    double sumRatio;
    int numHWs;
    int numHWsParRatio;
    int numMarkHWs;
    Marker* it;
    Marker* tmp;
    Marker* result;
    int i;
    int r;

    sumRatio = 0;
    for (it = markers; it; it = it->next)
    {
        sumRatio += it->ratio;
    }
    
    numHWs = numFiles(hw);
    numHWsParRatio = (int)(numHWs / sumRatio + EPSILON);

    for (it = markers; it; it = it->next)
    {
        numMarkHWs = (int)(numHWsParRatio * it->ratio + EPSILON);
        for (int i = 0; i < numMarkHWs; ++i)
        {
            it->files = insertFile(it->files, removeFrontFile(&hw));
        }
    }

    result = NULL;
    for (i = numMarkers(markers); hw; --i)
    {
        r = rand() % i;
        tmp = removeMarker(&markers, r);
        tmp->files = insertFile(tmp->files, removeFrontFile(&hw));
        result = insertMarker(result, tmp);
    }

    while (markers)
    {
        result = insertMarker(result, removeMarker(&markers, 0));
    }

    return result;
}
/*!
  \brief Insert a new marker
  \param label Label
  \param xAxis X axis to be attached
  \param yAxis Y axis to be attached
  \return New key if the marker could be inserted, 0 if not.
*/
long QwtPlot::insertMarker(const QString &label, int xAxis, int yAxis)
{
    QwtPlotMarker *marker = new QwtPlotMarker(this);
    if ( marker == 0 )
        return 0;

    marker->setAxis(xAxis, yAxis);
    marker->setLabel(label);

    long key = insertMarker(marker);
    if ( key == 0 )
        delete marker;

    return key;
}