void CSVWorld::CommandDelegate::setModelDataImp (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const { NastyTableModelHack hack (*model); QStyledItemDelegate::setModelData (editor, &hack, index); QVariant new_ = hack.getData(); if ((model->data (index)!=new_) && (model->flags(index) & Qt::ItemIsEditable)) getUndoStack().push (new CSMWorld::ModifyCommand (*model, index, new_)); }
void PanelWidget::pushUndoCommand(QUndoCommand* command) { boost::shared_ptr<QUndoStack> stack = getUndoStack(); if (stack) { stack->setActive(); stack->push(command); } else { //You are trying to push a command to a widget that do not own a stack! assert(false); } }
void CSVWorld::VarTypeDelegate::addCommands (QAbstractItemModel *model, const QModelIndex& index, int type) const { QModelIndex next = model->index (index.row(), index.column()+1); QVariant old = model->data (next); QVariant value; switch (type) { case ESM::VT_Short: case ESM::VT_Int: case ESM::VT_Long: value = old.toInt(); break; case ESM::VT_Float: value = old.toFloat(); break; case ESM::VT_String: value = old.toString(); break; default: break; // ignore the rest } getUndoStack().beginMacro ( "Modify " + model->headerData (index.column(), Qt::Horizontal, Qt::DisplayRole).toString()); getUndoStack().push (new CSMWorld::ModifyCommand (*model, index, type)); getUndoStack().push (new CSMWorld::ModifyCommand (*model, next, value)); getUndoStack().endMacro(); }
void TilePropertiesDialog::on_buttonBox_accepted() { int w = ui->spinBoxSizeX->value(); int h = ui->spinBoxSizeY->value(); int interleaved = ui->spinBoxInterleaved->value(); auto state = State::getInstance(); State::TileProperties properties; properties.size = {w,h}; properties.interleaved = interleaved; state->getUndoStack()->push(new SetTilePropertiesCommand(state, properties)); }
void UndoCommand::pushCommand( UndoCommand* a_pUndoCommand ) { o_assert(a_pUndoCommand->m_pParent == nullptr AND ( (getUndoStack() == nullptr) OR (m_eRedoChildExecutionPolicy < e_ChildExecutionPolicy_ForwardBeforeParent)) ); a_pUndoCommand->m_uiIndex = m_ChildCommands.size(); m_ChildCommands.push_back(a_pUndoCommand); a_pUndoCommand->m_pParent = this; if(m_pUndoStack) { a_pUndoCommand->setUndoStack(m_pUndoStack); } o_emit childCommandAdded(a_pUndoCommand); }
void UndoCommand::popCommand( UndoCommand* a_pUndoCommand ) { o_assert(a_pUndoCommand->m_pParent == this); o_assert(std::find(m_ChildCommands.begin(), m_ChildCommands.end(), a_pUndoCommand) != m_ChildCommands.end()); o_emit childCommandAboutToBeRemoved(a_pUndoCommand); if (getUndoStack()) a_pUndoCommand->undo(); m_ChildCommands.erase(std::find(m_ChildCommands.begin(), m_ChildCommands.end(), a_pUndoCommand)); a_pUndoCommand->m_pParent = nullptr; a_pUndoCommand->m_uiIndex = ~size_t(0); if(m_pUndoStack) { a_pUndoCommand->setUndoStack(nullptr); } }
bool PanelWidget::enterEventBase() { TabWidget* parentPane = getParentPane(); if (parentPane) { parentPane->setWidgetMouseOverFocus(this, true); } if ( _gui && _gui->isFocusStealingPossible() ) { _thisWidget->setFocus(); //Make this stack the active one boost::shared_ptr<QUndoStack> stack = getUndoStack(); if (stack) { stack->setActive(); } return true; } return false; }
void ParamItemModel::setDataNoUndo( const QModelIndex& index, const QVariant& newData, int role) { TreeNode* pNode = static_cast<TreeNode*>(index.internalPointer()); ParameterBaseData* pData = static_cast<ParameterBaseData*>(pNode->getData()); // Data given by the editor switch (role) { case Qt::EditRole: { switch (pData->getType()) { case ParameterBaseData::GROUP: case ParameterBaseData::PARAMETER: { ParameterData* pParameterData = static_cast<ParameterData*>(pData); const Parameter& newParameter = newData.value<Parameter>(); pParameterData->getParameter()->setValue(newParameter.getValue()); // Disable stack to avoid new undo commands QUndoStack* pStack = getUndoStack(); setUndoStack(NULL); emit dataChanged(index, index); setUndoStack(pStack); break; } default: { break; } } break; } } }
void PaletteWidget::mousePressEvent(QMouseEvent * event) { event->accept(); auto pos = event->localPos(); int x = pos.x() / PIXEL_SIZE_X; int y = pos.y() / PIXEL_SIZE_Y; int color = 8 * y + x; auto state = State::getInstance(); int pen = state->getSelectedPen(); int oldColor = state->getColorForPen(pen); if (oldColor != color) { state->getUndoStack()->push(new SetColorCommand(state, color, pen)); emit colorSelected(); update(); } }
void State::setColorForPen(int pen, int color, int tileIdx) { getUndoStack()->push(new SetColorCommand(this, color, pen, tileIdx)); }
void State::setForegroundColorMode(State::ForegroundColorMode mode) { getUndoStack()->push(new SetForegroundColorMode(this, mode)); }
void State::setMulticolorMode(bool enabled) { getUndoStack()->push(new SetMulticolorModeCommand(this, enabled)); }