void
RideFileTableModel::setRide(RideFile *newride)
{
    // QPointer helps us check if the current ride has been deleted before trying to disconnect
    static QPointer<RideFileCommand> connection = NULL;
    if (connection) {
        disconnect(connection, SIGNAL(beginCommand(bool,RideCommand*)), this, SLOT(beginCommand(bool,RideCommand*)));
        disconnect(connection, SIGNAL(endCommand(bool,RideCommand*)), this, SLOT(endCommand(bool,RideCommand*)));
    }

    ride = newride;
    tooltips.clear(); // remove the tooltips -- rideEditor will set them (this is fugly, but efficient)

    if (ride) {

        // set the headings to reflect the data that is present
        setHeadings();

        // Trap commands
        connection = ride->command;
        connect(ride->command, SIGNAL(beginCommand(bool,RideCommand*)), this, SLOT(beginCommand(bool,RideCommand*)));
        connect(ride->command, SIGNAL(endCommand(bool,RideCommand*)), this, SLOT(endCommand(bool,RideCommand*)));

        // refresh
        emit layoutChanged();
    }
}
void
RideFileTableModel::endCommand(bool undo, RideCommand *cmd)
{
    switch (cmd->type) {

        case RideCommand::SetPointValue:
        {
            SetPointValueCommand *spv = (SetPointValueCommand*)cmd;
            QModelIndex cell(index(spv->row,headingsType.indexOf(spv->series)));
            dataChanged(cell, cell);
            break;
        }
        case RideCommand::InsertPoint:
            if (!undo) endInsertRows();
            else endRemoveRows();
            break;

        case RideCommand::DeletePoint:
        case RideCommand::DeletePoints:
            if (undo) endInsertRows();
            else endRemoveRows();
            break;

        case RideCommand::AppendPoints:
            if (undo) endRemoveRows();
            else endInsertRows();
            break;

        case RideCommand::SetDataPresent:
            setHeadings();
            emit layoutChanged();
            break;

        default:
            break;
    }
}
示例#3
0
Session::Session(const QString &name)
    : SessionItem(name), TreeModel(), documents() {
    setRoot(this);
    setHeadings({"Type", "Name", "File Name", "Editors"});
}