Пример #1
0
// Triangulate a polygon
void glc::triangulate(QList<GLC_Point2d>& polygon, QList<int>& index, QList<int>& tList)
{
	const int size= polygon.size();
	if (size == 3)
	{
		tList << index[0] << index[1] << index[2];
		return;
	}
	int i0= 0;
	int i1= 1;
	int i2= 2;
	while(i0 < size)
	{
		if (isDiagonal(polygon, i0, i2))
		{
			// Add the triangle before removing the ear.
			tList << index[i0] << index[i1] << index[i2];
			// Remove the ear from polygon and index lists
			polygon.removeAt(i1);
			index.removeAt(i1);
			// recurse to the new polygon
			triangulate(polygon, index, tList);
			return;
		}
		++i0;
		i1= (i1 + 1) % size;
		i2= (i2 + 1) % size;
	}
}
Пример #2
0
void TestPAPageDeleteCommand::redoUndo()
{
    MockDocument doc;

    KoPAMasterPage * master1 = new KoPAMasterPage();
    doc.insertPage( master1, 0 );

    KoPAPage * page1 = new KoPAPage( master1 );
    doc.insertPage( page1, 0 );

    KoPAPage * p1 = dynamic_cast<KoPAPage *>( doc.pageByIndex( 0, false ) );
    KoPAMasterPage * m1 = dynamic_cast<KoPAMasterPage *>( doc.pageByIndex( 0, true ) );

    QVERIFY( p1 != 0 );
    QVERIFY( m1 != 0 );

    KoPAPage * p2 = new KoPAPage( m1 );
    KoPAPage * p3 = new KoPAPage( m1 );
    doc.insertPage( p2, 1 );
    doc.insertPage( p3, 2 );

    KoPAPageDeleteCommand cmd( &doc, p1 );
    KoPAPageDeleteCommand cmd2( &doc, p3 );

    QList<KoPAPage *> pages;
    pages.append( p1 );
    pages.append( p2 );
    pages.append( p3 );

    QList<KoPAPage *> allPages = pages;

    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    cmd.redo();

    pages.removeAt( 0 );
    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    cmd2.redo();

    pages.removeAt( 1 );
    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    cmd2.undo();
    cmd.undo();

    for( int i = 0; i < allPages.size(); ++i ) {
        QVERIFY( allPages[i] == doc.pageByIndex( i, false ) );
    }
}
Пример #3
0
QPoint Ghost::getNewDirection(void) {
    QList<QPoint> directions;
    directions.append(QPoint( 1,  0));
    directions.append(QPoint(-1,  0));
    directions.append(QPoint( 0,  1));
    directions.append(QPoint( 0, -1));

    QPoint reverse = -_direction;

    int i = 0;
    while(i < directions.size()) {
        QPointF testDirection = _position;
        testDirection += directions.at(i);
        if(directions.at(i) == reverse) {
            directions.removeAt(i);
        }
        else if(canAccess(testDirection.x(), testDirection.y())) {
            ++i;
        } else {
            directions.removeAt(i);
        }
    }
    if(!directions.size()) {
        return reverse;
    }
    return directions.at(qrand() % directions.size());
}
Пример #4
0
Tile TileCache::findBestTileLocked(QList<Tile>& tiles, bool& tileDone) {
    // find a tile that is visible and already in the cache:
    int size = tiles.size();

    for (int x = 0; x < size; x++) {
        Tile tile = tiles[x];
        if (tile.visible && populateTileFromCacheLocked(tile)) {
            tileDone = true;
            tiles.removeAt(x);
            return tile;
        }
    }

    // Nothing. Get a visible tile:
    for (int x = 0; x < size; x++) {
        Tile tile = tiles[x];
        if (tile.visible) {
            tileDone = populateTileFromCacheLocked(tile);
            tiles.removeAt(x);
            return tile;
        }
    }

    // Just return any tile:
    // TODO: We need a way to generate tiles near the center first.
    Tile tile = tiles.takeFirst();
    tileDone = populateTileFromCacheLocked(tile);

    return tile;
}
Пример #5
0
void qSslChat :: hostConnection()
{
  if(nameEdit ->text().isEmpty())
   {
      QMessageBox::critical(0,tr("Error"),tr("Choose a name."),QMessageBox::Ok);
      return;
   }

  connectButton -> setDisabled(true);
  hostButton -> setDisabled(true);
  server = new Server(portBox -> value(),false);

  QList<QHostAddress> ipList;
  ipList = QNetworkInterface :: allAddresses();
  int counter = 0;
  QString localIp("127.0.0.1");
  foreach(QHostAddress ip,ipList)
   {
    QString ipString = ip.toString();
    if(ipString.contains(":")) ipList.removeAt(counter);
     else
      if(ipString=="127.0.0.1") ipList.removeAt(counter);
       else
        if(ipString.contains("192.")&&!ipString.contains(".192"))
         {
           localIp = ipString;
           ipList.removeAt(counter);
         }
         else counter++;
   }
Пример #6
0
/** Edits selected item */
void medDatabaseView::onEditRequested(void)
{
    QModelIndexList indexes = this->selectedIndexes();
    if(!indexes.count())
        return;

    QModelIndex index = indexes.at(0);

    medAbstractDatabaseItem *item = NULL;

    if(QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(this->model()))
        item = static_cast<medAbstractDatabaseItem *>(proxy->mapToSource(index).internalPointer());

    if(item)
    {        
        QList<QVariant> attributes = item->attributes();
        QList<QVariant> values = item->values();
        QList<QString> labels;

        // Users are not allowed to change ThumbnailPath attribute.
        for (int i = 0; i<attributes.count(); i++)
        {
            if (attributes.at(i).toString() == "ThumbnailPath")
            {
                attributes.removeAt(i);
                values.removeAt(i);
            }
        }

        foreach(QVariant attrib, attributes)
        {
            const medMetaDataKeys::Key* key =  medMetaDataKeys::Key::fromKeyName(attrib.toString().toStdString().c_str());

            if(key)
            {
                labels << key->label();
            }
            else
            {
                labels << "";
            }
        }
        
        medDatabaseEditItemDialog editDialog(labels,values,this);
        
        int res =  editDialog.exec();
        medDataIndex index = item->dataIndex();

        if(res == QDialog::Accepted)
        {
            int i=0;
            foreach(QString label, labels)
            {
                QVariant data = editDialog.value(label);
                QVariant variant = item->attribute(i);
                medDataManager::instance()->setMetadata(index, variant.toString(), data.toString());
                i++;    
            }
        } 
void QSimpleResource::addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
                                                       QList<DomCustomWidget*>& custom_widget_list)
{
    QDesignerWidgetDataBaseInterface *db = core->widgetDataBase();
    for (int i=0; i < custom_widget_list.size(); ) {
        bool classInserted = false;
        DomCustomWidget *custom_widget = custom_widget_list[i];
        const QString customClassName = custom_widget->elementClass();
        const QString base_class = custom_widget->elementExtends();
        QString includeFile;
        IncludeType includeType = IncludeLocal;
        if (const DomHeader *header = custom_widget->elementHeader()) {
            includeFile = header->text();
            if (header->hasAttributeLocation() && header->attributeLocation() == QStringLiteral("global"))
                includeType = IncludeGlobal;
        }
        const bool domIsContainer = custom_widget->elementContainer();
        // Append a new item
        if (base_class.isEmpty()) {
            WidgetDataBaseItem *item = new WidgetDataBaseItem(customClassName);
            item->setPromoted(false);
            item->setGroup(QCoreApplication::translate("Designer", "Custom Widgets"));
            item->setIncludeFile(buildIncludeFile(includeFile, includeType));
            item->setContainer(domIsContainer);
            item->setCustom(true);
            addFakeMethodsToWidgetDataBase(custom_widget, item);
            db->append(item);
            custom_widget_list.removeAt(i);
            classInserted = true;
        } else {
            // Create a new entry cloned from base class. Note that this will ignore existing
            // classes, eg, plugin custom widgets.
            QDesignerWidgetDataBaseItemInterface *item =
                appendDerived(db, customClassName, QCoreApplication::translate("Designer", "Promoted Widgets"),
                              base_class,
                              buildIncludeFile(includeFile, includeType),
                              true,true);
            // Ok, base class found.
            if (item) {
                // Hack to accommodate for old UI-files in which "container" is not set properly:
                // Apply "container" from DOM only if true (else, eg classes from QFrame might not accept
                // dropping child widgets on them as container=false). This also allows for
                // QWidget-derived stacked pages.
                if (domIsContainer)
                    item->setContainer(domIsContainer);

                addFakeMethodsToWidgetDataBase(custom_widget, static_cast<WidgetDataBaseItem*>(item));
                custom_widget_list.removeAt(i);
                classInserted = true;
            }
        }
        // Skip failed item.
        if (!classInserted)
            i++;
    }

}
Пример #8
0
//returns 1 if this is a new cursor; 0 otherwise
int moveRemoteCursor(char *msg) {
    char *ip = (char*)malloc(sizeof(char)*20);
    char *tempstring = (char*)malloc(sizeof(char)*20);
    char *posstring = (char*)malloc(sizeof(char)*10);
    char *anchorstring = (char*)malloc(sizeof(char)*10);
    int size=strlen(msg);
    int pos;
    int anchor;
    int ipsize = strchr(msg,'|') - msg;
    strncpy(ip,msg,ipsize);
    ip[ipsize]='\0';
    strcpy(tempstring,msg+ipsize+1);
    int possize = strchr(tempstring,'|') - tempstring;
    strncpy(posstring,tempstring,possize);
    posstring[possize]='\0';
    strcpy(anchorstring,tempstring+possize+1);
    anchorstring[size-possize-ipsize-2]='\0';
    pos=atoi(posstring);
    anchor=atoi(anchorstring);

    int found=0;
    int i;

    for(i=0;i<cursorIPs.size();i++) {
        if(cursorIPs.at(i)==QString(ip)) {
            found=1;
            if(pos==-1){
                cursorIPs.removeAt(i);
                cursorHighlights.removeAt(i);
            } else {
                cursorHighlights[i].cursor.setPosition(pos,QTextCursor::MoveAnchor);
                if(pos==anchor){
                    cursorHighlights[i].cursor.setPosition(pos+1,QTextCursor::KeepAnchor);
                } else {
                    cursorHighlights[i].cursor.setPosition(anchor,QTextCursor::KeepAnchor);
                }
            }
        }
    }

    if(!found) {
        //add a new client
        QTextEdit::ExtraSelection highlight;
        highlight.cursor = editor->textCursor();
        highlight.cursor.setPosition(pos,QTextCursor::MoveAnchor);
        highlight.cursor.setPosition(pos+1,QTextCursor::KeepAnchor);
        highlight.format = editor->currentCharFormat();
        highlight.format.setBackground(pickColor(ip));
        cursorIPs.append(ip);
        cursorHighlights.append(highlight);
    }

    editor->setExtraSelections(cursorHighlights);

    return(!found);
}
Пример #9
0
void TestPAPageDeleteCommand::redoUndoMaster()
{
    MockDocument doc;
    KoPAMasterPage * master1 = new KoPAMasterPage();
    doc.insertPage( master1, 0 );

    KoPAMasterPage * m1 = dynamic_cast<KoPAMasterPage *>( doc.pageByIndex( 0, true ) );

    QVERIFY( m1 != 0 );

    KoPAMasterPage * m2 = new KoPAMasterPage();
    KoPAMasterPage * m3 = new KoPAMasterPage();
    doc.insertPage( m2, 1 );
    doc.insertPage( m3, 2 );

    KoPAPageDeleteCommand cmd( &doc, m1 );
    KoPAPageDeleteCommand cmd2( &doc, m3 );


    QList<KoPAMasterPage *> masterPages;
    masterPages.append( m1 );
    masterPages.append( m2 );
    masterPages.append( m3 );

    QList<KoPAMasterPage *> allMasterPages = masterPages;

    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    cmd.redo();

    masterPages.removeAt( 0 );
    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    cmd2.redo();

    masterPages.removeAt( 1 );
    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    cmd2.undo();
    cmd.undo();

    for( int i = 0; i < allMasterPages.size(); ++i ) {
        QVERIFY( allMasterPages[i] == doc.pageByIndex( i, true ) );
    }
}
Пример #10
0
	QModelIndex cast( NifModel * nif, const QModelIndex & index )
	{
		QModelIndex iData = getTriShapeData( nif, index );
		
		QList<Triangle> tris = nif->getArray<Triangle>( iData, "Triangles" ).toList();
		int cnt = 0;
		
		int i = 0;
		while ( i < tris.count() )
		{
			const Triangle & t = tris[i];
			if ( t[0] == t[1] || t[1] == t[2] || t[2] == t[0] )
			{
				tris.removeAt( i );
				cnt++;
			}
			else
				i++;
		}
		
		i = 0;
		while ( i < tris.count() )
		{
			const Triangle & t = tris[i];
			
			int j = i + 1;
			while ( j < tris.count() )
			{
				const Triangle & r = tris[j];
				
				if ( ( t[0] == r[0] && t[1] == r[1] && t[2] == r[2] )
					|| ( t[0] == r[1] && t[1] == r[2] && t[2] == r[0] )
					|| ( t[0] == r[2] && t[1] == r[0] && t[2] == r[1] ) )
				{
					tris.removeAt( j );
					cnt++;
				}
				else
					j++;
			}
			i++;
		}
		
		if ( cnt > 0 )
		{
			qWarning() << QString( Spell::tr("%1 triangles removed") ).arg( cnt );
			nif->set<int>( iData, "Num Triangles", tris.count() );
			nif->set<int>( iData, "Num Triangle Points", tris.count() * 3 );
			nif->updateArray( iData, "Triangles" );
			nif->setArray<Triangle>( iData, "Triangles", tris.toVector() );
		}
		return index;
	}
Пример #11
0
void ObjectListener::menuClicked(QAction *action)
{
    int index=-1;
    if(action==wnd->actionQuit)
    {
        wnd->close();
    }else if(action==wnd->actionNew)
    {
        openFile(true);
    }else if(action==wnd->actionClose)
    {
        index=wnd->tabs->currentIndex();
        if(index>-1)
        {
            wnd->tabs->removeTab(index);
            delete wnd->tables.at(index);
            wnd->tables.removeAt(index);
            lisSaveSelect.removeAt(index);
            lsavePath.removeAt(index);
            lisEditable.removeAt(index);
        }
    }else if(action==wnd->actionSave)
    {
        index=wnd->tabs->currentIndex();
        saveFile(false,index);

    }else if(action==wnd->actionSave_as)
    {
        index=wnd->tabs->currentIndex();
        saveFile(true,index);
    }else if(action==wnd->actionOpen)
    {
        openFile(false);
    }else if(action==wnd->actionAbout)
    {
        wnd->about->show();
    }else if(action==wnd->pActionEdit.data())
    {
        index=wnd->tabs->currentIndex();
        if(index>-1)
            tableDoubleClicked(wnd->tables[index]->currentIndex());
    }else if(action==wnd->pActionRemove.data())
    {
        index=wnd->tabs->currentIndex();
        if(index>-1)
            deleteItem(index);
    }
}
Пример #12
0
// scale data lists from one age to another
void Plant::scaleMaxAgeTo(int age)
{
    double scaleFactor = ((double)age)/((double)this->maxAge);
    Tupel3 newTupel;
    QList<Tupel3> *list;
    for (int i=0; i<dataList.size(); i++) {
        // get list from list of lists
        list = dataList.at(i);
        // rescale all ages in list
        // but remove all tupels that have duplicate age
        int previousAge = -1;
        for (int j=0; j<list->size(); j++) {
            // keep first entry untouched
            if (j==0) {
                previousAge = list->at(j).age;
                continue;
            }
            // get old tupel
            newTupel = list->at(j);
            // set last value to new max age
            if (j==list->size()-1) {
                newTupel.age = age;
                list->replace(j,newTupel);
                // check if previous is duplicate
                // but only if there are more than 2 entries
                if (list->size()>2) {
                    if (list->at(j-1).age==newTupel.age) {
                        list->removeAt(j-1);
                    }
                }
                continue;
            }
            // scale age
            newTupel.age = newTupel.age*scaleFactor;
            // remove old tupel if new age is already in list
            if (newTupel.age==previousAge) {
                list->removeAt(j);
                // remember to decrease counter
                j--;
            } else {
                // replace old tupel with new one
                list->replace(j,newTupel);
            }
        }
    }
    this->maxAge = age;
    this->growthAge = growthAge*scaleFactor;
}
Пример #13
0
bool AutoDJFeature::dropAccept(QList<QUrl> urls, QObject* pSource) {
    TrackDAO &trackDao = m_pTrackCollection->getTrackDAO();

    // If a track is dropped onto a playlist's name, but the track isn't in the
    // library, then add the track to the library before adding it to the
    // playlist.
    QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true);
    QList<TrackId> trackIds;
    if (pSource) {
        trackIds = trackDao.getTrackIds(files);
        trackDao.unhideTracks(trackIds);
    } else {
        trackIds = trackDao.addMultipleTracks(files, true);
    }

    // remove tracks that could not be added
    for (int trackIdIndex = 0; trackIdIndex < trackIds.size(); trackIdIndex++) {
        if (!trackIds.at(trackIdIndex).isValid()) {
            trackIds.removeAt(trackIdIndex--);
        }
    }

    // Return whether the tracks were appended.
    return m_playlistDao.appendTracksToPlaylist(trackIds, m_iAutoDJPlaylistId);
}
Пример #14
0
bool ConsolePlan::removeSpot(float angle, Plane2DCoordinate coordinate)
{
    QString str;
    if (m_planeSpots.contains(angle))
    {
        QList<Plane2DCoordinate> coordinates = m_planeSpots.value(angle);
        int i = containSpot(coordinates,coordinate);
        if (i >= 0)
        {
            coordinates.removeAt(i);
            if (coordinates.size() == 0)
            {
                m_planeSpots.remove(angle);
            }else
            {
                m_planeSpots.insert(angle,coordinates);
            }

            str = printLastAction(RemoveSpot) + printLastError(NoError);
            qCDebug(PlanGenerator()) << PlanGenerator().categoryName() << str;
            return true;
        }else
        {
            str = printLastAction(RemoveSpot) + printLastError(ErrorPlaneNoSuchSpot);
            qCDebug(PlanGenerator()) << PlanGenerator().categoryName() << str;
            return false;
        }
    }else
    {
        str = printLastAction(RemoveSpot) + printLastError(ErrorNoSuchPlane);
        qCWarning(PlanGenerator()) << PlanGenerator().categoryName() << str;
        emit error(ErrorNoSuchPlane);
        return false;
    }
}
Пример #15
0
// ===== findOrphanTrayWindows() =====
QList<WId> LX11::findOrphanTrayWindows(){
  //Scan the first level of root windows and see if any of them
    // are tray apps waiting to be embedded
  Display *disp = QX11Info::display();
  QList<WId> wins = LX11::findChildren(QX11Info::appRootWindow(), 0); //only go one level deep
  Atom embinfo = XInternAtom(disp, "_XEMBED_INFO",false);	
  for(int i=0; i<wins.length(); i++){
    uchar *data=0;
    ulong num, bytes;
    int fmt;
    Atom junk;
    bool ok = (Success != XGetWindowProperty(disp, wins[i], embinfo, 0, 2, false, embinfo, &junk, &fmt, &num, &bytes, &data) );
    if(ok){ //successfully found info
      ok = (data!=0);
    }
    
    if(!ok){
      //no embed info - not a tray app
      qDebug() << "Remove non-xembed window:" << wins[i];
      wins.removeAt(i);
      i--;
    }
    if(data){ XFree(data); } // clean up any data found
  }
  return wins; //anything left in the list must be a tray app that is still unembedded (root window parent)
}
Пример #16
0
//=====   WindowList() ========
QList<WId> LX11::WindowList(){
  QList<WId> output;
  output << LX11::GetClientList();

  
  //Validate windows
  int desk = LX11::GetCurrentDesktop();
  for(int i=0; i<output.length(); i++){
    bool remove=false;
    QString name = LX11::WindowClass(output[i]);
    if(output[i] == 0){ remove=true; }
    else if( desk >= 0 && LX11::WindowDesktop(output[i]) != desk){ remove = true; }
    else if( name=="Lumina-DE" ){ remove = true; }
    else if(name.startsWith("Lumina-")){
      //qDebug() << "Lumina Window:" << name << LX11::WindowName(output[i]);
      if(LX11::WindowName(output[i]).toLower()==name.toLower() ){ remove=true; }
    }
    /*else if( name.isEmpty() ){ 
      qDebug() << "Abnormal Window:" << output[i];
	qDebug() << " - Class:" << name;
	qDebug() << " - Text:" << LX11::WindowName(output[i]);
	qDebug() << " - Visible Name:" << LX11::WindowVisibleName(output[i]);
	qDebug() << " - Icon Name:" << LX11::WindowIconName(output[i]);
    }*/
    if(remove){
      //qDebug() << "Skip Window:" << output[i];
      output.removeAt(i);
      i--;
    }
  }
  //qDebug() << output;
  //Return the list
  return output;
}
Пример #17
0
bool PlaylistFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> urls,
                                      QObject* pSource) {
    int playlistId = playlistIdFromIndex(index);
    //m_playlistDao.appendTrackToPlaylist(url.toLocalFile(), playlistId);

    QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true);

    QList<TrackId> trackIds;
    if (pSource) {
        trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files);
        m_pTrackCollection->getTrackDAO().unhideTracks(trackIds);
    } else {
        // If a track is dropped onto a playlist's name, but the track isn't in the
        // library, then add the track to the library before adding it to the
        // playlist.
        // Adds track, does not insert duplicates, handles unremoving logic.
        trackIds = m_pTrackCollection->getTrackDAO().addTracks(files, true);
    }

    // remove tracks that could not be added
    for (int trackIdIndex = 0; trackIdIndex < trackIds.size(); ++trackIdIndex) {
        if (!trackIds.at(trackIdIndex).isValid()) {
            trackIds.removeAt(trackIdIndex--);
        }
    }

    // Return whether appendTracksToPlaylist succeeded.
    return m_playlistDao.appendTracksToPlaylist(trackIds, playlistId);
}
Пример #18
0
void ActionsProxyModel::updateVisibleActions(QList<QAction *> &visibleActions, const QList<ActionWithVisibility> &actions, int globalPosition)
{
    int i = 0, sourceModelRowCount = sourceModel() ? sourceModel()->rowCount() : 0;

    foreach (const ActionWithVisibility &action, actions)
    {
        // whether the action should be visible
        if (!(sourceModelRowCount == 0 && action.Visibility & NotVisibleWithEmptySourceModel) &&
                !(sourceModelRowCount == 1 && action.Visibility & NotVisibleWithOneRowSourceModel))
        {
            // if it should, but it isn't yet
            if (!visibleActions.contains(action.Action))
            {
                beginInsertRows(QModelIndex(), globalPosition, globalPosition);
                visibleActions.insert(i, action.Action);
                endInsertRows();
            }
            i++;
            globalPosition++;
        }
        // if it shouldn't, but now is visible
        else if (visibleActions.contains(action.Action))
        {
            beginRemoveRows(QModelIndex(), globalPosition, globalPosition);
            visibleActions.removeAt(i);
            endRemoveRows();
        }
    }
}
Пример #19
0
void CommandsModel::reInsertCommand(ShellCommand *toUpdate)
{
    if(toUpdate != NULL)
    {
        int index = m_commands.indexOf(toUpdate);

        QList<ShellCommand*> temp = m_commands;

        temp.removeAt(index);

        QList<ShellCommand*>::iterator i = getInsertPosition(m_sort_type, toUpdate, temp);

        int hypotheticPosition = (i - temp.begin());

        //  qDebug() << index << " != " << hypotheticPosition << " = " << (index != hypotheticPosition);

        if(index != (hypotheticPosition))
        {
            beginResetModel();
            if(index >= 0 && index < m_commands.count())
            {
                m_commands.removeAt(index);

                this->insertOnReset(toUpdate);
            }
            endResetModel();
        }
    }
}
Пример #20
0
void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval)
{
    // Handle normalized intervals only
    if(!interval.isNormal())
        return;

    for (int i = 0; i < intervals.count(); i++) {
        QMediaTimeInterval r = intervals[i];

        if (r.e < interval.s) {
            // Before the removal interval
            continue;
        } else if (interval.e < r.s) {
            // After the removal interval - stop here
            break;
        } else if (r.s < interval.s && interval.e < r.e) {
            // Split case - a single range has a chunk removed
            intervals[i].e = interval.s -1;
            addInterval(QMediaTimeInterval(interval.e + 1, r.e));
            break;
        } else if (r.s < interval.s) {
            // Trimming Tail Case
            intervals[i].e = interval.s - 1;
        } else if (interval.e < r.e) {
            // Trimming Head Case - we can stop after this
            intervals[i].s = interval.e + 1;
            break;
        } else {
            // Complete coverage case
            intervals.removeAt(i);
            --i;
        }
    }
}
Пример #21
0
void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval)
{
    // Handle normalized intervals only
    if(!interval.isNormal())
        return;

    // Find a place to insert the interval
    int i;
    for (i = 0; i < intervals.count(); i++) {
        // Insert before this element
        if(interval.s < intervals[i].s) {
            intervals.insert(i, interval);
            break;
        }
    }

    // Interval needs to be added to the end of the list
    if (i == intervals.count())
        intervals.append(interval);

    // Do we need to correct the element before us?
    if(i > 0 && intervals[i - 1].e >= interval.s - 1)
        i--;

    // Merge trailing ranges
    while (i < intervals.count() - 1
          && intervals[i].e >= intervals[i + 1].s - 1) {
        intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e);
        intervals.removeAt(i + 1);
    }
}
Пример #22
0
void MyBaseListWidget::chargeListImageInsequence(Sequence sq, bool sorted, int nb_image_charge){

    this->clear();
    QList<ImageInSequence> listImg = sq.listImageInSequence;

       if(sorted){
           qSort(listImg.begin(), listImg.end(), ImageInSequence::lessThan);
        }else{
            QList<ImageInSequence> randlistImg;
           while(listImg.count() > 0){
                int nb = listImg.count();
               int rand = Util::random(0,nb);

                randlistImg << listImg.value(rand);
                listImg.removeAt(rand);
            }
            listImg = randlistImg;
        }
    int i = 0;
    while(i < listImg.count() && i < nb_image_charge){
        ImageInSequence imgSeq = listImg.at(i);
        this->addImage(imgSeq.img.name,Util::getIcon(imgSeq.img.image_file, sq.name));
        ++i;
    }
}
Пример #23
0
void tst_QList::at() const
{
    // test at() and make sure it functions correctly with some simple list manipulation.
    QList<QString> list;

    // create a list
    list << "foo" << "bar" << "baz";
    QVERIFY(list.size() == 3);
    QCOMPARE(list.at(0), QLatin1String("foo"));
    QCOMPARE(list.at(1), QLatin1String("bar"));
    QCOMPARE(list.at(2), QLatin1String("baz"));

    // append an item
    list << "hello";
    QVERIFY(list.size() == 4);
    QCOMPARE(list.at(0), QLatin1String("foo"));
    QCOMPARE(list.at(1), QLatin1String("bar"));
    QCOMPARE(list.at(2), QLatin1String("baz"));
    QCOMPARE(list.at(3), QLatin1String("hello"));

    // remove an item
    list.removeAt(1);
    QVERIFY(list.size() == 3);
    QCOMPARE(list.at(0), QLatin1String("foo"));
    QCOMPARE(list.at(1), QLatin1String("baz"));
    QCOMPARE(list.at(2), QLatin1String("hello"));
}
Пример #24
0
void TransferModel::setFileProgression(
        #ifndef ULTRACOPIER_PLUGIN_DEBUG
        const
        #endif
        QList<Ultracopier::ProgressionItem> &progressionList)
{
    loop_size=progressionList.size();
    index_for_loop=0;
    while(index_for_loop<loop_size)
    {
        if(internalRunningOperation.contains(progressionList.at(index_for_loop).id))
        {
            internalRunningOperation[progressionList.at(index_for_loop).id].generalData.size=progressionList.at(index_for_loop).total;
            internalRunningOperation[progressionList.at(index_for_loop).id].currentReadProgression=progressionList.at(index_for_loop).currentRead;
            internalRunningOperation[progressionList.at(index_for_loop).id].currentWriteProgression=progressionList.at(index_for_loop).currentWrite;
            #ifdef ULTRACOPIER_PLUGIN_DEBUG
            progressionList.removeAt(index_for_loop);
            index_for_loop--;
            loop_size--;
            #endif
        }
        index_for_loop++;
    }
    #ifdef ULTRACOPIER_PLUGIN_DEBUG
    if(progressionList.size()>0)
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"progression remaning items");
    #endif
}
//==============
//    PRIVATE SLOTS
//==============
void LTaskManagerPlugin::UpdateButtons(){
  if(updating){ timer->start(); return; } //check again in a moment
  //Make sure this only runs one at a time
  updating=true;
  //Get the current window list
  QList<WId> winlist = LX11::WindowList();
  //qDebug() << "Update Buttons:" << winlist;
  //Now go through all the current buttons first
  for(int i=0; i<BUTTONS.length(); i++){
    //Get the windows managed in this button
    QList<LWinInfo> WI = BUTTONS[i]->windows();
    bool updated=false;
    for(int w=0; w<WI.length(); w++){
      if( winlist.contains( WI[w].windowID() ) ){
        //Still current window - update it later
	winlist.removeAll(WI[w].windowID()); //remove this window from the list since it is done
      }else{
	//Window was closed - remove it
	if(WI.length()==1){
	  //Remove the entire button
	  this->layout()->takeAt(i); //remove from the layout
	  delete BUTTONS.takeAt(i);
	  i--;
	  updated = true; //prevent updating a removed button
	  break; //break out of the button->window loop
	}else{
	  BUTTONS[i]->rmWindow(WI[w]); // one of the multiple windows for the button
	  WI.removeAt(w); //remove this window from the list
	  w--;
	}
	updated=true; //button already changed
      }
    }
    if(!updated){
      QTimer::singleShot(1,BUTTONS[i], SLOT(UpdateButton()) ); //keep moving on
    }
  }
  //Now go through the remaining windows
  for(int i=0; i<winlist.length(); i++){
    //New windows, create buttons for each (add grouping later)
    //Check for a button that this can just be added to
    QString ctxt = LX11::WindowClass(winlist[i]);
    bool found = false;
    for(int b=0; b<BUTTONS.length(); b++){
      if(BUTTONS[b]->text().section("(",0,0).simplified() == ctxt){
        found = true;
	BUTTONS[b]->addWindow(winlist[i]);
	break;
      }
    }
    if(!found){
      //No group, create a new button
      LTaskButton *but = new LTaskButton(this);
        but->addWindow( LWinInfo(winlist[i]) );
      this->layout()->addWidget(but);
      BUTTONS << but;
    }
  }
  updating=false;
}
Пример #26
0
bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> urls,
                                   QObject* pSource) {
    int crateId = crateIdFromIndex(index);
    if (crateId == -1) {
        return false;
    }
    QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true);
    QList<int> trackIds;
    if (pSource) {
        trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files);
        m_pTrackCollection->getTrackDAO().unhideTracks(trackIds);
    } else {
        // Adds track, does not insert duplicates, handles unremoving logic.
        trackIds = m_pTrackCollection->getTrackDAO().addTracks(files, true);
    }
    qDebug() << "CrateFeature::dropAcceptChild adding tracks"
            << trackIds.size() << " to crate "<< crateId;
    // remove tracks that could not be added
    for (int trackId = 0; trackId < trackIds.size(); ++trackId) {
        if (trackIds.at(trackId) < 0) {
            trackIds.removeAt(trackId--);
        }
    }
    m_crateDao.addTracksToCrate(crateId, &trackIds);
    return true;
}
Пример #27
0
QStringList SessionManagerPrivate::dependenciesOrder() const
{
    QList<QPair<QString, QStringList> > unordered;
    QStringList ordered;

    // copy the map to a temporary list
    foreach (Project *pro, m_projects) {
        const QString &proName = pro->projectFilePath();
        unordered << QPair<QString, QStringList>(proName, m_depMap.value(proName));
    }

    while (!unordered.isEmpty()) {
        for (int i=(unordered.count()-1); i>=0; --i) {
            if (unordered.at(i).second.isEmpty()) {
                ordered << unordered.at(i).first;
                unordered.removeAt(i);
            }
        }

        // remove the handled projects from the dependency lists
        // of the remaining unordered projects
        for (int i = 0; i < unordered.count(); ++i) {
            foreach (const QString &pro, ordered) {
                QStringList depList = unordered.at(i).second;
                depList.removeAll(pro);
                unordered[i].second = depList;
            }
        }
    }
/**
 * Move a entity list in this container at the given position,
 * the borders of this entity-container if autoUpdateBorders is true.
 */
void RS_EntityContainer::moveEntity(int index, QList<RS_Entity *>& entList){
    if (entList.isEmpty()) return;
    int ci = 0; //current index for insert without invert order
    bool ret, into = false;
	RS_Entity *mid = nullptr;
    if (index < 1) {
        ci = 0;
    } else if (index >= entities.size() ) {
        ci = entities.size() - entList.size();
    } else {
        into = true;
        mid = entities.at(index);
    }

    for (int i = 0; i < entList.size(); ++i) {
        RS_Entity *e = entList.at(i);
        ret = entities.removeOne(e);
        //if e not exist in entities list remove from entList
        if (!ret) {
            entList.removeAt(i);
        }
    }
    if (into) {
        ci = entities.indexOf(mid);
    }

	for(auto e: entList){
            entities.insert(ci++, e);
    }
}
Пример #29
0
void QGeoCodeReplyNokia::networkFinished()
{
    if (!m_reply)
        return;

    if (m_reply->error() != QNetworkReply::NoError) {
        // Removed because this is already done in networkError, which previously caused _two_ errors to be raised for every error.
        //setError(QGeoCodeReply::CommunicationError, m_reply->errorString());
        //m_reply->deleteLater();
        //m_reply = 0;
        return;
    }

    QGeoCodeXmlParser parser;
    if (parser.parse(m_reply)) {
        QList<QGeoLocation> locations = parser.results();
        QGeoShape bounds = viewport();
        if (bounds.isValid()) {
            for (int i = locations.size() - 1; i >= 0; --i) {
                if (!bounds.contains(locations[i].coordinate()))
                    locations.removeAt(i);
            }
        }
        setLocations(locations);
        setFinished(true);
    } else {
        setError(QGeoCodeReply::ParseError, parser.errorString());
    }

    m_reply->deleteLater();
    m_reply = 0;
}
bool SceneModel::removeRows(int row, int count, const QModelIndex &parent)
{
    int start = row;
    int end = row + (count-1);

    if (parent.isValid()){
        qWarning() << "remove scene - valid parent";
        return false;
    }

    if (row > rowCount()-1 || row < 0){
        qWarning() << "Could not delete from row" << row;
        return false;
    }

    if (end > rowCount()-1)
        end = rowCount()-1;
    beginRemoveRows(parent, row, end);

    QList<Scene *> scenes = mNovel->scenes();
    for (int i = start; i <= end; ++i)
        scenes.removeAt(start);
    mNovel->setScenes(scenes);

    endRemoveRows();
    return true;
}