void QCustomTableWidget::removeProperty(int index) { if (index != -1) { removeColumn(logicalColumn(index)); // updating the she property/character Lists std::vector<std::string> values; if (pCharacters) { for (CharacterList::iterator it = pCharacters->begin(); it != pCharacters->end(); it++) { if ((unsigned int)index < it->propertyNumber()) { values.push_back(it->property(index)); it->removeProperty(index); } } } if (pProperties) { if (pCharacters) { emit modificationDone(new CharacterModification(pProperties, (*pProperties)[index], pCharacters, values, index)); } pProperties->remove(index); } if (index == columnCount()) { index--; } setCurrentCell(0, index, QItemSelectionModel::Select | QItemSelectionModel::Columns); } }
void QCustomTableWidget::onCellChanged(int logicalRow, int logicalColumn) { // visual indices int row = visualRow(logicalRow); int column = visualColumn(logicalColumn); if (pCharacters) { Character &charact = (*pCharacters)[row]; for (int i=charact.propertyNumber(); i<column+1; i++) { charact.addProperty("0"); } std::string value = charact.property(column); std::string newValue = item(logicalRow, logicalColumn)->text().toStdString(); charact.property(column) = newValue; if (iCreatedCells) { // we ignore the newly created cells iCreatedCells--; } else if (!bUpdate) { // if it is a real modification, we register it emit modificationDone(new CharacterModification(pCharacters, value, newValue, row, column)); } } }
void QCustomTableWidget::onVHeaderMoved(int, int oldRow, int newRow) { if (pCharacters) { if (pCharacters->move(oldRow, newRow)) { emit modificationDone(new CharacterModification(pCharacters, oldRow, newRow)); } } }
void QCustomTableWidget::addProperty(int index) { if (index < 0) { // if no column is selected, we insert it at the end index += columnCount(); } if(pChangePropertyDial->exec()==QDialog::Accepted) { // modifying the property/character Lists if (pProperties) { std::string property = pChangePropertyDial->text().toStdString(); pProperties->add(property, index+1); emit modificationDone(new CharacterModification(pProperties, property, pCharacters, index+1)); } if (pCharacters) { for (CharacterList::iterator it=pCharacters->begin(); it != pCharacters->end(); it++) { if ((unsigned int)index+1 < it->propertyNumber()) { // adding a property it->addProperty("0",index+1); } } } // updating the display int row_nb = rowCount(); // created cells iCreatedCells = row_nb; insertColumn(index+1); for (int i = 0; i < row_nb; i++) { QTableWidgetItem *col1 = new QTableWidgetItem("0"); setItem(i,index+1,col1); } QTableWidgetItem *columnHeaderItem = horizontalHeaderItem(index+1); if (columnHeaderItem) { columnHeaderItem->setText(pChangePropertyDial->text()); } else { columnHeaderItem = new QTableWidgetItem(pChangePropertyDial->text()); setHorizontalHeaderItem(index+1, columnHeaderItem); } scrollTo(-1, index+1); } }
void QCustomTableWidget::onHHeaderMoved(int, int oldColumn, int newColumn) { if (pProperties) { if (pProperties->move(oldColumn, newColumn) && pCharacters) { emit modificationDone(new CharacterModification(pProperties, pCharacters, oldColumn, newColumn)); } } if (pCharacters) { for (CharacterList::iterator it = pCharacters->begin(); it != pCharacters->end(); it++) { it->moveProperty(oldColumn, newColumn); } } }
void QCustomTableWidget::removeCharacter(int index) { if (index != -1) { removeRow(logicalRow(index)); // updating the CharacterList if (pCharacters) { emit modificationDone(new CharacterModification(pCharacters, new Character((*pCharacters)[index]), index, false)); pCharacters->remove(index); } if (index == rowCount()) { index--; } setCurrentCell(index, 0, QItemSelectionModel::Select | QItemSelectionModel::Rows); } }
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::editProperty(int index) { if (index != -1) { scrollTo(-1, index); int logIndex = logicalColumn(index); QTableWidgetItem *columnHeaderItem = horizontalHeaderItem(logIndex); if(pChangePropertyDial->exec(columnHeaderItem->text())==QDialog::Accepted) { // updating the PropertyList if (pProperties) { std::string newProperty = pChangePropertyDial->text().toStdString(); emit modificationDone(new CharacterModification(pProperties, (*pProperties)[index], newProperty, index)); (*pProperties)[index] = newProperty; } QTableWidgetItem *columnHeaderItem = horizontalHeaderItem(logIndex); columnHeaderItem->setText(pChangePropertyDial->text()); scrollTo(-1, index); } } }
void QCustomTableWidget::editCharacter(int index) { if (index != -1) { scrollTo(index, -1); if (pCharacters) { Character &character = (*pCharacters)[index]; if(pChangeCharacterDial->exec(&character)==QDialog::Accepted) { // updating the CharacterList std::string name = character.name(); std::string shortDescription = character.shortDescription(); character.setName(pChangeCharacterDial->name().toStdString()); character.setShortDescription(pChangeCharacterDial->shortDescription().toStdString()); emit modificationDone(new CharacterModification(pCharacters, name, shortDescription, character.name(), character.shortDescription(), index)); QTableWidgetItem *rowHeaderItem = verticalHeaderItem(logicalRow(index)); rowHeaderItem->setText(headerText(pChangeCharacterDial->name(), pChangeCharacterDial->shortDescription())); } scrollTo(index, -1); } } }
void DateEditor::on_valueDateEdit_dateChanged(const QDate &aValue) { modificationDone(aValue); }