本文整理汇总了C++中QStack::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ QStack::clear方法的具体用法?C++ QStack::clear怎么用?C++ QStack::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStack
的用法示例。
在下文中一共展示了QStack::clear方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: procurafinal
string Tree::procurafinal(string codificacao){
unsigned char buffer;
string aux_s;
aux_s.clear();
ofstream write;
const char* aux_ch = filename.c_str();
write.open(aux_ch, ios::out | ios::binary | ios::app);
if(write.is_open()){
QStack<Node*>* StackdeCodigo = new QStack<Node*>();
StackdeCodigo->push(root);
for(int i = 0; i < codificacao.length();i++){
Node* temp = new Node();
if(codificacao[i] == '0'){
temp = StackdeCodigo->top()->getLeftChild();
if(temp->isLeaf() == false){
StackdeCodigo->push(temp);
}
else{
buffer = temp->getContent();
StackdeCodigo->clear();
StackdeCodigo->push(root);
write << buffer;
}
}
else if(codificacao[i] == '1'){
temp = StackdeCodigo->top()->getRightChild();
if(temp->isLeaf() == false){
StackdeCodigo->push(temp);
}
else{
buffer = temp->getContent();
StackdeCodigo->clear();
StackdeCodigo->push(root);
write << buffer;
}
}
}
}
else
{
cout << "TRASH!" << endl;
}
write.close();
return aux_s;
}
示例2: test
void Browser::test() {
BrowserItem *item = NULL;
BrowserLevel *currentLevel = NULL;
QStack <BrowserLevel *> testStack;
testStack.clear();
rootLevel->reset();
testStack.push(rootLevel);
while (!testStack.isEmpty()) {
currentLevel = testStack.pop();
item = currentLevel->getCurrentItem();
currentLevel->next();
if (item != NULL) {
qDebug() << "item:" << item->getPresentationData();
if (item->hasAction()) {
qDebug() << "has action:" << item->getActionModule() << ":" << item->getActionName();
} else if (item->hasLevelBelow()) {
qDebug() << "has one level below, going down";
testStack.push(currentLevel);
currentLevel = item->getLevelBelow();
currentLevel->reset();
}
}
testStack.push(currentLevel);
if (currentLevel->atEnd()) {
if (!testStack.isEmpty()) {
currentLevel = testStack.pop();
}
}
}
}
示例3: if
void stackShow::Post2In(QStringList &phrase)
{
static QStack <QString> stack;
QString r,r1,r2;
QString l[4]={"+" , "-" , "*" , "/" };
for (int i=0; i<phrase.size(); i++)
for (int j=0 ; j<4 ; j++)
{
if (phrase.at(i)!=l[j] && j==3)
{
stack.push(phrase.at(i));
ui->lneRes->insert(phrase.at(i) + " ");
phrase.removeFirst();
r = phrase.join(" ");
ui->lneExp->setText(r);
return;
}
else if ( phrase.at(i)==l[j] )
{
if (stack.size()<2)
return ;
QStringList t = stack.toList();
t.removeLast();
t.removeLast();
r = t.join(" ");
r1=stack.pop();
r2=stack.pop();
stack.push( "( " + r2 + " " + phrase.at(i) + " " + r1 + " ) ");
ui->lneRes->setText( "( " + r2 + " " + phrase.at(i) + " " + r1 + " ) ");
ui->lneStack->setText( r + " " "( " + r2 + " " + phrase.at(i) + " " + r1 + " ) ");
phrase.removeFirst();
r = phrase.join(" ");
ui->lneExp->setText(r);
if (phrase.size()==0)
stack.clear();
return;
}
}
}
示例4: loadJava
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd)
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
cd.appendError(QString::fromLatin1("Cannot open %1: %2")
.arg(filename, file.errorString()));
return false;
}
yyDefaultContext = cd.m_defaultContext;
yyInPos = -1;
yyFileName = filename;
yyPackage.clear();
yyScope.clear();
yyTok = -1;
yyParenDepth = 0;
yyCurLineNo = 0;
yyParenLineNo = 1;
QTextStream ts(&file);
QByteArray codecName;
if (!cd.m_codecForSource.isEmpty())
codecName = cd.m_codecForSource;
else
codecName = translator.codecName(); // Just because it should be latin1 already
ts.setCodec(QTextCodec::codecForName(codecName));
ts.setAutoDetectUnicode(true);
yyInStr = ts.readAll();
yyInPos = 0;
yyFileName = filename;
yyCurLineNo = 1;
yyParenLineNo = 1;
parse(&translator);
// Java uses UTF-16 internally and Jambi makes UTF-8 for tr() purposes of it.
translator.setCodecName("UTF-8");
return true;
}
示例5: startTokenizer
static void startTokenizer( const char *fileName, int (*getCharFunc)(),
int (*peekCharFunc)(), QTextCodec *codecForTr, QTextCodec *codecForSource )
{
yyInPos = 0;
buf = rawbuf = -1;
getChar = getCharFunc;
peekChar = peekCharFunc;
yyFileName = fileName;
yyCh = getChar();
yySavedParenDepth.clear();
yyParenDepth = 0;
yyCurLineNo = 1;
yyParenLineNo = 1;
yyCodecForTr = codecForTr;
if (!yyCodecForTr)
yyCodecForTr = QTextCodec::codecForName("ISO-8859-1");
Q_ASSERT(yyCodecForTr);
yyCodecForSource = codecForSource;
yyParsingUtf8 = false;
}
示例6: powerSeek
void Seeker::powerSeek( QString path ) {
this->flag = false ;
this->result.clear() ;
Node* node = this->seek( path ) ;
if ( node ) {
if ( node->record.count() ) {
//qDebug() << "get" << path ;
this->result.append( node ) ;
this->flag = true ;
}
else {
//qDebug() << "power seek" ;
QStack<Node*> current;
QStack<Node*> deeper;
current.push( this->current ) ;
while( current.count() > 0 && this->result.count() < 1 ) {
while( current.count() > 0 ) {
node = current.pop() ;
//qDebug() << QString( node->code ) ;
if ( node->record.count() )
this->result.append( node ) ;
else {
if ( this->result.count() < 1 ) {
for ( int i = 0; i < node->child.count(); i++ ) {
deeper.append( node->child[i] ) ;
}
}
}
}
current = deeper ;
deeper.clear() ;
}
}
}
//return this->result ;
}
示例7: parse
bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage)
{
QMimeTypePrivate data;
int priority = 50;
QStack<QMimeMagicRule *> currentRules; // stack for the nesting of rules
QList<QMimeMagicRule> rules; // toplevel rules
QXmlStreamReader reader(dev);
ParseState ps = ParseBeginning;
QXmlStreamAttributes atts;
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
ps = nextState(ps, reader.name());
atts = reader.attributes();
switch (ps) {
case ParseMimeType: { // start parsing a MIME type name
const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString();
if (name.isEmpty()) {
reader.raiseError(QString::fromLatin1("Missing '%1'-attribute").arg(QString::fromLatin1(mimeTypeAttributeC)));
} else {
data.name = name;
}
}
break;
case ParseGenericIcon:
data.genericIconName = atts.value(QLatin1String(nameAttributeC)).toString();
break;
case ParseIcon:
data.iconName = atts.value(QLatin1String(nameAttributeC)).toString();
break;
case ParseGlobPattern: {
const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString();
unsigned weight = atts.value(QLatin1String(weightAttributeC)).toString().toInt();
const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)).toString() == QLatin1String("true");
if (weight == 0)
weight = QMimeGlobPattern::DefaultWeight;
Q_ASSERT(!data.name.isEmpty());
const QMimeGlobPattern glob(pattern, data.name, weight, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
if (!process(glob, errorMessage)) // for actual glob matching
return false;
data.addGlobPattern(pattern); // just for QMimeType::globPatterns()
}
break;
case ParseSubClass: {
const QString inheritsFrom = atts.value(QLatin1String(mimeTypeAttributeC)).toString();
if (!inheritsFrom.isEmpty())
processParent(data.name, inheritsFrom);
}
break;
case ParseComment: {
// comments have locale attributes. We want the default, English one
QString locale = atts.value(QLatin1String(localeAttributeC)).toString();
const QString comment = reader.readElementText();
if (locale.isEmpty())
locale = QString::fromLatin1("en_US");
data.localeComments.insert(locale, comment);
}
break;
case ParseAlias: {
const QString alias = atts.value(QLatin1String(mimeTypeAttributeC)).toString();
if (!alias.isEmpty())
processAlias(alias, data.name);
}
break;
case ParseMagic: {
priority = 50;
const QString priorityS = atts.value(QLatin1String(priorityAttributeC)).toString();
if (!priorityS.isEmpty()) {
if (!parseNumber(priorityS, &priority, errorMessage))
return false;
}
currentRules.clear();
//qDebug() << "MAGIC start for mimetype" << data.name;
}
break;
case ParseMagicMatchRule: {
QMimeMagicRule *rule = 0;
if (!createMagicMatchRule(atts, errorMessage, rule))
return false;
QList<QMimeMagicRule> *ruleList;
if (currentRules.isEmpty())
ruleList = &rules;
else // nest this rule into the proper parent
ruleList = ¤tRules.top()->m_subMatches;
ruleList->append(*rule);
//qDebug() << " MATCH added. Stack size was" << currentRules.size();
currentRules.push(&ruleList->last());
delete rule;
break;
}
case ParseError:
reader.raiseError(QString::fromLatin1("Unexpected element <%1>").
arg(reader.name().toString()));
break;
default:
break;
}
//.........这里部分代码省略.........
示例8: calculPopupGeometry
void pTreeComboBox::calculPopupGeometry()
{
if ( !mView ) {
return;
}
QStyle * const style = this->style();
// set current item and select it
view()->selectionModel()->setCurrentIndex( mCurrentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
QFrame* container = mFrame;
QStyleOptionComboBox opt;
initStyleOption( &opt );
QRect listRect( style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this ) );
QRect screen = popupGeometry( QApplication::desktop()->screenNumber( this ) );
QPoint below = mapToGlobal( listRect.bottomLeft() );
int belowHeight = screen.bottom() -below.y();
QPoint above = mapToGlobal( listRect.topLeft() );
int aboveHeight = above.y() -screen.y();
bool boundToScreen = !window()->testAttribute( Qt::WA_DontShowOnScreen );
listRect.moveTopLeft( mapToGlobal( rect().bottomLeft() ) );
listRect.setSize( QSize(
qMax( qMax( view()->viewport()->width(), mFrame->width() ), width() )
,
qMax( view()->viewport()->height(), mFrame->height() )
) );
const bool usePopup = style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this );
{
int listHeight = 0;
int count = 0;
QStack<QModelIndex> toCheck;
toCheck.push( view()->rootIndex() );
#ifndef QT_NO_TREEVIEW
QTreeView* treeView = qobject_cast<QTreeView*>( view() );
if ( treeView && treeView->header() && !treeView->header()->isHidden() )
listHeight += treeView->header()->height();
#endif
while ( !toCheck.isEmpty() ) {
QModelIndex parent = toCheck.pop();
for ( int i = 0; i < model()->rowCount( parent ); ++i ) {
QModelIndex idx = model()->index( i, mModelColumn, parent );
if ( !idx.isValid() )
continue;
listHeight += view()->visualRect( idx ).height();
#ifndef QT_NO_TREEVIEW
if ( model()->hasChildren( idx ) && treeView && treeView->isExpanded( idx ) )
toCheck.push( idx );
#endif
++count;
if ( !usePopup && count > mMaxVisibleItems ) {
toCheck.clear();
break;
}
}
}
listRect.setHeight( listHeight );
}
{
// add the spacing for the grid on the top and the bottom;
int heightMargin = 0;
// add the frame of the container
int marginTop, marginBottom;
container->getContentsMargins( 0, &marginTop, 0, &marginBottom );
heightMargin += marginTop +marginBottom;
//add the frame of the view
view()->getContentsMargins( 0, &marginTop, 0, &marginBottom );
marginTop += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top*/;
marginBottom += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom*/;
heightMargin += marginTop +marginBottom;
listRect.setHeight( listRect.height() +heightMargin );
}
// Add space for margin at top and bottom if the style wants it.
if ( usePopup )
listRect.setHeight( listRect.height() +style->pixelMetric( QStyle::PM_MenuVMargin, &opt, this ) *2 );
// Make sure the popup is wide enough to display its contents.
if ( usePopup ) {
const int diff = sizeHint().width() /*d->computeWidthHint()*/ -width();
if ( diff > 0 )
listRect.setWidth( listRect.width() +diff );
}
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
container->layout()->activate();
//takes account of the minimum/maximum size of the container
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
.boundedTo(container->maximumSize()));
// make sure the widget fits on screen
if (boundToScreen) {
if (listRect.width() > screen.width() )
listRect.setWidth(screen.width());
if (/*mapToGlobal(*/listRect/*.bottomRight())*/.x() > screen.right()) {
//.........这里部分代码省略.........
示例9: resizePopup
// -------------------------------------------------------------------------
void ctkTreeComboBox::resizePopup()
{
// copied from QComboBox.cpp
Q_D(ctkTreeComboBox);
QStyle * const style = this->style();
QWidget* container = qobject_cast<QWidget*>(this->view()->parent());
QStyleOptionComboBox opt;
this->initStyleOption(&opt);
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
QStyle::SC_ComboBoxListBoxPopup, this));
QRect screen = QApplication::desktop()->availableGeometry(
QApplication::desktop()->screenNumber(this));
QPoint below = this->mapToGlobal(listRect.bottomLeft());
int belowHeight = screen.bottom() - below.y();
QPoint above = this->mapToGlobal(listRect.topLeft());
int aboveHeight = above.y() - screen.y();
bool boundToScreen = !this->window()->testAttribute(Qt::WA_DontShowOnScreen);
const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
{
int listHeight = 0;
int count = 0;
QStack<QModelIndex> toCheck;
toCheck.push(this->view()->rootIndex());
#ifndef QT_NO_TREEVIEW
QTreeView *treeView = qobject_cast<QTreeView*>(this->view());
if (treeView && treeView->header() && !treeView->header()->isHidden())
listHeight += treeView->header()->height();
#endif
while (!toCheck.isEmpty())
{
QModelIndex parent = toCheck.pop();
for (int i = 0; i < this->model()->rowCount(parent); ++i)
{
QModelIndex idx = this->model()->index(i, this->modelColumn(), parent);
if (!idx.isValid())
{
continue;
}
listHeight += this->view()->visualRect(idx).height(); /* + container->spacing() */;
#ifndef QT_NO_TREEVIEW
if (this->model()->hasChildren(idx) && treeView && treeView->isExpanded(idx))
{
toCheck.push(idx);
}
#endif
++count;
if (!usePopup && count > this->maxVisibleItems())
{
toCheck.clear();
break;
}
}
}
listRect.setHeight(listHeight);
}
{
// add the spacing for the grid on the top and the bottom;
int heightMargin = 0;//2*container->spacing();
// add the frame of the container
int marginTop, marginBottom;
container->getContentsMargins(0, &marginTop, 0, &marginBottom);
heightMargin += marginTop + marginBottom;
//add the frame of the view
this->view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
//marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->top;
//marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->bottom;
heightMargin += marginTop + marginBottom;
listRect.setHeight(listRect.height() + heightMargin);
}
// Add space for margin at top and bottom if the style wants it.
if (usePopup)
{
listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
}
// Make sure the popup is wide enough to display its contents.
if (usePopup)
{
const int diff = d->computeWidthHint() - this->width();
if (diff > 0)
{
listRect.setWidth(listRect.width() + diff);
}
}
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
container->layout()->activate();
//takes account of the minimum/maximum size of the container
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
.boundedTo(container->maximumSize()));
// make sure the widget fits on screen
//.........这里部分代码省略.........
示例10: reset
void PreprocessContext::reset()
{
m_sectionStack.clear();
// Add a default, enabled section.
m_sectionStack.push(PreprocessStackEntry(OtherSection, true, true));
}
示例11: progressChanged
void
Volume::findConnectedRegion(int mind, int maxd,
int minw, int maxw,
int minh, int maxh,
QList<int> pos,
bool sliceOnly)
{
m_connectedbitmask.fill(false);
uchar *lut = Global::lut();
QStack<int> stack;
uchar *vslice;
uchar v0, g0;
int d = pos[0];
int w = pos[1];
int h = pos[2];
vslice = m_pvlFileManager.rawValue(d, w, h);
v0 = vslice[0];
// vslice = m_gradFileManager.rawValue(d, w, h);
// g0 = vslice[0];
g0 = 0;
// put the seeds in
for(int pi=0; pi<pos.size()/3; pi++)
{
int d = pos[3*pi];
int w = pos[3*pi+1];
int h = pos[3*pi+2];
if (d >= mind && d <= maxd &&
w >= minw && w <= maxw &&
h >= minh && h <= maxh)
{
qint64 idx = d*m_width*m_height + w*m_height + h;
if (m_bitmask.testBit(idx))
{
m_connectedbitmask.setBit(idx);
stack.push(d);
stack.push(w);
stack.push(h);
}
}
}
if (sliceOnly)
stack.clear();
int pv = 0;
int progv = 0;
while(!stack.isEmpty())
{
progv++;
if (progv == 1000)
{
progv = 0;
pv = (++pv % 100);
emit progressChanged(pv);
}
int h = stack.pop();
int w = stack.pop();
int d = stack.pop();
qint64 idx = d*m_width*m_height + w*m_height + h;
if (m_bitmask.testBit(idx))
{
int d0 = qMax(d-1, 0);
int d1 = qMin(d+1, m_depth-1);
int w0 = qMax(w-1, 0);
int w1 = qMin(w+1, m_width-1);
int h0 = qMax(h-1, 0);
int h1 = qMin(h+1, m_height-1);
for(int d2=d0; d2<=d1; d2++)
for(int w2=w0; w2<=w1; w2++)
for(int h2=h0; h2<=h1; h2++)
{
if (d2 >= mind && d2 <= maxd &&
w2 >= minw && w2 <= maxw &&
h2 >= minh && h2 <= maxh)
{
qint64 idx = d2*m_width*m_height +
w2*m_height + h2;
if ( m_bitmask.testBit(idx) &&
!m_connectedbitmask.testBit(idx) )
{
// uchar v, g;
// vslice = m_pvlFileManager.rawValue(d2, w2, h2);
// v = vslice[0];
// vslice = m_gradFileManager.rawValue(d2, w2, h2);
// g = vslice[0];
//
// if (qAbs(v-v0) < Global::deltaV() &&
// g < Global::deltaG())
{
m_connectedbitmask.setBit(idx);
stack.push(d2);
stack.push(w2);
stack.push(h2);
}
//.........这里部分代码省略.........
示例12: parseTrace
void TraceLoader::parseTrace()
{
QList<ApiTraceFrame*> frames;
ApiTraceFrame *currentFrame = 0;
int frameCount = 0;
QStack<ApiTraceCall*> groups;
QVector<ApiTraceCall*> topLevelItems;
QVector<ApiTraceCall*> allCalls;
quint64 binaryDataSize = 0;
int lastPercentReport = 0;
trace::Call *call = m_parser.parse_call();
while (call) {
//std::cout << *call;
if (!currentFrame) {
currentFrame = new ApiTraceFrame();
currentFrame->number = frameCount;
++frameCount;
}
ApiTraceCall *apiCall =
apiCallFromTraceCall(call, m_helpHash, currentFrame, groups.isEmpty() ? 0 : groups.top(), this);
allCalls.append(apiCall);
if (groups.count() == 0) {
topLevelItems.append(apiCall);
}
if (call->flags & trace::CALL_FLAG_MARKER_PUSH) {
groups.push(apiCall);
} else if (call->flags & trace::CALL_FLAG_MARKER_POP) {
groups.top()->finishedAddingChildren();
groups.pop();
}
if (!groups.isEmpty()) {
groups.top()->addChild(apiCall);
}
if (apiCall->hasBinaryData()) {
QByteArray data =
apiCall->arguments()[apiCall->binaryDataIndex()].toByteArray();
binaryDataSize += data.size();
}
if (call->flags & trace::CALL_FLAG_END_FRAME) {
allCalls.squeeze();
topLevelItems.squeeze();
if (topLevelItems.count() == allCalls.count()) {
currentFrame->setCalls(allCalls, allCalls, binaryDataSize);
} else {
currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize);
}
allCalls.clear();
groups.clear();
topLevelItems.clear();
frames.append(currentFrame);
currentFrame = 0;
binaryDataSize = 0;
if (frames.count() >= FRAMES_TO_CACHE) {
emit framesLoaded(frames);
frames.clear();
}
if (m_parser.percentRead() - lastPercentReport >= 5) {
emit parsed(m_parser.percentRead());
lastPercentReport = m_parser.percentRead();
}
}
delete call;
call = m_parser.parse_call();
}
//last frames won't have markers
// it's just a bunch of Delete calls for every object
// after the last SwapBuffers
if (currentFrame) {
allCalls.squeeze();
if (topLevelItems.count() == allCalls.count()) {
currentFrame->setCalls(allCalls, allCalls, binaryDataSize);
} else {
currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize);
}
frames.append(currentFrame);
currentFrame = 0;
}
if (frames.count()) {
emit framesLoaded(frames);
}
}