Exemplo n.º 1
0
void FlatProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
{
    if (QAbstractProxyModel::sourceModel()) {
        disconnect(QAbstractProxyModel::sourceModel(), nullptr, this, nullptr);
    }

    QAbstractProxyModel::setSourceModel(sourceModel);

    emit layoutAboutToBeChanged();
    removeSubTree(QModelIndex(), false /* don't emit removeRows() */);
    insertSubTree(QModelIndex(), false /* don't emit insertRows() */);
    emit layoutChanged();

    if (sourceModel) {
        connect(sourceModel, &QAbstractItemModel::columnsAboutToBeInserted, this, &FlatProxyModel::on_columnsAboutToBeInserted);
        connect(sourceModel, &QAbstractItemModel::columnsAboutToBeRemoved, this, &FlatProxyModel::on_columnsAboutToBeRemoved);
        connect(sourceModel, &QAbstractItemModel::columnsInserted, this, &FlatProxyModel::on_columnsInserted);
        connect(sourceModel, &QAbstractItemModel::columnsRemoved, this, &FlatProxyModel::on_columnsRemoved);

        connect(sourceModel, &QAbstractItemModel::dataChanged, this, &FlatProxyModel::on_dataChanged);
        // on_headerDataChanged(Qt::Orientation orientation, int first, int last)

        connect(sourceModel, &QAbstractItemModel::layoutAboutToBeChanged, this, &FlatProxyModel::on_layoutAboutToBeChanged);
        connect(sourceModel, &QAbstractItemModel::layoutChanged, this, &FlatProxyModel::on_layoutChanged);

        connect(sourceModel, &QAbstractItemModel::modelAboutToBeReset, this, &FlatProxyModel::on_modelAboutToBeReset);
        // void on_modelReset()

        connect(sourceModel, &QAbstractItemModel::rowsAboutToBeInserted, this, &FlatProxyModel::on_rowsAboutToBeInserted);
        connect(sourceModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &FlatProxyModel::on_rowsAboutToBeRemoved);
        connect(sourceModel, &QAbstractItemModel::rowsInserted, this, &FlatProxyModel::on_rowsInserted);
        connect(sourceModel, &QAbstractItemModel::rowsRemoved, this, &FlatProxyModel::on_rowsRemoved);
    }
}
Exemplo n.º 2
0
/*
 * getTreeFromFile
 * Function: Use a previously encoded file to create a EncodingTree
 * Parameters: The path to the encoded file
 * Return: The EncodingTree produced
 */
EncodingTree * getTreeFromFile(char * fileName)
{
    FILE * file;
    EncodingTree * eTree;
    EncodingTree * toAdd;
    char * charBinary;
    char * binaryString;
    char phrase[6] = {'\0'};
    char letter;
    int i;

    file = fopen(fileName, "r");
    if(file == NULL)
    {
        printf("Error: not enough memory\n");
        exit(0);
    }
    
    eTree = NULL;
    toAdd = NULL;
    i = 0;
    letter = '\0';
    charBinary = NULL;
    binaryString = NULL;

    /* Find the point in the file where ":ARC:" is found */
    while(strcmp(phrase, ":ARC:") != 0)
    {
        for(i = 0; i < 5; i ++)
        {
            phrase[i] = fgetc(file);
        }
        phrase[i] = '\0';
        for(i = 4; i > 0; i--)
        {
            ungetc(phrase[i], file);
        }
    }
    for(i = 0; i < 5; i++)
    {
       fgetc(file);
    }
    /***/
    letter = fgetc(file);
    while(letter != EOF)
    {
        /*printf("%c\n", letter);*/
        toAdd = createSubTree(letter);
        eTree = insertSubTree(eTree, toAdd);    
        letter = fgetc(file);
    }
    /*printTree(eTree);*/
    
    fclose(file);    
    return(eTree);
}
Exemplo n.º 3
0
void FlatProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
    if (QAbstractProxyModel::sourceModel()) {
        disconnect(QAbstractProxyModel::sourceModel(), 0, this, 0);
    }

    QAbstractProxyModel::setSourceModel(sourceModel);

    emit layoutAboutToBeChanged();
    removeSubTree(QModelIndex(), false /* don't emit removeRows() */);
    insertSubTree(QModelIndex(), false /* don't emit insertRows() */);
    emit layoutChanged();

    if (sourceModel) {
        connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
            this, SLOT(on_columnsAboutToBeInserted(const QModelIndex &, int, int)));
        connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
            this, SLOT(on_columnsAboutToBeRemoved(const QModelIndex &, int, int)));
        connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
            this, SLOT(on_columnsInserted(const QModelIndex &, int, int)));
        connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
            this, SLOT(on_columnsRemoved(const QModelIndex &, int, int)));

        connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
            this, SLOT(on_dataChanged(const QModelIndex &, const QModelIndex &)));
        // on_headerDataChanged(Qt::Orientation orientation, int first, int last)

        connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
            this, SLOT(on_layoutAboutToBeChanged()));
        connect(sourceModel, SIGNAL(layoutChanged()),
            this, SLOT(on_layoutChanged()));

        connect(sourceModel, SIGNAL(modelAboutToBeReset()),
            this, SLOT(on_modelAboutToBeReset()));
        // void on_modelReset()

        connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
            this, SLOT(on_rowsAboutToBeInserted(const QModelIndex &, int, int)));
        connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
            this, SLOT(on_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
        connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
            this, SLOT(on_rowsInserted(const QModelIndex &, int, int)));
        connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
            this, SLOT(on_rowsRemoved(const QModelIndex &, int, int)));
    }
}