int main(int argc,char **argv) { QApplication app(argc,argv); QPtrList<int> list; for (int i=0;i<3;i++) { list.append(new int(i)); // 插入資料 } list.first(); // 先跳到第一個元素 for (int i=0;i<3;i++,list.next()) { cout << *(list.current()) << endl; } list.first(); list.next(); list.remove(); list.remove(); list.remove(); cout << *(list.current()) << endl; // 由這一個例子可以知道,刪掉一個成員後,指標會跑到下一個.但若刪掉後沒有下一個時,指標會跑到前一個 return 0; }
void QtCalculator::temp_stack_next(){ CALCAMNT *number; if( temp_stack.current() == temp_stack.getLast()){ KNotifyClient::beep(); return; } number = temp_stack.next(); if(number == NULL){ KNotifyClient::beep(); return; } else{ // printf("Number: %Lg\n",*number); last_input = RECALL; DISPLAY_AMOUNT = *number; UpdateDisplay(); } }
void QXsldbgDoc::clearMarks(bool allMarkTypes) { if (locked) return; KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc); if (markIf){ if (!allMarkTypes){ QPtrList<KTextEditor::Mark> marks = markIf->marks(); while ( marks.current()) { markIf->removeMark(marks.current()->line, KTextEditor::MarkInterface::Execution); markIf->removeMark(marks.current()->line, KTextEditor::MarkInterface::BreakpointReached); marks.next(); } }else { markIf->clearMarks(); } } }
// ----------------------------------------------------------------------- // Is called if the "Replace"-button is pressed. void ChangeDialog::slotButtReplace() { Expr.setWildcard(true); // switch into wildcard mode Expr.setPattern(CompNameEdit->text()); /* if(!Expr.isValid()) { QMessageBox::critical(this, tr("Error"), tr("Regular expression for component name is invalid.")); return; }*/ // create dialog showing all found components QDialog *Dia = new QDialog(this); Dia->setCaption(tr("Found Components")); QVBoxLayout *Dia_All = new QVBoxLayout(Dia); Dia_All->setSpacing(3); Dia_All->setMargin(5); QScrollView *Dia_Scroll = new QScrollView(Dia); Dia_Scroll->setMargin(5); Dia_All->addWidget(Dia_Scroll); QVBox *Dia_Box = new QVBox(Dia_Scroll->viewport()); Dia_Scroll->addChild(Dia_Box); QLabel *Dia_Label = new QLabel(tr("Change properties of\n") + tr("these components ?"), Dia); Dia_All->addWidget(Dia_Label); QHBox *Dia_h = new QHBox(Dia); Dia_h->setSpacing(5); Dia_All->addWidget(Dia_h); QPushButton *YesButton = new QPushButton(tr("Yes"), Dia_h); connect(YesButton, SIGNAL(clicked()), Dia, SLOT(accept())); connect(new QPushButton(tr("Cancel"), Dia_h), SIGNAL(clicked()), Dia, SLOT(reject())); QPtrList<QCheckBox> pList; QCheckBox *pb; Component *pc; QStringList List; QString str; int i1, i2; // search through all components for(pc = Doc->Components->first(); pc!=0; pc = Doc->Components->next()) { if(matches(pc->Model)) { if(Expr.search(pc->Name) >= 0) for(Property *pp = pc->Props.first(); pp!=0; pp = pc->Props.next()) if(pp->Name == PropNameEdit->currentText()) { pb = new QCheckBox(pc->Name, Dia_Box); pList.append(pb); pb->setChecked(true); i1 = pp->Description.find('['); if(i1 < 0) break; // no multiple-choice property i2 = pp->Description.findRev(']'); if(i2-i1 < 2) break; str = pp->Description.mid(i1+1, i2-i1-1); str.replace( QRegExp("[^a-zA-Z0-9_,]"), "" ); List = List.split(',',str); if(List.findIndex(NewValueEdit->text()) >= 0) break; // property value is okay pb->setChecked(false); pb->setEnabled(false); break; } } } QColor theColor; if(pList.isEmpty()) { YesButton->setEnabled(false); theColor = (new QLabel(tr("No match found!"), Dia_Box))->paletteBackgroundColor(); } else theColor = pList.current()->paletteBackgroundColor(); Dia_Scroll->viewport()->setPaletteBackgroundColor(theColor); Dia->resize(50, 300); // show user all components found int Result = Dia->exec(); if(Result != QDialog::Accepted) return; bool changed = false; // change property values for(pb = pList.first(); pb!=0; pb = pList.next()) { if(!pb->isChecked()) continue; for(pc = Doc->Components->first(); pc!=0; pc = Doc->Components->next()) { if(pb->text() != pc->Name) continue; for(Property *pp = pc->Props.first(); pp!=0; pp = pc->Props.next()) { if(pp->Name != PropNameEdit->currentText()) continue; int tx_Dist, ty_Dist, tmp; pc->textSize(tx_Dist, ty_Dist); tmp = pc->tx+tx_Dist - pc->x1; if((tmp > 0) || (tmp < -6)) tx_Dist = 0; // remember text position tmp = pc->ty+ty_Dist - pc->y1; if((tmp > 0) || (tmp < -6)) ty_Dist = 0; pp->Value = NewValueEdit->text(); int dx, dy; pc->textSize(dx, dy); // correct text position if(tx_Dist != 0) { pc->tx += tx_Dist-dx; tx_Dist = dx; } if(ty_Dist != 0) { pc->ty += ty_Dist-dy; ty_Dist = dy; } // apply changes to schematic symbol Doc->recreateComponent(pc); changed = true; break; } break; } } delete Dia_All; delete Dia; if(changed) accept(); else reject(); }