示例#1
0
void TableView::addRow(types::Data &data, int fid)
{
    QTableWidget* table =  getTableWidget();

    if(0!=table)
    {
        if(fid>=table->rowCount())
        {
            table->setRowCount(fid+50);
        }
        unsigned int size = data.size();
        if(table->columnCount()<(int)size)
        {
            size = table->columnCount();
        }
        for(unsigned int i=0;i<size;i++)
        {
            table->setItem(fid,i,new QTableWidgetItem(QString("%1").arg(data[i])));
        }
        table->selectRow(fid);
        if(_realcount<fid)
        {
            _realcount = fid;
        }
   }
}
示例#2
0
文件: pages.cpp 项目: valisc/freeciv
/***************************************************************************
  Updates list of servers in network page in proper QTableViews
***************************************************************************/
void fc_client::update_server_list(enum server_scan_type sstype,
                                   const struct server_list *list)
{
  QTableWidget* sel = NULL;
  QString host, portstr;
  int port;

  switch (sstype) {
  case SERVER_SCAN_LOCAL:
    sel = lan_widget;
    break;
  case SERVER_SCAN_GLOBAL:
    sel = wan_widget;
    break;
  default:
    break;
  }

  if (!sel) {
    return;
  }

  if (!list) {
    return;
  }

  host = connect_host_edit->text();
  portstr = connect_port_edit->text();
  port = portstr.toInt();
  sel->clearContents();
  sel->setRowCount(0);
  int row = 0;
  server_list_iterate(list, pserver) {
    char buf[20];
    sel->insertRow(row);

    if (pserver->humans >= 0) {
      fc_snprintf(buf, sizeof(buf), "%d", pserver->humans);
    } else {
      strncpy(buf, _("Unknown"), sizeof(buf));
    }

    int tmp = pserver->port;
    QString tstring = QString::number(tmp);

    for (int col = 0; col < 6; col++) {
      QTableWidgetItem *item;
      item = new QTableWidgetItem();

      switch (col) {
      case 0:
        item->setText(pserver->host);
        break;
      case 1:
        item->setText(tstring);
        break;
      case 2:
        item->setText(pserver->version);
        break;
      case 3:
        item->setText(_(pserver->state));
        break;
      case 4:
        item->setText(buf);
        break;
      case 5:
        item->setText(pserver->message);
        break;
      default:
        break;
      }

      sel->setItem(row, col, item);
    }

    if (host == pserver->host && port == pserver->port) {
      sel->selectRow(row);
    }

    row++;
  } server_list_iterate_end;