Ejemplo n.º 1
0
int GradientStopEditor::addStop( int newStopValue, qreal newStopPosition, bool emitSignalsAndUpdate )
{
	if( newStopValue < 0 )
		newStopValue = 0;

	if( newStopValue > 255 )
		newStopValue = 255;

	if( newStopPosition < 0 )
		newStopPosition = 0;

	if( newStopPosition > 1.0 )
		newStopPosition = 1.0;

	int countStops = values.size();
	for( int i = 1; i < countStops - 1; i++ )
	{
		if( positions[i] < newStopPosition )
			continue;

		values.insert( i, newStopValue );
		positions.insert( i, newStopPosition );
		if( emitSignalsAndUpdate )
		{
			emit stopAdded( newStopValue, newStopPosition, i );
			if( stopChannel == composite )
				generateBackground( true );
			update();
		}
		return i;
		break;
	}

	values.insert( values.size() - 1, newStopValue );
	positions.insert( positions.size() - 1, newStopPosition );
	if( emitSignalsAndUpdate )
	{
		emit stopAdded( newStopValue, newStopPosition, values.size() - 2 );
		if( stopChannel == composite )
			generateBackground( true );
		update();
	}
	return ( values.size() - 2 );
}
Ejemplo n.º 2
0
void bacra::RouteContainer::stopDataReceived(const QString &data)
{
    qDebug() << "RouteContainer::stopDataReceived()";
    QStringList stopNameAndLine = data.split(';');
    if (stopNameAndLine.size() != 2) {
        qDebug() << "invalid data";
        return;
    }
    QRegExp rx(".+[(](\\d{1,6})[)]");
    rx.indexIn(stopNameAndLine.at(0));
    QString stopId = rx.cap(1);
    QList<Route *>::ConstIterator it;
    bool routeUpdated = false;
    for (it = mRoutes.begin(); it != mRoutes.end(); it++) {
        qDebug() << "checking " << (*it)->stopId();
        if ((*it)->stopId() == stopId) {
              (*it)->parseLines(data);
              emit updatedDepartures();
              routeUpdated = true;
              qDebug() << "updating " << stopId;
        }
    }
    if (routeUpdated) {
        emit stopAdded();
        return;
    }

    Route *r = bacra::RouteFactory::createStop(data);
    if (!r->parseLines(data)) {
        qDebug() << "RouteContainer::stopDataReceived()";
        emit invalidStop();
        return;
    }

    beginInsertRows(QModelIndex(), 0, 0);
    mRoutes.prepend(r);
    endInsertRows();

    //ok for testing purpose save
    //saveRoutes("./savedata.txt");

    emit stopAdded();
}
Ejemplo n.º 3
0
QtGradientStop *QtGradientStopsModel::addStop(qreal pos, const QColor &color)
{
    qreal newPos = pos;
    if (pos < 0.0)
        newPos = 0.0;
    if (pos > 1.0)
        newPos = 1.0;
    if (d_ptr->m_posToStop.contains(newPos))
        return 0;
    QtGradientStop *stop = new QtGradientStop();
    stop->setPosition(newPos);
    stop->setColor(color);

    d_ptr->m_posToStop[newPos] = stop;
    d_ptr->m_stopToPos[stop] = newPos;

    emit stopAdded(stop);

    return stop;
}
Ejemplo n.º 4
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{

    // NOTE: these dataextractors are deleted by
    // routecontainer class instance.
    dataExtractor = new bacra::DataExtractor();
    dataExtractor->initialize();
    dataExtractor2 = new bacra::DataExtractor();
    dataExtractor2->initialize();


    routeContainer = new bacra::RouteContainer(dataExtractor, this);
    stopContainer = new bacra::RouteContainer(dataExtractor2, this);
    stopDelegate = new bacra::StopDelegate(this);
    routeDelegate = new bacra::StopDelegate(this);



    ui->setupUi(this);



    QRegExp rx("\\d{0,6}");
    QValidator *validator = new QRegExpValidator(rx, this);
    ui->stopLineEdit->setValidator(validator);

    ui->routesView->setModel(routeContainer);
    ui->routesView->setItemDelegate(new bacra::StopDelegate());

    ui->stopsView->setModel(stopContainer);
    ui->stopsView->setItemDelegate(new bacra::StopDelegate());

    ui->tab_2->setDisabled(true);

    ui->progressBar->setVisible(false);

    //ui->stopsView->setStyleSheet("QTableView {background: url(:/bacra/images/bacra.png); background-attachment: fixed; background-position: bottom-center;}");
    //ui->departuresView->setStyleSheet("QTableView {background: url(:/bacra/images/bacra.png); background-attachment: fixed; background-position: bottom-center;}");
    //ui->routesView->setStyleSheet("QTableView {background: url(:/bacra/images/bacra.png); background-attachment: fixed; background-position: bottom-center;}");
    ui->addStopButton->setIcon(QIcon(":/bacra/images/add.png"));

    ui->stopsView->setDragEnabled(true);
    ui->stopsView->setAcceptDrops(true);

    connect(stopContainer, SIGNAL(updatedDepartures()), ui->departuresView, SLOT(setFocus()));

    connect(dataExtractor, SIGNAL(infoResponseReady(int)), ui->progressBar, SLOT(setValue(int)));
    connect(dataExtractor2, SIGNAL(infoResponseReady(int)), ui->progressBar, SLOT(setValue(int)));

    connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(commercialAnnouncement(int)));

    connect(ui->fromLineEdit, SIGNAL(returnPressed()), ui->toLineEdit, SLOT(setFocus()));
    connect(ui->toLineEdit, SIGNAL(returnPressed()), ui->addRouteButton, SLOT(click()));
    connect(ui->addRouteButton, SIGNAL(clicked()), this, SLOT(addRouteClicked()));
    connect(this, SIGNAL(addRoute(QString, QString)), routeContainer, SLOT(addRouteItem(QString, QString)));

    connect(ui->stopLineEdit, SIGNAL(returnPressed()), ui->addStopButton, SLOT(click()));
    connect(ui->addStopButton, SIGNAL(clicked()), this, SLOT(addStopClicked()));
    connect(this, SIGNAL(addStop(QString)), stopContainer, SLOT(addStopItem(QString)));
    connect(ui->stopsView, SIGNAL(clicked(QModelIndex)), stopContainer, SLOT(indexSelected(QModelIndex)));
    connect(ui->routesView, SIGNAL(clicked(QModelIndex)), routeContainer, SLOT(indexSelected(QModelIndex)));

    connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(updateDepartures()));
    
    connect(stopContainer, SIGNAL(dataChanged(QModelIndex,QModelIndex)), ui->stopsView, SLOT(dataChanged(QModelIndex,QModelIndex)));

    connect(routeContainer, SIGNAL(routeAdded()), this, SLOT(routeAdded()));
    connect(stopContainer, SIGNAL(stopAdded()), this, SLOT(stopAdded()));

    connect(stopContainer, SIGNAL(showDepartures(bacra::Route*)), this, SLOT(showDepartures(bacra::Route*)));

    connect(stopContainer, SIGNAL(invalidStop()), this, SLOT(invalidStop()));
    connect(routeContainer, SIGNAL(invalidRoute()), this, SLOT(invalidRoute()));

     //Loading routes from disk
     //setting ui so loaded stops display themselves
    //correctly
//    ui->stopsView->setColumnWidth(0, 170);
 //   ui->stopsView->setColumnWidth(1, 40);
    ui->stopsView->setColumnWidth(0, 180);
    ui->stopsView->setColumnWidth(1, 30);
    stopContainer->loadRoutes("./savedata.txt");
}