void MainWindow::newObjectClicked(QModelIndex index) { // Make sure we can undo this later pushUndo(); // Get filename of object template QString filename = QString(PATH_OBJECT_TEMPLATES + ui->newObjectListWidget->currentItem()->text() + ".template"); // Construct new object from template file QMap<QString, QVariant> newObject = loadObjectFromTemplateFile(filename); // Get center of viewport QRect rect = ui->graphicsView->rect(); int newX = ui->graphicsView->horizontalScrollBar()->value() + rect.width() / 2; int newY = levelPlist.value("level_height").toInt() - ui->graphicsView->verticalScrollBar()->value() - rect.height() / 2; // Rename object newObject.insert("name", getNameForCopy(newObject.value("name").toString())); // Set object's x/y to center of viewport if(newObject.contains("x")) newObject.insert("x", QString("%1").arg(newX)); if(newObject.contains("y")) newObject.insert("y", QString("%1").arg(newY)); // Add new object to levelObjects levelObjects.append(newObject); // Update display ui->objectSelectorComboBox->setCurrentIndex(ui->objectSelectorComboBox->count() - 1); updateGraphics(); updateObjectComboBox(); }
void MainWindow::deleteLevelPropertyClicked() { int row = ui->levelPlistTableWidget->currentRow(); if(row == -1) // nothing selected return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); // iterate to the deleted row QMap<QString, QVariant>::const_iterator it = levelPlist.constBegin(); for(int i = 0; i < row; i++) ++it; levelPlist.remove(it.key()); updateGraphics(); updateLevelPlistTable(); noEmit = false; }
void MainWindow::wallThicknessClicked() { qDebug("Triggered"); // Push an Undo object pushUndo(); int thickness = ui->wallThicknessEdit->text().toInt(); if(thickness <= 0) // invalid input return; for(int i = 0; i < levelObjects.count(); i++) { if(levelObjects[i].value("type").toString().toLower().contains("wall")) { bool xSmaller = true; if(levelObjects[i].value("height").toInt() < levelObjects[i].value("width").toInt()) xSmaller = false; if(xSmaller) levelObjects[i].insert("width", QString::number(thickness)); else levelObjects[i].insert("height", QString::number(thickness)); } } updateGraphics(); updateObjectTable(ui->objectSelectorComboBox->currentIndex()); }
void MainWindow::rotationSliderMoved(int value) { int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1) // nothing selected return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); float rot = (value * 360.0 / 99); // dividing by 99 instead of 100 so that 360 can actually be reached int rotation = (int)rot / 5 * 5; // round to the nearest 5 levelObjects[objId].insert("rotation", QString::number(rotation)); updateGraphics(); noEmit = false; updateObjectTable(objId); }
void uoReportUndo::doTextChange(QString oldText, int row, int col) { if (!m_collectChanges) return; uoRUndo01* undo = new uoRUndo01(row, col, oldText); if (undo){ pushUndo(undo); } }
void MainWindow::newObjectClicked() { // Push an Undo object pushUndo(); levelObjects.append(QMap<QString, QVariant>()); updateGraphics(); updateObjectComboBox(); ui->objectSelectorComboBox->setCurrentIndex(levelObjects.count()-1); updateObjectTable(levelObjects.count() - 1); }
void MainWindow::deleteObjectClicked() { if(selectedObjects.count() == 0) // nothing selected return; // Push an Undo object pushUndo(); // Sort Selected Objects backwards so we can remove safely below (Whee, Bubblesort!) for(int i = 0; i < selectedObjects.count(); i++) { for(int j = i; j < selectedObjects.count(); j++) { if(selectedObjects[i] < selectedObjects[j]) { int temp = selectedObjects[i]; selectedObjects[i] = selectedObjects[j]; selectedObjects[j] = temp; } } } for(int i = 0; i < selectedObjects.count(); i++) { // This is safe because we just sorted :P levelObjects.removeAt(selectedObjects[i]); } selectedObjects.clear(); // Make sure we can't paste anything after this without re-copying copyObjects.clear(); if(noEmit) return; noEmit = true; updateGraphics(); updateObjectComboBox(); if(levelObjects.count() != 0) { ui->objectSelectorComboBox->setCurrentIndex(0); updateObjectTable(0); } else { clearObjectTable(); } noEmit = false; }
void uoReportUndo::doScaleResize(uoRptHeaderType hType, int nomRC, uorNumber oldSize) { if (!m_collectChanges) return; if (!m_doc) return; // uoRUndo02(int row_or_col, uoRptHeaderType hType, uorHeaderScaleChangeType chType) if (hType == uorRhtUnknown){ qWarning() << "bad perametere from uoReportUndo::doScaleResize"; return; } bool gropStarted = false; bool fixed; // строка фиксирована if (hType == uorRhtRowsHeader) { fixed = m_doc->getScaleFixedProp(hType, nomRC); if (!fixed){ gropStarted = true; } } if (gropStarted){ groupCommandStart(); uoRUndo02* undo2 = new uoRUndo02(nomRC, hType, uorHSCT_Fixed); if (undo2){ undo2->mu_fixed = fixed; pushUndo(undo2); } } uoRUndo02* undo = new uoRUndo02(nomRC, hType, uorHSCT_Size); if (undo){ undo->mu_size = oldSize; pushUndo(undo); } if (gropStarted){ groupCommandEnd(); } }
void MainWindow::addLevelPropertyClicked() { if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); levelPlist.insert("new_property", "null"); updateGraphics(); updateLevelPlistTable(); noEmit = false; }
void MainWindow::addPropertyClicked() { // Push an Undo object pushUndo(); int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1) // nothing selected return; levelObjects[objId].insert("new_property", "null"); updateGraphics(); updateObjectComboBox(); updateObjectTable(objId); }
void MainWindow::redoClicked() { if(!redoStack.isEmpty()) { UndoObject r = redoStack.pop(); // Push current state to undo stack pushUndo(false); // Restore state from undo object levelObjects = r.levelObjects; levelPlist = r.levelPlist; selectedObjects = r.selectedObjects; // Make sure we don't end up in an infinite loop noEmit = true; // Update stuff to reflect new state updateGraphics(); updateObjectComboBox(); updateLevelPlistTable(); if(selectedObjects.length() > 0) { ui->objectSelectorComboBox->setCurrentIndex(selectedObjects[0]); updateObjectTable(selectedObjects[0]); } else { ui->objectSelectorComboBox->setCurrentIndex(0); updateObjectTable(0); } noEmit = false; } else { QMessageBox msgBox; msgBox.setText("Nothing to redo!"); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); } }
void MainWindow::objectSelected(QString type, int id) { // Push Undo object pushUndo(); if(noEmit) return; noEmit = true; if(type == "object") { ui->objectSelectorComboBox->setCurrentIndex(id); updateObjectTable(id); } ui->levelPlistTableWidget->setCurrentCell(-1, -1); ui->objectsTableWidget->setCurrentCell(-1, -1); noEmit = false; //updateGraphics(); }
void MainWindow::objectChanged(QTableWidgetItem* newItem) { int column = ui->objectsTableWidget->currentColumn(); // Nothing selected, abort. if(column < 0) return; int row = ui->objectsTableWidget->currentRow(); int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1 || row == -1) // not initialized yet return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); // iterate to the changed row QMap<QString, QVariant>::const_iterator it = levelObjects[objId].constBegin(); for(int i = 0; i < row; i++) ++it; if(column == 1) { levelObjects[objId].insert(it.key(), newItem->text()); } else if(column == 0) { QString value = levelObjects[objId].value(it.key()).toString(); levelObjects[objId].remove(it.key()); levelObjects[objId].insert(newItem->text(), value); } updateGraphics(); updateObjectComboBox(); noEmit = false; }
void MainWindow::levelPlistChanged(QTableWidgetItem* newItem) { int column = ui->levelPlistTableWidget->currentColumn(); // Nothing selected, abort. if(column < 0) return; if(noEmit) return; noEmit = true; // Push an Undo object pushUndo(); int row = ui->levelPlistTableWidget->currentRow(); // iterate to the changed row QMap<QString, QVariant>::const_iterator it = levelPlist.constBegin(); for(int i = 0; i < row; i++) ++it; if(column == 1) { levelPlist.insert(it.key(), newItem->text()); } else if(column == 0) { QString value = levelPlist.value(it.key()).toString(); levelPlist.remove(it.key()); levelPlist.insert(newItem->text(), value); } updateGraphics(); updateLevelPlistTable(); noEmit = false; }
void MainWindow::deletePropertyClicked() { // Push an Undo object pushUndo(); int row = ui->objectsTableWidget->currentRow(); int objId = ui->objectSelectorComboBox->currentIndex(); if(objId == -1 || row == -1) // nothing selected return; // iterate to the deleted row QMap<QString, QVariant>::const_iterator it = levelObjects[objId].constBegin(); for(int i = 0; i < row; i++) ++it; levelObjects[objId].remove(it.key()); updateGraphics(); updateObjectComboBox(); updateObjectTable(objId); }
/** \brief Set's the name of the survey trip */ void cwTrip::setName(QString name) { if(name != Name && !name.isEmpty()) { pushUndo(new NameCommand(this, name)); } }
/** Sets the date of the trip */ void cwTrip::setDate(QDate date) { if(date != Date && !date.isNull()) { pushUndo(new DateCommand(this, date)); } }