Ejemplo n.º 1
0
bool BootstrapModelPrivate::save()
{
   QString ret;
   for(const Lines* l : m_lines) {
      if (!l->hostname.trimmed().isEmpty()) {
         if (ret.size())
            ret += ';';
         ret += l->hostname + (l->port > -1? ':'+QString::number(l->port):QString());
      }
   }

   //Clear empty lines
   bool val = true;
   for(int i=0;i<m_lines.size();i++) {
      Lines* l = m_lines[i];
      if (l->hostname.isEmpty() && l->port == -1) {
         q_ptr->beginRemoveRows(QModelIndex(),i,i);
         const int idx = m_lines.indexOf(l);
         if (idx >= 0)
            m_lines.removeAt(idx);
         q_ptr->endRemoveRows();
         val = false;
      }
   }

   m_pAccount->d_ptr->setAccountProperty(DRing::Account::ConfProperties::HOSTNAME,ret);
   return val;
}
Ejemplo n.º 2
0
void MainWindow::on_del_clicked()
{
	if(ui->listWidget->count()<=1||ui->listWidget->currentRow()<0||!firstStart)
		return;
	int removeIndex=ui->listWidget->currentRow();
	if(removeIndex==currentSegIndex)
		return;
	for(int i=ui->listWidget->count()-1;i>removeIndex;i--)
		ui->listWidget->item(i)->setText(QString::number(i));
	QListWidgetItem* item=ui->listWidget->takeItem(removeIndex);
	delete item;
	segTime.removeAt(removeIndex);
	updateSpinBoxTime();
	on_listWidget_itemSelectionChanged();
}
Ejemplo n.º 3
0
void Field::throwBalls(int num, bool directly)
{
    QVector<QPoint> free;
    free.fill(QPoint(0, 0), W * H);
    int nFree = 0;
    for (int i = 0; i < W; i++)
        for (int j = 0; j < H; j++)
            if (at(i, j) == 0)
            {
                free[nFree] = QPoint(i, j);
                nFree++;
            }

#ifdef QT_DEBUG
    for (int i = 0; i < W * H; i++)
    {
        //qDebug("%d, %d", free[i].x(), free[i].y());
    }
#endif
    //return;

    QList<SuggestedBall> ballsToThrow;
    for (int n = 0; n < num; n++)
    {
        if (nFree > 0)
        {
            int at = qrand() % nFree;
            ballsToThrow.append({ free[at], qrand() % COLORS + 1, NULL, NULL });
            free.removeAt(at);
            nFree--;
        }
        else
            ballsToThrow.append({ QPoint(-1, -1), qrand() % COLORS + 1, NULL, NULL });
    }

    if (directly)
    {
        // This is needed on startup only, therefore do nothing except placing balls
        foreach (auto ball, ballsToThrow)
        {
            setAt(ball.pt, ball.color);
            QGraphicsObject *item = new SvgRendererItem(ResourceLoader::instance()->ball(ball.color));
            item->setPos(ball.pt * CELL_SIZE);
            item->setZValue(3);
            m_scene->addItem(item);
            setVectorAt(m_fieldItems, ball.pt, item);
        }
    }
Ejemplo n.º 4
0
void Dialog::deleteitem()
{
 //int detext=(deindex->text().isEmpty())?count:(deindex->text().toInt());
   int detext=deindex->text().toInt();
  if(detext<=0||detext>count)
  {
   QMessageBox::critical(NULL, "输入错误", "输入数字不在范围内",QMessageBox::Yes | QMessageBox::No,QMessageBox::Yes);
  }else{
      QString str="确定要删除第"+QString::number(detext)+"篇文献?";
      QMessageBox message(QMessageBox::Question,"检查",str,QMessageBox::Ok|QMessageBox::Cancel,NULL);
      if(message.exec()==QMessageBox::Ok)
      {
        textresult.removeAt(detext-1);
       // textresult.resize(textresult.size()-1);
        count--;
        updatetext();
      }

  }
}
// calculateVectorInput(QVector<ExpressionElement> input)
//
//
//
ExpressionElement StringCalculator::calculateVectorInput(QVector<ExpressionElement> input)
{
    // Copy the old list that we will boil down to
    // a single expression element.
    QVector<ExpressionElement> modifiableVector = QVector<ExpressionElement>(input);

    // Put in implied constants at the beginning
    if(!input.at(0).isNumber_)
    {
        if(input.at(0).op_ == "-" || input.at(0).op_ == "+") // Allow for negative numbers
        {
            modifiableVector.insert(0, ExpressionElement(0));
        }
        else if(input.at(0).op_ == "*" || input.at(0).op_ == "/" || input.at(0).op_ == "^") // Complain when we begin with these
        {
            // SYNTAX ERROR
            throw 101;
        }
        else // Allow for stuff like "sin(45)" and "log(100)"
        {
            modifiableVector.insert(0, ExpressionElement(1));
        }
    }

    // Put in implied constants at the end.
    if(!input.at(input.size()-1).isNumber_)
    {
        if(input.at(input.size()-1).op_ == "pi"
                || input.at(input.size()-1).op_ == "e"
                || input.at(input.size()-1).op_ == "!")
        {
            modifiableVector.append(ExpressionElement(1));
        }
        else
        {
            // SYNTAX ERROR
            throw 102;
        }
    }

    if(modifiableVector.size() == 2)
    {
        // INTERNAL ERROR: It's impossible to have an ExpressionElement vector
        // of size 2
        throw 100;
    }

    // BEGIN LOOPS
    // --------------------------------
    // Loop through every operation, in the order defined by OP_ORDER
    for(int opIndex = 0; opIndex < OP_ORDER.size(); opIndex++)
    {

        int opCount = 0; // Represents the number of this type of operation in the list.

        for(int e = 0; e < modifiableVector.size(); e++)
        {
            ExpressionElement elem = modifiableVector[e];
            if(!elem.isNumber_)
            {
                if(elem.op_ == OP_ORDER[opIndex]) // Check to see if this is our operation
                {
                    opCount++;
                }
            }
        }

        // Go through every operation of this type first and calculate it out.
        while(opCount > 0)
        {
            int i = 0; // Iterator for each operation
            while(i < modifiableVector.size()-2)
            {
                // Get the element in front of this one, and check if it's an operation.
                ExpressionElement opElement = modifiableVector[i+1];
                if(!opElement.isNumber_)
                {
                    if(opElement.op_ == OP_ORDER[opIndex])
                    {
                        // TODO:
                        // We need a try catch here for when the calc doesn't work
                        QVector<ExpressionElement> calculatedElements = opElement.calc(modifiableVector[i], modifiableVector[i+2]);

                        // Remove these 3 and substitute my own elements.
                        modifiableVector.removeAt(i+2);
                        modifiableVector.removeAt(i+1);
                        modifiableVector.removeAt(i);

                        for(int j = calculatedElements.size() - 1; j >= 0; j--)
                        {
                            // Insert the elements in reverse order. This is due to how insertion works.
                            modifiableVector.insert(i, calculatedElements.at(j));
                        }
                    }
                    opCount--; // We removed the element from the list
                }
                i++;
            }
        }
    }
    // --------------------------------
    // END LOOPS
    return modifiableVector[0];
}
void BaseEditorProperty::removeChild(int index)
{
	delete m_children[index];
	m_children.removeAt(index);
}