int eListBoxBase::setCurrent(const eListBoxEntry *c, bool sendSelected ) { /* if (childs.empty() || ((current != childs.end()) && (*current == c))) // no entries or current is equal the entry to search return E_ALLREADY_SELECTED; // do nothing*/ if ( !entries ) return E_COULDNT_FIND; ePtrList<eListBoxEntry>::iterator item(childs.begin()), it(childs.begin()); int cnt=0; for ( ; item != childs.end(); ++item, ++cnt) if ( *item == c ) break; if ( item == childs.end() ) // entry not in listbox... do nothing return E_COULDNT_FIND; currentPos=cnt; int newCurPos=-1; int oldCurPos=-1; ePtrList<eListBoxEntry>::iterator oldCur(current); int i = 0; for (it=top; it != bottom; ++it, ++i) // check if entry to set between bottom and top { if (it == item) { newCurPos=i; current = it; } if ( it == oldCur) oldCurPos=i; } if (newCurPos != -1) // found on current screen, so redraw only old and new { if (isVisible()) { if (in_atomic) { if (atomic_redraw == arNothing) { atomic_redraw = arCurrentOld; atomic_old = oldCurPos; } if (atomic_redraw == arCurrentOld) atomic_new = newCurPos; }else { invalidateEntry(newCurPos); if (oldCurPos != -1) invalidateEntry(oldCurPos); } } } else // then we start to search from begin { bottom = childs.begin(); while (newCurPos == -1 && MaxEntries) // MaxEntries is already checked above... { if ( bottom != childs.end() ) top = bottom; // n鋍hster Durchlauf for (i = 0; (i < (MaxEntries*columns) ) && (bottom != childs.end()); ++bottom, ++i) { if (bottom == item) { current = bottom; // we have found ++newCurPos; } } } if (isVisible()) { if (!in_atomic) invalidateContent(); // Draw all else atomic_redraw=arAll; } } if (!in_atomic) { /*emit*/ SendSelChanged(*current); if ( sendSelected ) /*emit*/ SendSelected(*current); }else { atomic_selchanged=1; if ( sendSelected ) atomic_selected=1; } return OK; }
void LatexTables::removeColumn(QDocument *doc,const int lineNumber,const int column,QStringList *cutBuffer){ QDocumentCursor cur(doc); //preparations for search QStringList nTokens; nTokens << "\\\\" << "\\&" << "&"; cur.moveTo(lineNumber,0); QString def=getDef(cur); //int result=findNextToken(cur,QStringList(),false,true); // move to \begin{...} if(def.isEmpty()) { return; // begin not found } cur.beginEditBlock(); //remove col in definition QStringList defs=splitColDef(def); def.clear(); for(int i=0;i<defs.count();i++){ if(i==column){ if(cutBuffer) cutBuffer->append(defs[i]); }else{ def.append(defs[i]); } } if(def.isEmpty()){ cur.removeSelectedText(); }else{ cur.insertText(def); } cur.movePosition(2,QDocumentCursor::Right); // remove column QString line; bool breakLoop=false; while(!breakLoop){ int result=2; int off=0; for(int col=0;col<column;col++){ if(off>0) off--; cur.clearSelection(); QDocumentCursor oldCur(cur); do{ result=findNextToken(cur,nTokens,true); }while(result==1); QString selText=cur.selectedText(); if(selText.startsWith("\\multicolumn")){ int add=getNumOfColsInMultiColumn(selText); if(off==0) off=add; if(off>1) cur=oldCur; } breakLoop=(result<0); // end of tabular reached (eof or \end) if(result<1) break; //end of tabular line reached } cur.clearSelection(); if(result==-1) break; // add element if(result>0 || off){ do{ result=findNextToken(cur,nTokens,true); }while(result==1); QString selText=cur.selectedText(); int add=0; if(selText.startsWith("\\multicolumn")){ add=getNumOfColsInMultiColumn(selText); } if(add>1) { //multicolumn handling QStringList values; LatexParser::resolveCommandOptions(selText,0,values); values.takeFirst(); values.prepend(QString("{%1}").arg(add-1)); cur.movePosition(1,QDocumentCursor::Left,QDocumentCursor::KeepAnchor); if(result==0) cur.movePosition(1,QDocumentCursor::Left,QDocumentCursor::KeepAnchor); cur.insertText("\\multicolumn"+values.join("")); }else{ //normal handling if(result==2 && column>0) { cur.movePosition(1,QDocumentCursor::Left,QDocumentCursor::KeepAnchor); } if(result==0) { cur.movePosition(2,QDocumentCursor::Left,QDocumentCursor::KeepAnchor); } QString zw=cur.selectedText(); if(cutBuffer){ if(column==0 && result!=0) zw.chop(1); cutBuffer->append(zw); } // detect elements which need to be kept like \hline QString keep; if(column==0){ QStringList elementsToKeep; elementsToKeep << "\\hline" << "\\endhead" << "\\endfoot" << "\\endfirsthead" << "\\endlastfoot"; for(int i=0;i<zw.length();i++){ if(zw.at(i)=='\n') { if(!keep.endsWith('\n')) keep += "\n"; } //commands if(zw.at(i)=='\\') { QRegExp rx("\\w+"); rx.indexIn(zw,i+1); QString cmd="\\"+rx.cap(); if(elementsToKeep.contains(cmd)){ keep += " " + cmd; } } } if(keep.length()==1) keep.clear();; } cur.removeSelectedText(); if(column>0) { cur.movePosition(1,QDocumentCursor::Left,QDocumentCursor::KeepAnchor); cur.removeSelectedText(); } cur.insertText(keep); } const QStringList tokens("\\\\"); breakLoop=(findNextToken(cur,tokens)==-1); } if(cur.atLineEnd()) cur.movePosition(1,QDocumentCursor::Right); line=cur.line().text(); if(line.contains("\\end{")) breakLoop=true; } cur.endEditBlock(); }