Ejemplo n.º 1
0
void printIncompatibleMessage(const AbstractInputSlot* slot, const std::string& typeName,
                              const AbstractData & data) {
    std::cout
        << "Trying to connect incompatible type "
        << data.qualifiedName() << " (" << data.type() << ")"
        << " to "
        << slot->qualifiedName() << " (" << typeName << ")"
        << std::endl;
}
Ejemplo n.º 2
0
// Read csv-file and save it's data to AbstractData-based container
// class
// @input:
// - filePath - string with absolute path to csv-file
// - data - AbstractData object where all file content will be saved
// - separator - string or character that separate values in a row
// @output:
// - bool - True if file was successfully read, otherwise False
bool Reader::readToData(const QString &filePath,
                        AbstractData &data,
                        const QString &separator)
{
    if ( filePath.isEmpty() || separator.isEmpty() )
    {
        qDebug() << __func__ << "Error - invalid arguments";
        return false;
    }

    if ( false == CheckFile(filePath) )
    {
        qDebug() << __func__ << "Error - wrong file path/name:" << filePath;
        return false;
    }

    QFile csvFile(filePath);
    if ( false == csvFile.open(QIODevice::ReadOnly | QIODevice::Text) )
    {
        qDebug() << __func__ << "Error - can't open file:" << filePath;
        return false;
    }

    QTextStream stream(&csvFile);
    while ( false == stream.atEnd() )
    {
        QString line = stream.readLine();
        data.addRow( line.split(separator) );
    }

    csvFile.close();

    return true;
}
Ejemplo n.º 3
0
// Write data to csv-file
// @input:
// - filePath - string with absolute path to csv-file
// - data - not empty AbstractData object that contains information that should
// be written to csv-file
// - separator - string or character that would separate values in a row
// (line) in csv-file
// - textDelimiter - string or character that enclose each element in a row
// - mode - write mode of the file
// - header - strings that will be written at the beginning of the file in
// one line. separator will be used as delimiter character.
// - footer - strings that will be written at the end of the file in
// one line. separator will be used as delimiter character.
// - codec - pointer to codec object that would be used for file writing
// @output:
// - bool - True if data was written to the file, otherwise False
bool Writer::write(const QString& filePath,
                   const AbstractData& data,
                   const QString& separator,
                   const QString& textDelimiter,
                   const WriteMode& mode,
                   const QStringList& header,
                   const QStringList& footer,
                   QTextCodec* codec)
{
    if ( filePath.isEmpty() )
    {
        qDebug() << __FUNCTION__ << "Error - empty path to file";
        return false;
    }

    if ( data.isEmpty() )
    {
        qDebug() << __FUNCTION__ << "Error - empty data";
        return false;
    }

    if ( false == CheckFile(filePath) )
    {
        qDebug() << __FUNCTION__ << "Error - wrong file path/name:" << filePath;
        return false;
    }

    ContentIterator content(data, separator, textDelimiter, header, footer);

    bool result = false;
    switch (mode)
    {
        case APPEND:
            result = WriterPrivate::appendToFile(filePath, content, codec);
            break;
        case REWRITE:
        default:
            result = WriterPrivate::overwriteFile(filePath, content, codec);
    }

    return result;
}
Ejemplo n.º 4
0
// Read csv-file and save it's data to AbstractData-based container class
// @input:
// - filePath - string with absolute path to csv-file
// - data - AbstractData object where all file content will be saved
// - separator - string or character that separate elements in a row
// - textDelimiter - string or character that enclose each element in a row
// - codec - pointer to codec object that would be used for file reading
// @output:
// - bool - True if file was successfully read, otherwise False
bool Reader::readToData(const QString& filePath,
                        AbstractData& data,
                        const QString& separator,
                        const QString& textDelimiter,
                        QTextCodec* codec)
{
    QList<QStringList> list;
    if (false == ReaderPrivate::read(filePath, list, separator, textDelimiter,
                                     codec))
    {
        return false;
    }

    for (int i = 0; i < list.size(); ++i)
    {
        data.addRow( list.at(i) );
    }

    return true;
}
Ejemplo n.º 5
0
void AbstractStage::addOutput(const std::string & name, AbstractData & output)
{
    output.setName(name);
    output.setOwner(this);
    m_outputs.insert(&output);
}