void QCustomTableWidget::addCharacter(int index) { if(pChangeCharacterDial->exec()==QDialog::Accepted) { // updating the CharacterList if (pCharacters != NULL) { Character character(pChangeCharacterDial->name().toStdString(),pChangeCharacterDial->playerName().toStdString()); pCharacters->add(character,index+1); } // updating the display insertRow(index+1); int column_nb; column_nb = columnCount(); for (int i = 0; i < column_nb; i++) { QTableWidgetItem *row1 = new QTableWidgetItem("0"); setItem(index+1,i,row1); } QTableWidgetItem *rowHeaderItem = verticalHeaderItem(index+1); if (rowHeaderItem != NULL) { rowHeaderItem->setText(pChangeCharacterDial->name()+"\n"+pChangeCharacterDial->playerName()); } else { rowHeaderItem = new QTableWidgetItem(pChangeCharacterDial->name()+"\n"+pChangeCharacterDial->playerName()); setVerticalHeaderItem(index+1, rowHeaderItem); } resizeRowsToContents(); } }
ClusterInfoTable::ClusterInfoTable(QWidget * parent) : QTableWidget(parent) { ClusterInfoTable::build_row_indices(); horizontalHeader()->setVisible(false); setRowCount(_ROW_INDICES.row_count); setColumnCount(0); setVerticalHeaderItem(_ROW_INDICES.cluster_id, new QTableWidgetItem("Cluster ID")); setVerticalHeaderItem(_ROW_INDICES.color, new QTableWidgetItem("Color")); setVerticalHeaderItem(_ROW_INDICES.member_count, new QTableWidgetItem("# members")); setVerticalHeaderItem(_ROW_INDICES.slope, new QTableWidgetItem("Slope")); for(int i = 0; i < 12; i++) { QString heading ("Temp ["); heading.append(QString::number(i+1)).append("]"); setVerticalHeaderItem(_ROW_INDICES.temp[i], new QTableWidgetItem(heading)); } for(int i = 0; i < 12; i++) { QString heading ("Illumination ["); heading.append(QString::number(i+1)).append("]"); setVerticalHeaderItem(_ROW_INDICES.illumination[i], new QTableWidgetItem(heading)); } for(int i = 0; i < 12; i++) { QString heading ("Soil Humdity ["); heading.append(QString::number(i+1)).append("]"); setVerticalHeaderItem(_ROW_INDICES.soil_humidity[i], new QTableWidgetItem(heading)); } }
void Table::setMaskType(PolyEdit::Shape type) { isReady = false; clear(); mMask->clear(); switch (type) { case PolyEdit::Polygon: { setColumnCount(2); setRowCount(1); setHorizontalHeaderItem(0, new Cell("X")); setHorizontalHeaderItem(1, new Cell("Y")); break; } case PolyEdit::Circle: { setColumnCount(1); setRowCount(3); setHorizontalHeaderItem(0, new Cell("Circle")); setVerticalHeaderItem(0,new Cell("X")); setVerticalHeaderItem(1,new Cell("Y")); setVerticalHeaderItem(2,new Cell("Radius")); break; } case PolyEdit::Box: { setColumnCount(1); setRowCount(4); setHorizontalHeaderItem(0, new Cell("Box")); setVerticalHeaderItem(0,new Cell("Left")); setVerticalHeaderItem(1,new Cell("Top")); setVerticalHeaderItem(2,new Cell("Width")); setVerticalHeaderItem(3,new Cell("Height")); break; } case PolyEdit::Invalid: { break; } } clearContents(); mType = type; horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); mMask->setType(type); isReady = true; }
void QCustomTableWidget::addCharacter(int index) { if (index < 0) { // if no row is selected, we insert it at the end index += rowCount(); } if(pChangeCharacterDial->exec()==QDialog::Accepted) { // updating the CharacterList if (pCharacters) { Character character(pChangeCharacterDial->name().toStdString(), pChangeCharacterDial->shortDescription().toStdString()); pCharacters->add(character,index+1); emit modificationDone(new CharacterModification(pCharacters, new Character(character), index+1, true)); } // updating the display int column_nb = columnCount(); // created cells iCreatedCells = column_nb; insertRow(index+1); for (int i = 0; i < column_nb; i++) { QTableWidgetItem *row1 = new QTableWidgetItem("0"); setItem(index+1,i,row1); } QTableWidgetItem *rowHeaderItem = verticalHeaderItem(index+1); if (rowHeaderItem) { rowHeaderItem->setText(headerText(pChangeCharacterDial->name(), pChangeCharacterDial->shortDescription())); } else { rowHeaderItem = new QTableWidgetItem(headerText(pChangeCharacterDial->name(), pChangeCharacterDial->shortDescription())); setVerticalHeaderItem(index+1, rowHeaderItem); } scrollTo(index+1, -1); } }
void QCustomTableWidget::setLists(SkillList *skills, CharacterList *chars) { pSkills = skills; pCharacters = chars; clear(); setColumnCount(0); setRowCount(0); int i=0; for (SkillList::iterator it = skills->begin(); it != skills->end(); it++) { insertColumn(i); setHorizontalHeaderItem(i,new QTableWidgetItem((*it).c_str())); i++; } int j=0,k; for (CharacterList::iterator it = chars->begin(); it != chars->end(); it++) { insertRow(j); setVerticalHeaderItem(j,new QTableWidgetItem(((*it).name()+"\n"+(*it).playerName()).c_str())); // creating items for (k=0;k<i;k++) { } // setting values k = 0; for (Character::SkillIterator itSkill = (*it).begin(); itSkill != (*it).end() && k<i; itSkill++) { setItem(j,k,new QTableWidgetItem((*itSkill).c_str())); k++; } for (;k<i;k++) { setItem(j,k,new QTableWidgetItem("0")); } j++; } resizeRowsToContents(); resizeColumnsToContents(); }
void QCustomTableWidget::editCharacter(int index) { if(pChangeCharacterDial->exec()==QDialog::Accepted) { QTableWidgetItem *rowHeaderItem = verticalHeaderItem ( index ); if (rowHeaderItem != NULL) { rowHeaderItem->setText(pChangeCharacterDial->name()+"\n"+pChangeCharacterDial->playerName()); } else { rowHeaderItem = new QTableWidgetItem(pChangeCharacterDial->name()+"\n"+pChangeCharacterDial->playerName()); setVerticalHeaderItem(index, rowHeaderItem); } // updating the CharacterList if (pCharacters != NULL) { Character &charact = (*pCharacters)[index]; charact.setName(pChangeCharacterDial->name().toStdString()); charact.setPlayerName(pChangeCharacterDial->playerName().toStdString()); } } resizeRowToContents(index); }
void QCustomTableWidget::updateDisplay(int row, int column) { // storing the scroll state QScrollBar *hbar = horizontalScrollBar(); QScrollBar *vbar = verticalScrollBar(); int x = hbar->value(); int y = vbar->value(); // iterating over characters and properties to populate the table bUpdate = true; clear(); setColumnCount(0); setRowCount(0); int i=0; for (PropertyList::iterator it = pProperties->begin(); it != pProperties->end(); it++) { insertColumn(i); setHorizontalHeaderItem(i,new QTableWidgetItem((*it).c_str())); i++; } int j=0,k; for (CharacterList::iterator it = pCharacters->begin(); it != pCharacters->end(); it++) { insertRow(j); setVerticalHeaderItem(j, new QTableWidgetItem(headerText((*it).name().c_str(), (*it).shortDescription().c_str()))); // creating items for (k=0;k<i;k++) { } // setting values k = 0; for (Character::PropertyIterator itProperty = (*it).begin(); itProperty != (*it).end() && k<i; itProperty++) { setItem(j,k,new QTableWidgetItem((*itProperty).c_str())); k++; } for (;k<i;k++) { setItem(j,k,new QTableWidgetItem("0")); } j++; } bUpdate = false; if (row > -1 || column > -1) { // restoring the scroll state hbar->setValue(x); vbar->setValue(y); scrollTo(row, column); // setting the current cell, row or column QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Select; if (row == -1) { flags |= QItemSelectionModel::Columns; row = 0; } if (column == -1) { flags |= QItemSelectionModel::Rows; column = 0; } setCurrentCell(row, column, flags); } }