Example #1
0
//! [11]
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (line != 0 && myMode == InsertLine) {
        QList<QGraphicsItem *> startItems = items(line->line().p1());
        if (startItems.count() && startItems.first() == line)
            startItems.removeFirst();
        QList<QGraphicsItem *> endItems = items(line->line().p2());
        if (endItems.count() && endItems.first() == line)
            endItems.removeFirst();

        removeItem(line);
        delete line;
//! [11] //! [12]

        if (startItems.count() > 0 && endItems.count() > 0 &&
            startItems.first()->type() == DiagramItem::Type &&
            endItems.first()->type() == DiagramItem::Type &&
            startItems.first() != endItems.first()) {
            DiagramItem *startItem =
                qgraphicsitem_cast<DiagramItem *>(startItems.first());
            DiagramItem *endItem =
                qgraphicsitem_cast<DiagramItem *>(endItems.first());
            Arrow *arrow = new Arrow(startItem, endItem);
            arrow->setColor(myLineColor);
            startItem->addArrow(arrow);
            endItem->addArrow(arrow);
            arrow->setZValue(-1000.0);
            addItem(arrow);
            arrow->updatePosition();
        }
    }
//! [12] //! [13]
    line = 0;
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
bool getAdmin1TranslationSubs(QString const &pathFile,
                              QList<QString> &listAdmin1Subs)
{
    QFile inputFile(pathFile);
    if(inputFile.open(QIODevice::ReadOnly))   {
        QString before = "\"";
        QString after = "";
        QTextStream in(&inputFile);
        while(!in.atEnd())   {
            QString line = in.readLine();

            // sometimes quotes are added in to
            // the translation substitutes file
            // so they should be removed
            line.replace(before,after);

            listAdmin1Subs.push_back(line);
        }

        listAdmin1Subs.removeFirst();   // should be 'BEGIN'
        listAdmin1Subs.removeLast();    // should be 'END'

        return true;
    }
    else   {
        return false;
    }
}
Example #3
0
void ChangeSet::apply_helper()
{
    // convert all ops to replace
    QList<EditOp> replaceList;
    {
        while (!m_operationList.isEmpty()) {
            const EditOp cmd(m_operationList.first());
            m_operationList.removeFirst();
            convertToReplace(cmd, &replaceList);
        }
    }

    // execute replaces
    if (m_cursor)
        m_cursor->beginEditBlock();

    while (!replaceList.isEmpty()) {
        const EditOp cmd(replaceList.first());
        replaceList.removeFirst();
        doReplace(cmd, &replaceList);
    }

    if (m_cursor)
        m_cursor->endEditBlock();
}
Example #4
0
void MainWindow::paint_shingles()
{
    QList<QStringList> set = dbuniq_dialog->shingles_similar;
    if (set.isEmpty())
        return;
    QString wrong_char = "?!., ;:\'\"\\/+><@#~`$%^&*(){}|\n\r\t\a\?-1234567890";
    QTextCursor cur(ui->textEdit->document());
    QChar end_of_buf;
    fake_text = ui->textEdit->toHtml();
    progress->setMaximum(ui->textEdit->toPlainText().length());
    off_ct = true;
    QString word;
    QStringList founded_set;
    QTextCharFormat format;
    format.setBackground(QBrush(QColor("yellow")));
    int word_length = 0;
    while (cur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor))
    {
        word_length++;
        progress->setValue(progress->value()+1);
        word = cur.selectedText().right(word_length);
        end_of_buf = word[word.length()-1];
        if (wrong_char.contains(end_of_buf) || end_of_buf.unicode()==8233)
        {
            word.remove(word.length()-1,1);
            if  (word.length()>3)
            {
                if (founded_set.length()<set[0].length())
                    founded_set<<word;
                else
                {
                    if (founded_set == set[0])
                    {
                        word = cur.selectedText();
                        cur.removeSelectedText();
                        cur.insertText(word,format);
                    }
                    else
                    {
                        founded_set.clear();
                        set.removeFirst();
                    }
                    cur.clearSelection();
                }
            }
            word_length=0;
        }
    }
    if (founded_set == set[0])
    {
        word = cur.selectedText();
        cur.removeSelectedText();
        cur.insertText(word,format);
    }
    off_ct = false;
}
Example #5
0
ListItem::ListItem(QList<QVariant>& data, ListItem* const parent)
    : d(new Private())
{
    d->parentItem = parent;
    d->itemData.append(data);

    data.removeFirst();

    foreach (const QVariant& val, data)
    {
        d->tagIds.append(val.toInt());
    }
Example #6
0
/* TODO Old system. Random generation of matches.
 *
 * Should generate next matches on the fly !
 * Even over few next phases
 */
void FourMatchesContest::generateNextMatchList()
{
  QList<Team> teamsList = TeamModel::getInstance()->getRawData();

  Util<Team>::shuffle( &teamsList );
  //qDebug() << "Is teamsList.size() even ? " << (teamsList.size() % 2 == 0);

  if( teamsList.size() % 2 != 0 && mState != NOT_STARTED_YET) {
      QList<Team> mustPlay = getTeamsAlreadyBeenExempt();
//      qDebug() << "Must play :";
//      Q_FOREACH(Team team, mustPlay) {
//          qDebug() << team.getName();
//      }
//      qDebug() << "";

      while( !mustPlay.isEmpty() ) {
        QList<Team> teamsAvailable = teamsAvailableToPlayAgainst( mustPlay.first(), teamsList );
        //qDebug() << "New match " << teamsList.first().getName() << " vs " << teamsAvailable.first().getName();
        addMatchToCurrentPhase( mustPlay.first(), teamsAvailable.first() );
        teamsList.removeOne( mustPlay.first() );
        teamsList.removeOne( teamsAvailable.first() );
        mustPlay.removeFirst();
      }
  }

  while( !teamsList.isEmpty() ) {
    //qDebug() << " >> teamsList.size() == " << teamsList.size();
    if( teamsList.size() > 1 ) {
      QList<Team> teamsAvailable = teamsAvailableToPlayAgainst( teamsList.first(), teamsList );
      //qDebug() << "New match " << teamsList.first().getName() << " vs " << teamsAvailable.first().getName();
      addMatchToCurrentPhase( teamsList.first(), teamsAvailable.first() );
      teamsList.removeFirst();
      teamsList.removeOne( teamsAvailable.first() );
    } else if( teamsList.size() == 1 ) {
        //qDebug() << "Generate last match with " << teamsList.first().getName();
        addMatchToCurrentPhase( teamsList.first(), Team() );
        teamsList.removeFirst();
    }
  }
}
void QwwSmtpClientPrivate::sendRcpt() {
    SMTPCommand &cmd = commandqueue.head();
    QVariantList vlist = cmd.data.toList();
    QList<QVariant> rcptlist = vlist.at(1).toList();
    QByteArray buf = QByteArray("RCPT TO:<").append(rcptlist.first().toByteArray()).append(">\r\n");
    qDebug() << "SMTP >>>" << buf;
    socket->write(buf);
    rcptlist.removeFirst();
    vlist[1] = rcptlist;
    cmd.data = vlist;

    if (rcptlist.isEmpty()) cmd.extra = 1;
}
SplitRideDialog::SplitRideDialog(MainWindow *mainWindow)
    : mainWindow(mainWindow)
{
    setAttribute(Qt::WA_DeleteOnClose);
    setWindowTitle("Split Ride");

    listWidget = new QListWidget(this);
    listWidget->setSelectionMode(QAbstractItemView::SingleSelection);

    QLabel *splitLabel = new QLabel(tr("Split at the following positions:"), this);
    QLabel *labelSpacer = new QLabel(this);
    labelSpacer->setIndent(10);

    okButton = new QPushButton(tr("&OK"), this);
    cancelButton = new QPushButton(tr("&Cancel"), this);

    connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
    connect(listWidget,
            SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);

    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->addWidget(splitLabel);
    mainLayout->addWidget(listWidget);
    mainLayout->addWidget(labelSpacer);
    mainLayout->addLayout(buttonLayout);

    const RideFile *ride = mainWindow->currentRide();
    QMap<int,QString> splitPoints;

    QList<RideFileInterval> intervals = ride->intervals();
    if (!intervals.empty()) {
        intervals.removeFirst();
        foreach (RideFileInterval interval, intervals) {
            int nDataPoint = ride->intervalBegin(interval);
            QString strDesc = QString("Interval %1").arg(interval.name);
            splitPoints.insert(nDataPoint, strDesc);
        }
Example #9
0
void MainWindow::readPendingDatagrams()
{
    QByteArray payload;
    QByteArray Type;
    QList<QByteArray> byte;

    while (udpSocket->hasPendingDatagrams()) {
        payload.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(payload.data(), payload.size());
    }
    qDebug()<<payload<<endl;
    ui->ready_bar->setValue(80);

    if (QString::compare(payload.data(),"Invalid Option",Qt::CaseInsensitive)==0)
    {
        qDebug()<<"Invalid Option"<<endl;
    }
    else
    {
        byte=payload.split('+');
        byte.removeFirst();
        byte.removeLast();

        Type=byte.takeFirst();

        if(QString::compare(Type.data(),"OMR",Qt::CaseInsensitive)==0)
        {
            OP=byte.takeFirst();
            Read_Write=byte.takeFirst();
            Polarity=byte.takeFirst();
            PS=byte.takeFirst();
            Disc_CSM_SPM=byte.takeFirst();
            TP=byte.takeFirst();
            Count_L=byte.takeFirst();
            byte.removeFirst();
            byte.removeFirst();
            byte.removeFirst();
            byte.removeFirst();
            Equalization=byte.takeFirst();
            Colour_Mode=byte.takeFirst();
            Pixel_Mode=byte.takeFirst();
            byte.removeFirst();
            Gain_Mode=byte.takeFirst();
            byte.removeFirst();
            byte.removeFirst();
            byte.removeFirst();
            Time=byte.takeFirst();
            NImage=byte.takeFirst();
            Gap=byte.takeFirst();
            RCount=byte.takeFirst();

            ui->Aquire_Time_Input->setText(Time);
            ui->Gap_Input->setText(Gap);
            ui->NImages_Input->setText(NImage);
            ui->Read_Counter_Input->setCurrentIndex(RCount.toInt());
            ui->Polarity_Input->setCurrentIndex(Polarity.toInt());
            ui->Colour_Mode_Input->setCurrentIndex(Colour_Mode.toInt());
            ui->Read_Write_Input->setCurrentIndex(Read_Write.toInt());
            ui->Disc_CSM_SPM_Input->setCurrentIndex(Disc_CSM_SPM.toInt());
            ui->Output_Input->setCurrentIndex(PS.toInt());
            ui->Count_L_Input->setCurrentIndex(Count_L.toInt());
            ui->Gain_Mode_Input->setCurrentIndex(Gain_Mode.toInt());
            ui->Pixel_Mode_Input->setCurrentIndex(Pixel_Mode.toInt());
        }
        else if(QString::compare(Type.data(),"DAC",Qt::CaseInsensitive)==0)
        {
            th0=byte.takeFirst();
            th1=byte.takeFirst();
            th2=byte.takeFirst();
            th3=byte.takeFirst();
            th4=byte.takeFirst();
            th5=byte.takeFirst();
            th6=byte.takeFirst();
            th7=byte.takeFirst();
            preamp=byte.takeFirst();
            ikrum=byte.takeFirst();
            shaper=byte.takeFirst();
            disc=byte.takeFirst();
            discls=byte.takeFirst();
            shapertest=byte.takeFirst();
            dacdiscl=byte.takeFirst();
            dactest=byte.takeFirst();
            dacdisch=byte.takeFirst();
            delay=byte.takeFirst();
            tpbufferin=byte.takeFirst();
            tpbufferout=byte.takeFirst();
            rpz=byte.takeFirst();
            gnd=byte.takeFirst();
            tpref=byte.takeFirst();
            fbk=byte.takeFirst();
            cas=byte.takeFirst();
            tprefa=byte.takeFirst();
            tprefb=byte.takeFirst();

            ui->TH0_Input->setText(th0);
            ui->TH1_Input->setText(th1);
            ui->TH2_Input->setText(th2);
            ui->TH3_Input->setText(th3);
            ui->TH4_Input->setText(th4);
            ui->TH5_Input->setText(th5);
            ui->TH6_Input->setText(th6);
            ui->TH7_Input->setText(th7);
            ui->IPREAMP_Input->setText(preamp);
            ui->IKRUM_Input->setText(ikrum);
            ui->ISHAPER_Input->setText(shaper);
            ui->IDISC_Input->setText(disc);
            ui->IDISCLS_Input->setText(discls);
            ui->ISHAPERTEST_Input->setText(shapertest);
            ui->IDACDISCL_Input->setText(dacdiscl);
            ui->IDAC_Test_Input->setText(dactest);
            ui->IDACDISCH_Input->setText(dacdisch);
            ui->IDELAY_Input->setText(delay);
            ui->ITPBUFFERIN_Input->setText(tpbufferin);
            ui->ITPBUFFEROUT_Input->setText(tpbufferout);
            ui->VRPZ_Input->setText(rpz);
            ui->VGND_Input->setText(gnd);
            ui->VTPREF_Input->setText(tpref);
            ui->VFBK_Input->setText(fbk);
            ui->VCAS_Input->setText(cas);
            ui->VTPREFA_Input->setText(tprefa);
            ui->VTPREFB_Input->setText(tprefb);
        }
        else if(QString::compare(Type.data(),"SEND",Qt::CaseInsensitive)==0)
        {
            Send_Ip=byte.takeFirst();
            Send_Port=byte.takeFirst();
            Send_Mac=byte.takeFirst();
            byte.removeFirst();
            Host_Ip=byte.takeFirst();
            Host_Net=byte.takeFirst();

            ui->SENDIP_Input->setText(Send_Ip);
            ui->SENDPORT_Input->setText(Send_Port);
            ui->SENDMAC_Input->setText(Send_Mac);

            ui->HOSTIP_Input->setText(Host_Ip);
            ui->HOSTNETMASK_Input->setText(Host_Net);
        }
        ui->ready_bar->setValue(100);
    }
}
/*!\brief reimplementation of the mouseReleaseEvent
 *
 * ...
 */
void LaunchFileView::mouseReleaseEvent(QMouseEvent *event)
{

    if (_handScrolling) {
        _handScrolling = false;
        viewport()->setCursor(_savedCursor);

        event->accept();
        return;
    }
    if (itemAt((event->pos()))){ //else tool crashes
        if (myMode== DeleteItem && event->button() == Qt::LeftButton) {

            if (itemAt(event->pos())->type() == NodeItem::Type) {

                qgraphicsitem_cast<NodeItem *>(itemAt(event->pos()))->removeArrows();
                scene()->removeItem(itemAt(event->pos())); ///removes the Node from the scene
            } else if (itemAt(event->pos())->type() == 8){  // Don't try to kill the View
                if (itemAt(event->pos())->parentItem()->type() == NodeItem::Type){
                    qgraphicsitem_cast<NodeItem *>((itemAt(event->pos()))->parentItem())->removeArrows();
                    scene()->removeItem((itemAt(event->pos()))->parentItem()); ///removes the Node from the scene
                }else
                    scene()->removeItem((itemAt(event->pos()))->parentItem()); ///removes the Parameter

            }else if(itemAt(event->pos())->type() == GroupItem::Type) {
                QList<QGraphicsItem *> list;
                list=itemAt(event->pos())->childItems();
                //qDebug()<<"Begin group items->";

                for (int i = 0; i < list.size(); i++) {
                    if (list.at(i)->type() != 8)

                        (list.at(i))->setParentItem(0);
                  //  qDebug()<<(list.at(i)->type());
                }
                //qDebug()<<"<-End group items";
                scene()->removeItem(itemAt(event->pos()));
            }


            event->setAccepted(true);// tell the base class we are handling this event


        }
    }if (line != 0 && myMode == InsertLine) {

            QList<QGraphicsItem *> startItems = scene()->items(line->line().p1());
            if (startItems.count() && startItems.first() == line)
                startItems.removeFirst();

            QList<QGraphicsItem *> endItems = scene()->items(line->line().p2());
            if (endItems.count() && endItems.first() == line)
                endItems.removeFirst();

            if (startItems.count() &&startItems.first()->type() == 8)
                startItems.first() = startItems.first()->parentItem();
            if (endItems.count() && endItems.first()->type() == 8)
                endItems.first() = endItems.first()->parentItem();


            scene()->removeItem(line); //remove temporary line
            delete line;
            //! [11] //! [12]



            if (startItems.count() > 0 && endItems.count() > 0 &&
                    startItems.first()->type() == NodeItem::Type &&
                    endItems.first()->type() == NodeItem::Type &&
                    startItems.first() != endItems.first()) {
                NodeItem *startItem =
                        qgraphicsitem_cast<NodeItem *>(startItems.first());
                NodeItem *endItem =
                        qgraphicsitem_cast<NodeItem *>(endItems.first());


                RemapArrow *arrow = new RemapArrow(startItem, endItem);
                if (arrow->getArrowData()==true){

                    startItem->addArrow(arrow);
                    endItem->addArrow(arrow);
                    arrow->setZValue(-20);
                    scene()->addItem(arrow);
                    arrow->updatePosition();
                }
            }
        }

    //! [12] //! [13]
    line = 0;

    QGraphicsView::mouseReleaseEvent(event);
}
Example #11
0
QList<HistoryItem> JsonEngine::getMessages(const TreeModelItem &item, const QDateTime &last_time)
{
	QList<HistoryItem> items;
	if(!m_show_recent_messages)
		return items;
	QDir dir = getAccountDir(item);
	QString identification = QString("%1.%2.%3").arg(item.m_protocol_name).arg(item.m_account_name).arg(item.m_item_name);
	QString filter = quote(m_history_hash.value(identification, item.m_item_name));
	filter += ".*.json";
	QStringList files = dir.entryList(QStringList() << filter, QDir::Readable | QDir::Files | QDir::NoDotAndDotDot,QDir::Name);
	if(files.isEmpty())
		return items;
	for(int i=files.size()-1; i>=0; i--)
	{
		QList<const uchar *> pointers;
		QFile file(dir.filePath(files[i]));
		if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
			continue;
		int len = file.size();
		QByteArray data;
		const uchar *fmap = file.map(0, file.size());
		if(!fmap)
		{
			data = file.readAll();
			fmap = (uchar *)data.constData();
		}
		const uchar *s = K8JSON::skipBlanks(fmap, &len);
		uchar qch = *s;
		if(!s || (qch != '[' && qch != '{'))
			continue;
		qch = (qch == '{' ? '}' : ']');
		s++;
		len--;
		bool first = true;
		while(s)
		{
			s = K8JSON::skipBlanks(s, &len);
			if(len < 2 || (s && *s == qch))
				break;
			if((!first && *s != ',') || (first && *s == ','))
				break;
			first = false;
			if(*s == ',')
			{
				s++;
				len--;
			}
			pointers.prepend(s);
			if(!(s = K8JSON::skipRec(s, &len)))
			{
				pointers.removeFirst();
				break;
			}
		}
		QVariant value;
		for(int i=0; i<pointers.size(); i++)
		{
			value.clear();
			s = pointers[i];
			len = file.size() + 1 - (s - fmap);
			K8JSON::parseRec(value, s, &len);
			QVariantMap message = value.toMap();
			HistoryItem item;
			item.m_time = QDateTime::fromString(message.value("datetime").toString(), Qt::ISODate);
			if(item.m_time >= last_time)
				continue;
			item.m_in = message.value("in", false).toBool();
			item.m_type = message.value("type", 1).toInt();
			item.m_message = message.value("text").toString();
			items.prepend(item);
			if(items.size() >= m_max_num)
				return items;
		}
	}
	return items;
}
Route * GeneticAlgorithm::calculateRoute(AdjacencyMatrix *adjacencyMatrix,  unsigned int startNode)
{
    emit started();
    QList<Route*> routeListToNextRound;
    QList<Route*> routeList;
    QList<Route*> routeListToDoOperations;
    Route * currentBestRoute= NULL;
    unsigned int populationSizeRatio = 8;
    unsigned int populationSize = adjacencyMatrix->getSize() * populationSizeRatio;
    unsigned int roundsWithoutBetterRoute = 0;
    //int numberOfRoutesToNextRound
    for(unsigned int i = 0; i < populationSize; i++)
    {
        Route * tempRoute = new Route(adjacencyMatrix->getSize(),adjacencyMatrix);
        tempRoute->makeRandomRoute(startNode);
        routeListToNextRound.append(tempRoute);
    }

    do
    {
        int routeListToNextRoundSize = routeListToNextRound.size();
        for(int j = 0; j < routeListToNextRoundSize; j++)
        {
            routeList.append(routeListToNextRound.at(0));
            routeListToNextRound.removeFirst();
        }

        if(costType == Route::WITH_TIME)qSort(routeList.begin(),routeList.end(),routeLessThanWithTime);
        if(costType == Route::WITHOUT_TIME)qSort(routeList.begin(),routeList.end(),routeLessThanWithoutTime);

        if (currentBestRoute == NULL)
        {
            //currentBestRoute = new Route(*routeList.at(0));
            Route * tempRoute = new Route(routeList.at(0));

            //*tempRoute = *routeList.at(0);
            currentBestRoute = tempRoute;
        }
        else
        {
            if(routeList.at(0)->getCost(costType) < currentBestRoute->getCost(costType))
            {
                delete(currentBestRoute);
                Route * tempRoute = new Route(routeList.at(0));
                //Route * tempRoute = new Route(routeList.at(0)->getSize(),routeList.at(0)->getAdjacencyMatrix());
                //*tempRoute = *routeList.at(0);
                //currentBestRoute = new Route(*routeList.at(0));
                currentBestRoute = tempRoute;
                roundsWithoutBetterRoute = 0;
            }
            else
            {
                roundsWithoutBetterRoute++;
            }
        }

        int routeListSize = routeList.size();
        for(int k = 0; k < routeListSize/10 ; k++)
        {
              routeListToDoOperations.append(routeList.at(0));
              routeList.removeFirst();
        }

        qDeleteAll(routeList);
        routeList.clear();

        for(int l = 0; l < 10; l++)
        {
            routeListToNextRound.append(crossbreedRoutes(routeListToDoOperations.at(0),routeListToDoOperations.at(1)));
        }

        for(int l = 0; l < populationSize/2; l++)
        {
            routeListToNextRound.append(crossbreedRoutes(routeListToDoOperations.at(qrand() % routeListToDoOperations.size()),routeListToDoOperations.at(qrand() % routeListToDoOperations.size())));
        }
        for(int m = 0; m < populationSize/2; m++)
        {
            routeListToNextRound.append(makeMutation(routeListToNextRound.at(qrand() % routeListToNextRound.size())));
        }
        routeListToNextRound.append(new Route(currentBestRoute));
        qDeleteAll(routeListToDoOperations);
        routeListToDoOperations.clear();
    }
    while(roundsWithoutBetterRoute < 12);

    qDeleteAll(routeListToNextRound);
    routeListToNextRound.clear();
    //qDeleteAll(routeListToDoOperations);
    //routeListToDoOperations.clear();
    emit finished();
    return currentBestRoute;

}