diff --git a/ChangeLog.txt b/ChangeLog.txt index 4e5dda37b..05fd011eb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- New feature. Groups. - Tool "Curve intersect axis" store data about subpaths. - [#444] Length along Path seems not valid. - Added new curve path segment variables. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index b508af5f5..117787659 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -74,7 +74,7 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in switch."); switch (item->type()) { @@ -191,7 +191,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -323,7 +323,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in switch."); switch (currentItem->type()) { diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 5c5c462de..bddd259f3 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -208,7 +208,7 @@ void DialogHistory::FillTable() QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -383,6 +383,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodePoint: case Tool::NodeSpline: case Tool::NodeSplinePath: + case Tool::Group: return QString(); } } diff --git a/src/app/valentina/dialogs/dialogs.pri b/src/app/valentina/dialogs/dialogs.pri index f110de946..c5910f074 100644 --- a/src/app/valentina/dialogs/dialogs.pri +++ b/src/app/valentina/dialogs/dialogs.pri @@ -17,7 +17,8 @@ HEADERS += \ $$PWD/configpages/pathpage.h \ $$PWD/dialoglayoutsettings.h \ $$PWD/dialoglayoutprogress.h \ - $$PWD/dialogsavelayout.h + $$PWD/dialogsavelayout.h \ + $$PWD/vwidgetgroups.h SOURCES += \ $$PWD/dialogincrements.cpp \ @@ -33,7 +34,8 @@ SOURCES += \ $$PWD/configpages/pathpage.cpp \ $$PWD/dialoglayoutsettings.cpp \ $$PWD/dialoglayoutprogress.cpp \ - $$PWD/dialogsavelayout.cpp + $$PWD/dialogsavelayout.cpp \ + $$PWD/vwidgetgroups.cpp FORMS += \ $$PWD/dialogincrements.ui \ @@ -44,4 +46,5 @@ FORMS += \ $$PWD/dialogpatternxmledit.ui \ $$PWD/dialoglayoutsettings.ui \ $$PWD/dialoglayoutprogress.ui \ - $$PWD/dialogsavelayout.ui + $$PWD/dialogsavelayout.ui \ + $$PWD/vwidgetgroups.ui diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp new file mode 100644 index 000000000..abc3d34f0 --- /dev/null +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -0,0 +1,159 @@ +/************************************************************************ + ** + ** @file vwidgetgroups.cpp + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vwidgetgroups.h" +#include "ui_vwidgetgroups.h" +#include "../vtools/dialogs/tools/dialoggroup.h" +#include "../vtools/undocommands/delgroup.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VWidgetGroups::VWidgetGroups(VAbstractPattern *doc, QWidget *parent) + : QWidget(parent), + ui(new Ui::VWidgetGroups), + doc(doc) +{ + ui->setupUi(this); + + FillTable(doc->GetGroups()); + + ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(ui->tableWidget, &QTableWidget::cellClicked, this, &VWidgetGroups::GroupVisibilityChanged); + connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &VWidgetGroups::CtxMenu); +} + +//--------------------------------------------------------------------------------------------------------------------- +VWidgetGroups::~VWidgetGroups() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VWidgetGroups::GroupVisibilityChanged(int row, int column) +{ + if (column != 0) + { + return; + } + + QTableWidgetItem *item = ui->tableWidget->item(row, column); + const quint32 id = item->data(Qt::UserRole).toUInt(); + const bool visible = not doc->GetGroupVisivility(id); + doc->SetGroupVisivility(id, visible); + if (visible) + { + item->setIcon(QIcon("://icon/16x16/open_eye.png")); + } + else + { + item->setIcon(QIcon("://icon/16x16/closed_eye.png")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VWidgetGroups::CtxMenu(const QPoint &pos) +{ + QTableWidgetItem *item = ui->tableWidget->itemAt(pos); + if(not item) + { + return; + } + + const int row = item->row(); + item = ui->tableWidget->item(row, 0); + const quint32 id = item->data(Qt::UserRole).toUInt(); + + QMenu *menu = new QMenu; + QAction *actionRename = menu->addAction(tr("Rename")); + QAction *actionDelete = menu->addAction(tr("Delete")); + QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos)); + if (selectedAction == actionRename) + { + DialogGroup *dialog = new DialogGroup(new VContainer(qApp->TrVars(), qApp->patternUnitP()), NULL_ID, this); + dialog->SetName(doc->GetGroupName(id)); + const int result = dialog->exec(); + + if (result == QDialog::Accepted) + { + doc->SetGroupName(id, dialog->GetName()); + item = ui->tableWidget->item(row, 1); + item->setText(dialog->GetName()); + } + delete dialog; + } + else if (selectedAction == actionDelete) + { + DelGroup *delGroup = new DelGroup(doc, id); + connect(delGroup, &DelGroup::UpdateGroups, this, &VWidgetGroups::UpdateGroups); + qApp->getUndoStack()->push(delGroup); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VWidgetGroups::UpdateGroups() +{ + FillTable(doc->GetGroups()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VWidgetGroups::FillTable(const QMap > &groups) +{ + ui->tableWidget->clear(); + + ui->tableWidget->setColumnCount(2); + ui->tableWidget->setRowCount(groups.size()); + qint32 currentRow = -1; + auto i = groups.constBegin(); + while (i != groups.constEnd()) + { + ++currentRow; + const QPair data = i.value(); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setTextAlignment(Qt::AlignHCenter); + if (data.second) + { + item->setIcon(QIcon("://icon/16x16/open_eye.png")); + } + else + { + item->setIcon(QIcon("://icon/16x16/closed_eye.png")); + } + item->setData(Qt::UserRole, i.key()); + ui->tableWidget->setItem(currentRow, 0, item); + + item = new QTableWidgetItem(data.first); + item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + ui->tableWidget->setItem(currentRow, 1, item); + ++i; + } + ui->tableWidget->resizeColumnsToContents(); + ui->tableWidget->resizeRowsToContents(); +} diff --git a/src/app/valentina/dialogs/vwidgetgroups.h b/src/app/valentina/dialogs/vwidgetgroups.h new file mode 100644 index 000000000..5d46f7a57 --- /dev/null +++ b/src/app/valentina/dialogs/vwidgetgroups.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file vwidgetgroups.h + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VWIDGETGROUPS_H +#define VWIDGETGROUPS_H + +#include +#include "../ifc/xml/vabstractpattern.h" + +namespace Ui +{ + class VWidgetGroups; +} + +class VWidgetGroups : public QWidget +{ + Q_OBJECT + +public: + explicit VWidgetGroups(VAbstractPattern *doc, QWidget *parent = nullptr); + virtual ~VWidgetGroups(); + +public slots: + void UpdateGroups(); + +private slots: + void GroupVisibilityChanged(int row, int column); + void CtxMenu(const QPoint &pos); +private: + Q_DISABLE_COPY(VWidgetGroups) + Ui::VWidgetGroups *ui; + VAbstractPattern *doc; + + void FillTable(const QMap > &groups); +}; + +#endif // VWIDGETGROUPS_H diff --git a/src/app/valentina/dialogs/vwidgetgroups.ui b/src/app/valentina/dialogs/vwidgetgroups.ui new file mode 100644 index 000000000..3bd6c417e --- /dev/null +++ b/src/app/valentina/dialogs/vwidgetgroups.ui @@ -0,0 +1,58 @@ + + + VWidgetGroups + + + + 0 + 0 + 371 + 279 + + + + Form + + + + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + 16 + + + false + + + true + + + false + + + false + + + 10 + + + + + + + + diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 227ed6aab..4125aed5d 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -54,6 +54,8 @@ #include "tools/vtooldetail.h" #include "tools/vtooluniondetails.h" #include "dialogs/dialogs.h" +#include "dialogs/vwidgetgroups.h" +#include "../vtools/undocommands/addgroup.h" #include #include @@ -111,11 +113,16 @@ MainWindow::MainWindow(QWidget *parent) dialogTable(nullptr), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation), - currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs(), + currentDrawIndex(0), currentToolBoxIndex(0), + isDockToolOptionsVisible(true), + isDockGroupsVisible(true), + drawMode(true), recentFileActs(), separatorAct(nullptr), leftGoToStage(nullptr), rightGoToStage(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr), gradationSizes(nullptr), gradationHeightsLabel(nullptr), gradationSizesLabel(nullptr), - toolOptions(nullptr), lock(nullptr) + toolOptions(nullptr), + groupsWidget(nullptr), + lock(nullptr) { for (int i = 0; i < MaxRecentFiles; ++i) { @@ -150,7 +157,7 @@ MainWindow::MainWindow(QWidget *parent) ui->toolBox->setCurrentIndex(0); ReadSettings(); - PropertyBrowser(); + InitDocksContain(); setCurrentFile(""); WindowsLocale(); @@ -305,6 +312,7 @@ void MainWindow::InitScenes() connect(this, &MainWindow::EnableLabelSelection, sceneDraw, &VMainGraphicsScene::ToggleLabelSelection); connect(this, &MainWindow::EnablePointSelection, sceneDraw, &VMainGraphicsScene::TogglePointSelection); + connect(this, &MainWindow::EnableLineSelection, sceneDraw, &VMainGraphicsScene::ToggleLineSelection); connect(this, &MainWindow::EnableArcSelection, sceneDraw, &VMainGraphicsScene::ToggleArcSelection); connect(this, &MainWindow::EnableSplineSelection, sceneDraw, &VMainGraphicsScene::ToggleSplineSelection); connect(this, &MainWindow::EnableSplinePathSelection, sceneDraw, &VMainGraphicsScene::ToggleSplinePathSelection); @@ -551,6 +559,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons SCASSERT(scene != nullptr); connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); + connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool, &DialogTool::SelectedObject); connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); ui->view->itemClicked(nullptr); @@ -906,7 +915,7 @@ void MainWindow::ToolPointOfContact(bool checked) */ void MainWindow::ToolDetail(bool checked) { - ToolSelectAllObjects(); + ToolSelectAllDrawObjects(); SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", tr("Select points, arcs, curves clockwise."), &MainWindow::ClosedDialogDetail); } @@ -991,6 +1000,38 @@ void MainWindow::ClosedDialogUnionDetails(int result) doc->LiteParseTree(Document::LiteParse); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolGroup(bool checked) +{ + ToolSelectGroupObjects(); + currentScene->clearSelection(); + SetToolButton(checked, Tool::Group, ":/cursor/group_plus_cursor.png", + tr("Select one or more objects, Enter - finish creation"), + &MainWindow::ClosedDialogGroup); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ClosedDialogGroup(int result) +{ + SCASSERT(dialogTool != nullptr); + if (result == QDialog::Accepted) + { + VMainGraphicsScene *scene = qobject_cast(currentScene); + SCASSERT(scene != nullptr); + + DialogGroup *dialog = qobject_cast(dialogTool); + SCASSERT(dialog != nullptr); + const QDomElement group = doc->CreateGroup(pattern->getNextId(), dialog->GetName(), dialog->GetGroup()); + if (not group.isNull()) + { + AddGroup *addGroup = new AddGroup(group, doc); + connect(addGroup, &AddGroup::UpdateGroups, groupsWidget, &VWidgetGroups::UpdateGroups); + qApp->getUndoStack()->push(addGroup); + } + } + ArrowTool(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolCutArc handler tool cutArc. @@ -1018,7 +1059,7 @@ void MainWindow::ToolLineIntersectAxis(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolCurveIntersectAxis(bool checked) { - ToolSelectAllObjects(); + ToolSelectAllDrawObjects(); SetToolButtonWithApply(checked, Tool::CurveIntersectAxis, ":/cursor/curve_intersect_axis_cursor.png", tr("Select curve"), @@ -1029,7 +1070,7 @@ void MainWindow::ToolCurveIntersectAxis(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolArcIntersectAxis(bool checked) { - ToolSelectAllObjects(); + ToolSelectAllDrawObjects(); // Reuse ToolCurveIntersectAxis but with different cursor and tool tip SetToolButtonWithApply(checked, Tool::CurveIntersectAxis, ":/cursor/arc_intersect_axis_cursor.png", @@ -1698,7 +1739,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonPointFromArcAndTangent, &QToolButton::clicked, this, &MainWindow::ToolPointFromArcAndTangent); connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength); connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); - + connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); } //--------------------------------------------------------------------------------------------------------------------- @@ -1739,7 +1780,7 @@ void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::CancelTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1863,6 +1904,9 @@ void MainWindow::CancelTool() case Tool::TrueDarts: ui->toolButtonTrueDarts->setChecked(false); break; + case Tool::Group: + ui->toolButtonGroup->setChecked(false); + break; } currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1895,6 +1939,7 @@ void MainWindow::ArrowTool() // Only true for rubber band selection emit EnableLabelSelection(true); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -2025,7 +2070,8 @@ void MainWindow::ActionDraw(bool checked) } ui->dockWidgetLayoutPages->setVisible(false); - ui->dockWidgetToolOptions->setVisible(true); + ui->dockWidgetToolOptions->setVisible(isDockToolOptionsVisible); + ui->dockWidgetGroups->setVisible(isDockGroupsVisible); } else { @@ -2086,7 +2132,7 @@ void MainWindow::ActionDetails(bool checked) mode = Draw::Modeling; SetEnableTool(true); SetEnableWidgets(true); - ui->toolBox->setCurrentIndex(4); + ui->toolBox->setCurrentIndex(5); if (qApp->patternType() == MeasurementsType::Standard) { @@ -2094,7 +2140,8 @@ void MainWindow::ActionDetails(bool checked) } ui->dockWidgetLayoutPages->setVisible(false); - ui->dockWidgetToolOptions->setVisible(true); + ui->dockWidgetToolOptions->setVisible(isDockToolOptionsVisible); + ui->dockWidgetGroups->setVisible(isDockGroupsVisible); helpLabel->setText(""); } @@ -2161,7 +2208,7 @@ void MainWindow::ActionLayout(bool checked) mode = Draw::Layout; SetEnableTool(true); SetEnableWidgets(true); - ui->toolBox->setCurrentIndex(5); + ui->toolBox->setCurrentIndex(6); mouseCoordinate->setText(""); @@ -2171,7 +2218,14 @@ void MainWindow::ActionLayout(bool checked) } ui->dockWidgetLayoutPages->setVisible(true); + + ui->dockWidgetToolOptions->blockSignals(true); ui->dockWidgetToolOptions->setVisible(false); + ui->dockWidgetToolOptions->blockSignals(false); + + ui->dockWidgetGroups->blockSignals(true); + ui->dockWidgetGroups->setVisible(false); + ui->dockWidgetGroups->blockSignals(false); ShowPaper(ui->listWidget->currentRow()); @@ -2668,6 +2722,7 @@ void MainWindow::SetEnableWidgets(bool enable) ui->actionUnloadMeasurements->setEnabled(enable && designStage); actionDockWidgetToolOptions->setEnabled(enable && designStage); + actionDockWidgetGroups->setEnabled(enable && designStage); undoAction->setEnabled(enable && designStage && qApp->getUndoStack()->canUndo()); redoAction->setEnabled(enable && designStage && qApp->getUndoStack()->canRedo()); @@ -2875,6 +2930,18 @@ void MainWindow::ChangedHeight(const QString &text) } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::DockToolOptionsVisibilityChanged(bool visible) +{ + isDockToolOptionsVisible = visible; +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::DockGropsVisibilityChanged(bool visible) +{ + isDockGroupsVisible = visible; +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetDefaultHeight() { @@ -3042,6 +3109,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonPointFromArcAndTangent->setEnabled(drawTools); ui->toolButtonArcWithLength->setEnabled(drawTools); ui->toolButtonTrueDarts->setEnabled(drawTools); + ui->toolButtonGroup->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3192,6 +3260,9 @@ void MainWindow::ReadSettings() // Text under tool buton icon ToolBarStyles(); + + isDockToolOptionsVisible = ui->dockWidgetToolOptions->isVisible(); + isDockGroupsVisible = ui->dockWidgetGroups->isVisible(); } //--------------------------------------------------------------------------------------------------------------------- @@ -3298,13 +3369,6 @@ void MainWindow::CreateMenus() separatorAct->setSeparator(true); ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct); - //Add dock - actionDockWidgetToolOptions = ui->dockWidgetToolOptions->toggleViewAction(); - ui->menuPatternPiece->insertAction(ui->actionPattern_properties, actionDockWidgetToolOptions); - - separatorAct = new QAction(this); - separatorAct->setSeparator(true); - ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct); AddDocks(); } @@ -3316,7 +3380,7 @@ void MainWindow::CreateMenus() void MainWindow::LastUsedTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3463,6 +3527,10 @@ void MainWindow::LastUsedTool() ui->toolButtonTrueDarts->setChecked(true); ToolTrueDarts(true); break; + case Tool::Group: + ui->toolButtonGroup->setChecked(true); + ToolGroup(true); + break; } } @@ -3473,7 +3541,15 @@ void MainWindow::LastUsedTool() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::AddDocks() { - ui->menuPatternPiece->insertAction(ui->actionPattern_properties, ui->dockWidgetToolOptions->toggleViewAction()); + //Add dock + actionDockWidgetToolOptions = ui->dockWidgetToolOptions->toggleViewAction(); + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, actionDockWidgetToolOptions); + connect(ui->dockWidgetToolOptions, &QDockWidget::visibilityChanged, this, + &MainWindow::DockToolOptionsVisibilityChanged); + + actionDockWidgetGroups = ui->dockWidgetGroups->toggleViewAction(); + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, actionDockWidgetGroups); + connect(ui->dockWidgetGroups, &QDockWidget::visibilityChanged, this, &MainWindow::DockGropsVisibilityChanged); separatorAct = new QAction(this); separatorAct->setSeparator(true); @@ -3481,13 +3557,17 @@ void MainWindow::AddDocks() } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::PropertyBrowser() +void MainWindow::InitDocksContain() { qCDebug(vMainWindow, "Initialization property browser."); toolOptions = new VToolOptionsPropertyBrowser(ui->dockWidgetToolOptions); connect(ui->view, &VMainGraphicsView::itemClicked, toolOptions, &VToolOptionsPropertyBrowser::itemClicked); connect(doc, &VPattern::FullUpdateFromFile, toolOptions, &VToolOptionsPropertyBrowser::UpdateOptions); + + qCDebug(vMainWindow, "Initialization groups dock."); + groupsWidget = new VWidgetGroups(doc, this); + ui->dockWidgetGroups->setWidget(groupsWidget); } //--------------------------------------------------------------------------------------------------------------------- @@ -4070,6 +4150,7 @@ void MainWindow::ChangePP(int index, bool zoomBestFit) } } toolOptions->itemClicked(nullptr);//hide options for tool in previous pattern piece + groupsWidget->UpdateGroups(); } } @@ -4459,6 +4540,7 @@ void MainWindow::ToolSelectPoint() const // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4494,6 +4576,7 @@ void MainWindow::ToolSelectSpline() const // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4517,6 +4600,7 @@ void MainWindow::ToolSelectSplinePath() const // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4540,6 +4624,7 @@ void MainWindow::ToolSelectArc() const // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4563,6 +4648,7 @@ void MainWindow::ToolSelectPointArc() const // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4586,6 +4672,7 @@ void MainWindow::ToolSelectCurve() const // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4604,11 +4691,12 @@ void MainWindow::ToolSelectCurve() const } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::ToolSelectAllObjects() const +void MainWindow::ToolSelectAllDrawObjects() const { // Only true for rubber band selection emit EnableLabelSelection(false); emit EnablePointSelection(false); + emit EnableLineSelection(false); emit EnableArcSelection(false); emit EnableSplineSelection(false); emit EnableSplinePathSelection(false); @@ -4626,6 +4714,30 @@ void MainWindow::ToolSelectAllObjects() const ui->view->AllowRubberBand(false); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolSelectGroupObjects() const +{ + // Only true for rubber band selection + emit EnableLabelSelection(true); + emit EnablePointSelection(true); + emit EnableLineSelection(true); + emit EnableArcSelection(true); + emit EnableSplineSelection(true); + emit EnableSplinePathSelection(true); + + // Hovering + emit EnableLabelHover(true); + emit EnablePointHover(true); + emit EnableLineHover(true); + emit EnableArcHover(true); + emit EnableSplineHover(true); + emit EnableSplinePathHover(true); + + emit ItemsSelection(SelectionType::ByMouseRelease); + + ui->view->AllowRubberBand(true); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolSelectDetail() const { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index f241b3526..98b383942 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -48,6 +48,7 @@ class QLabel; class DialogIncrements; class DialogTool; class DialogHistory; +class VWidgetGroups; /** * @brief The MainWindow class main windows. @@ -120,6 +121,7 @@ public slots: void ToolTriangle(bool checked); void ToolPointOfIntersection(bool checked); void ToolUnionDetails(bool checked); + void ToolGroup(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); @@ -134,6 +136,7 @@ public slots: void ClosedDialogDetail(int result); void ClosedDialogUnionDetails(int result); + void ClosedDialogGroup(int result); //tmp void LastUsedTool(); @@ -161,6 +164,7 @@ signals: void EnableLabelSelection(bool enable) const; void EnablePointSelection(bool enable) const; + void EnableLineSelection(bool enable) const; void EnableArcSelection(bool enable) const; void EnableSplineSelection(bool enable) const; void EnableSplinePathSelection(bool enable) const; @@ -201,6 +205,9 @@ private slots: void ChangedSize(const QString &text); void ChangedHeight(const QString & text); + void DockToolOptionsVisibilityChanged(bool visible); + void DockGropsVisibilityChanged(bool visible); + private: Q_DISABLE_COPY(MainWindow) /** @brief ui keeps information about user interface */ @@ -252,6 +259,9 @@ private: /** @brief currentToolBoxIndex save current set of tools. */ qint32 currentToolBoxIndex; + bool isDockToolOptionsVisible; + bool isDockGroupsVisible; + /** @brief drawMode true if we current draw scene. */ bool drawMode; @@ -267,6 +277,7 @@ private: QPointer gradationHeightsLabel; QPointer gradationSizesLabel; VToolOptionsPropertyBrowser *toolOptions; + VWidgetGroups *groupsWidget; std::shared_ptr> lock; void SetDefaultHeight(); @@ -324,7 +335,7 @@ private: void UpdateSizesList(const QStringList &list); void AddDocks(); - void PropertyBrowser(); + void InitDocksContain(); bool OpenNewValentina(const QString &fileName = QString())const; void FileClosedCorrect(); QStringList GetUnlokedRestoreFileList()const; @@ -360,7 +371,8 @@ private: void ToolSelectArc() const; void ToolSelectPointArc() const; void ToolSelectCurve() const; - void ToolSelectAllObjects() const; + void ToolSelectAllDrawObjects() const; + void ToolSelectGroupObjects() const; void ToolSelectDetail() const; }; diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 90c9bb8a7..51eb11f32 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,14 +48,14 @@ Tools - 2 + 4 0 0 - 100 + 130 318 @@ -375,7 +375,7 @@ 0 0 - 100 + 130 58 @@ -700,7 +700,7 @@ 0 0 - 100 + 130 196 @@ -937,12 +937,60 @@ + + + + 0 + 0 + 130 + 356 + + + + + :/icon/16x16/operations.png:/icon/16x16/operations.png + + + Operations + + + Operations + + + + + + false + + + Create new group + + + ... + + + + :/toolicon/32x32/group_plus.png:/toolicon/32x32/group_plus.png + + + + 32 + 32 + + + + true + + + + + 0 0 - 100 + 130 58 @@ -1028,8 +1076,8 @@ 0 0 - 87 - 58 + 130 + 356 @@ -1415,6 +1463,18 @@ + + + true + + + Groups + + + 2 + + + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index e5137b537..2cbf03c0f 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -60,7 +60,8 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList()), shadows(QList()), scenes(QList()), details(QList >()), - undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), + undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), actionDockWidgetGroups(nullptr), + curFile(QString()), isLayoutStale(true), margins(), paperSize(), isTiled(false) { InitTempLayoutScene(); diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 1cb1d1926..f4aea3bb0 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -83,6 +83,7 @@ protected: QAction *undoAction; QAction *redoAction; QAction *actionDockWidgetToolOptions; + QAction *actionDockWidgetGroups; /** @brief fileName name current pattern file. */ QString curFile; diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index a52e2b468..1063918f4 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -64,5 +64,7 @@ cursor/cubic_bezier_cursor@2x.png cursor/cubic_bezier_path_cursor.png cursor/cubic_bezier_path_cursor@2x.png + cursor/group_plus_cursor.png + cursor/group_plus_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/group_plus_cursor.png b/src/app/valentina/share/resources/cursor/group_plus_cursor.png new file mode 100644 index 000000000..e1b00a753 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/group_plus_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/group_plus_cursor@2x.png b/src/app/valentina/share/resources/cursor/group_plus_cursor@2x.png new file mode 100644 index 000000000..8b34beca8 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/group_plus_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 772aa06a7..8b5d0bec5 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -62,5 +62,7 @@ toolicon/32x32/cubic_bezier@2x.png toolicon/32x32/cubic_bezier_path.png toolicon/32x32/cubic_bezier_path@2x.png + toolicon/32x32/group_plus.png + toolicon/32x32/group_plus@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/group_plus.png b/src/app/valentina/share/resources/toolicon/32x32/group_plus.png new file mode 100644 index 000000000..4b00755f0 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/group_plus.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/group_plus@2x.png b/src/app/valentina/share/resources/toolicon/32x32/group_plus@2x.png new file mode 100644 index 000000000..7b9c63a74 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/group_plus@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/group_plus.svg b/src/app/valentina/share/resources/toolicon/svg/group_plus.svg new file mode 100644 index 000000000..92243882d --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/group_plus.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 5a949d7be..31c89cbf0 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -469,7 +469,7 @@ void VPattern::customEvent(QEvent *event) */ void VPattern::ParseDrawElement(const QDomNode &node, const Document &parse) { - QStringList tags = QStringList() << TagCalculation << TagModeling << TagDetails; + QStringList tags = QStringList() << TagCalculation << TagModeling << TagDetails << TagGroups; QDomNode domNode = node.firstChild(); while (domNode.isNull() == false) { @@ -493,6 +493,10 @@ void VPattern::ParseDrawElement(const QDomNode &node, const Document &parse) qCDebug(vXML, "Tag details."); ParseDetails(domElement, parse); break; + case 3: // TagGroups + qCDebug(vXML, "Tag groups."); + ParseGroups(domElement); + break; default: VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName())); throw e; @@ -2885,7 +2889,7 @@ bool VPattern::IsDefCustom() const const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - return GetParametrBool(domElement, AttrCustom, QStringLiteral("false")); + return GetParametrBool(domElement, AttrCustom, falseStr); } else { @@ -3054,7 +3058,7 @@ bool VPattern::IsReadOnly() const return false; } - return GetParametrBool(pattern, AttrReadOnly, QStringLiteral("false")); + return GetParametrBool(pattern, AttrReadOnly, falseStr); } //--------------------------------------------------------------------------------------------------------------------- @@ -3126,7 +3130,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id) QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used."); QRectF rec; @@ -3240,6 +3244,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::NodePoint: case Tool::NodeSpline: case Tool::NodeSplinePath: + case Tool::Group: break; } } diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index c65ccb6d1..92c57cd13 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -112,9 +112,9 @@ private: void ParseDrawElement(const QDomNode& node, const Document &parse); void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); - void ParseDetailElement(const QDomElement &domElement, - const Document &parse); + void ParseDetailElement(const QDomElement &domElement, const Document &parse); void ParseDetails(const QDomElement &domElement, const Document &parse); + void ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse, const QString &type); void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 1fe74a4c7..d8aa89e47 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -13,6 +13,7 @@ schema/pattern/v0.2.5.xsd schema/pattern/v0.2.6.xsd schema/pattern/v0.2.7.xsd + schema/pattern/v0.3.0.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.3.0.xsd b/src/libs/ifc/schema/pattern/v0.3.0.xsd new file mode 100644 index 000000000..b868553f3 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.0.xsd @@ -0,0 +1,480 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 2a5a0579b..ca528a4ab 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -31,6 +31,8 @@ #include "exception/vexceptionemptyparameter.h" #include "vpatternconverter.h" #include "../qmuparser/qmutokenparser.h" +#include "../exception/vexceptionobjecterror.h" +#include "../vtools/tools/vdatatool.h" const QString VAbstractPattern::TagPattern = QStringLiteral("pattern"); const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation"); @@ -44,6 +46,9 @@ const QString VAbstractPattern::TagMeasurements = QStringLiteral("measurements") const QString VAbstractPattern::TagIncrements = QStringLiteral("increments"); const QString VAbstractPattern::TagIncrement = QStringLiteral("increment"); const QString VAbstractPattern::TagDraw = QStringLiteral("draw"); +const QString VAbstractPattern::TagGroups = QStringLiteral("groups"); +const QString VAbstractPattern::TagGroup = QStringLiteral("group"); +const QString VAbstractPattern::TagGroupItem = QStringLiteral("item"); const QString VAbstractPattern::TagPoint = QStringLiteral("point"); const QString VAbstractPattern::TagLine = QStringLiteral("line"); const QString VAbstractPattern::TagSpline = QStringLiteral("spline"); @@ -55,6 +60,9 @@ const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); +const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); +const QString VAbstractPattern::AttrObject = QStringLiteral("object"); +const QString VAbstractPattern::AttrTool = QStringLiteral("tool"); const QString VAbstractPattern::AttrType = QStringLiteral("type"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); @@ -289,6 +297,56 @@ bool VAbstractPattern::GetActivNodeElement(const QString &name, QDomElement &ele return false; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::ParseGroups(const QDomElement &domElement) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + QMap itemTool; + QMap itemVisibility; + + QDomNode domNode = domElement.firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + if (domElement.tagName() == TagGroup) + { + const QPair > groupData = ParseItemElement(domElement); + const QMap group = groupData.second; + auto i = group.constBegin(); + while (i != group.constEnd()) + { + if (not itemTool.contains(i.key())) + { + itemTool.insert(i.key(), i.value()); + } + + const bool previous = itemVisibility.value(i.key(), false); + itemVisibility.insert(i.key(), previous || groupData.first); + ++i; + } + } + } + } + domNode = domNode.nextSibling(); + } + + auto i = itemTool.constBegin(); + while (i != itemTool.constEnd()) + { + if (tools.contains(i.value())) + { + VDataTool* tool = tools.value(i.value()); + tool->GroupVisibility(i.key(), itemVisibility.value(i.key(), true)); + } + ++i; + } +} + //--------------------------------------------------------------------------------------------------------------------- int VAbstractPattern::CountPP() const { @@ -595,7 +653,7 @@ QMap VAbstractPattern::GetGradationHeights() const const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - const QString defValue = QStringLiteral("true"); + const QString defValue = trueStr; switch (gTags.indexOf(domElement.tagName())) { case 0: // TagHeights @@ -761,7 +819,7 @@ QMap VAbstractPattern::GetGradationSizes() const const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - const QString defValue = QStringLiteral("true"); + const QString defValue = trueStr; switch (gTags.indexOf(domElement.tagName())) { case 0: // TagHeights @@ -1375,6 +1433,44 @@ bool VAbstractPattern::IsFunction(const QString &token) const return false; } +//--------------------------------------------------------------------------------------------------------------------- +QPair > VAbstractPattern::ParseItemElement(const QDomElement &domElement) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + const bool visible = GetParametrBool(domElement, AttrVisible, trueStr); + + QMap items; + + const QDomNodeList nodeList = domElement.childNodes(); + const qint32 num = nodeList.size(); + for (qint32 i = 0; i < num; ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (not element.isNull() && element.tagName() == TagGroupItem) + { + const quint32 object = GetParametrUInt(element, AttrObject, NULL_ID_STR); + const quint32 tool = GetParametrUInt(element, AttrTool, NULL_ID_STR); + items.insert(object, tool); + } + } + + QPair > group; + group.first = visible; + group.second = items; + + return group; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating group"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief IsModified state of the document for cases that do not cover QUndoStack. @@ -1410,3 +1506,187 @@ QDomElement VAbstractPattern::GetDraw(const QString &name) const } return QDomElement(); } + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VAbstractPattern::CreateGroups() +{ + QDomElement draw; + if (GetActivDrawElement(draw)) + { + QDomElement groups = draw.firstChildElement(TagGroups); + + if (groups.isNull()) + { + groups = createElement(TagGroups); + draw.appendChild(groups); + } + + return groups; + } + return QDomElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VAbstractPattern::CreateGroup(quint32 id, const QString &name, const QMap &groupData) +{ + if (id == NULL_ID || groupData.isEmpty()) + { + return QDomElement(); + } + + QDomElement group = createElement(TagGroup); + SetAttribute(group, AttrId, id); + SetAttribute(group, AttrName, name); + SetAttribute(group, AttrVisible, true); + + auto i = groupData.constBegin(); + while (i != groupData.constEnd()) + { + QDomElement item = createElement(TagGroupItem); + item.setAttribute(AttrObject, i.key()); + item.setAttribute(AttrTool, i.value()); + group.appendChild(item); + ++i; + } + + return group; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetGroupName(quint32 id) +{ + QString name = tr("New group"); + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = elementById(id); + if (group.isElement()) + { + name = GetParametrString(group, AttrName, name); + return name; + } + else + { + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + + qDebug("Can't get group by id = %u.", id); + return name; + } + } + else + { + qDebug("Can't get tag Groups."); + return name; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetGroupName(quint32 id, const QString &name) +{ + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = elementById(id); + if (group.isElement()) + { + group.setAttribute(AttrName, name); + modified = true; + emit patternChanged(false); + } + else + { + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + + qDebug("Can't get group by id = %u.", id); + return; + } + } + else + { + qDebug("Can't get tag Groups."); + return; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap > VAbstractPattern::GetGroups() +{ + QMap > data; + + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + QDomNode domNode = groups.firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement group = domNode.toElement(); + if (group.isNull() == false) + { + if (group.tagName() == TagGroup) + { + const quint32 id = GetParametrUInt(group, AttrId, "0"); + const bool visible = GetParametrBool(group, AttrVisible, trueStr); + const QString name = GetParametrString(group, AttrName, tr("New group")); + + data.insert(id, qMakePair(name, visible)); + } + } + } + domNode = domNode.nextSibling(); + } + } + else + { + qDebug("Can't get tag Groups."); + } + + return data; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractPattern::GetGroupVisivility(quint32 id) +{ + QDomElement group = elementById(id); + if (group.isElement()) + { + return GetParametrBool(group, AttrVisible, trueStr); + } + else + { + qDebug("Can't get group by id = %u.", id); + return true; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetGroupVisivility(quint32 id, bool visible) +{ + QDomElement group = elementById(id); + if (group.isElement()) + { + SetAttribute(group, AttrVisible, visible); + modified = true; + emit patternChanged(false); + + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + ParseGroups(groups); + } + } + else + { + qDebug("Can't get group by id = %u.", id); + return; + } +} diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index a48dd24bf..8524b4f9f 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -119,6 +119,15 @@ public: QDomElement GetDraw(const QString &name) const; + void ParseGroups(const QDomElement &domElement); + QDomElement CreateGroups(); + QDomElement CreateGroup(quint32 id, const QString &name, const QMap &groupData); + QString GetGroupName(quint32 id); + void SetGroupName(quint32 id, const QString &name); + QMap > GetGroups(); + bool GetGroupVisivility(quint32 id); + void SetGroupVisivility(quint32 id, bool visible); + static const QString TagPattern; static const QString TagCalculation; static const QString TagModeling; @@ -131,6 +140,9 @@ public: static const QString TagIncrements; static const QString TagIncrement; static const QString TagDraw; + static const QString TagGroups; + static const QString TagGroup; + static const QString TagGroupItem; static const QString TagPoint; static const QString TagLine; static const QString TagSpline; @@ -142,6 +154,9 @@ public: static const QString TagUnit; static const QString AttrName; + static const QString AttrVisible; + static const QString AttrObject; + static const QString AttrTool; static const QString AttrType; static const QString AttrAll; @@ -281,6 +296,8 @@ private: bool IsVariable(const QString& token) const; bool IsPostfixOperator(const QString& token) const; bool IsFunction(const QString& token) const; + + QPair > ParseItemElement(const QDomElement &domElement); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index c7a9ee5a1..0a44f9841 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -255,7 +255,7 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString //--------------------------------------------------------------------------------------------------------------------- NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name) const { - const bool value = GetParametrBool(domElement, name, QStringLiteral("true")); + const bool value = GetParametrBool(domElement, name, trueStr); if (value) { return NodeUsage::InUse; @@ -271,11 +271,11 @@ void VDomDocument::SetParametrUsage(QDomElement &domElement, const QString &name { if (value == NodeUsage::InUse) { - domElement.setAttribute(name, QStringLiteral("true")); + domElement.setAttribute(name, trueStr); } else { - domElement.setAttribute(name, QStringLiteral("false")); + domElement.setAttribute(name, falseStr); } } diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index f725d1d65..46e09ae74 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -43,8 +43,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.7"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.7.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.0"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.0.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -111,6 +111,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000206): return QStringLiteral("://schema/pattern/v0.2.6.xsd"); case (0x000207): + return QStringLiteral("://schema/pattern/v0.3.0.xsd"); + case (0x000300): return CurrentSchema; default: InvalidVersion(ver); @@ -210,6 +212,13 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000207): + { + ToV0_3_0(); + const QString schema = XSDSchema(0x000300); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000300): break; default: break; @@ -331,6 +340,13 @@ void VPatternConverter::ToV0_2_7() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_0() +{ + SetVersion(QStringLiteral("0.3.0")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index d1a0be553..1a4de28d8 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -68,6 +68,7 @@ private: void ToV0_2_5(); void ToV0_2_6(); void ToV0_2_7(); + void ToV0_3_0(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 3995185dd..e94baca4f 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -408,6 +408,8 @@ const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-clos // From documantation: If you use QStringLiteral you should avoid declaring the same literal in multiple places: This // furthermore blows up the binary sizes. const QString degreeSymbol = QStringLiteral("°"); +const QString trueStr = QStringLiteral("true"); +const QString falseStr = QStringLiteral("false"); //--------------------------------------------------------------------------------------------------------------------- void SetOverrideCursor(const QString &pixmapPath, int hotX, int hotY) diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 6987cc452..521492ba6 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -101,6 +101,7 @@ enum class Tool : ToolVisHolderType PointFromArcAndTangent, TrueDarts, UnionDetails, + Group, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -583,6 +584,8 @@ extern const QString cursorArrowOpenHand; extern const QString cursorArrowCloseHand; extern const QString degreeSymbol; +extern const QString trueStr; +extern const QString falseStr; void SetOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); void RestoreOverrideCursor(const QString & pixmapPath); diff --git a/src/libs/vmisc/share/resources/icon.qrc b/src/libs/vmisc/share/resources/icon.qrc index ed0dec1b4..8abf44308 100644 --- a/src/libs/vmisc/share/resources/icon.qrc +++ b/src/libs/vmisc/share/resources/icon.qrc @@ -55,5 +55,11 @@ icon/16x16/toolsectioncurve@2x.png icon/16x16/toolsectionline@2x.png icon/16x16/toolsectionpoint@2x.png + icon/16x16/operations.png + icon/16x16/operations@2x.png + icon/16x16/closed_eye.png + icon/16x16/closed_eye@2x.png + icon/16x16/open_eye.png + icon/16x16/open_eye@2x.png diff --git a/src/libs/vmisc/share/resources/icon/16x16/closed_eye.png b/src/libs/vmisc/share/resources/icon/16x16/closed_eye.png new file mode 100644 index 000000000..dc1142f4a Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/16x16/closed_eye.png differ diff --git a/src/libs/vmisc/share/resources/icon/16x16/closed_eye@2x.png b/src/libs/vmisc/share/resources/icon/16x16/closed_eye@2x.png new file mode 100644 index 000000000..3c702063a Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/16x16/closed_eye@2x.png differ diff --git a/src/libs/vmisc/share/resources/icon/16x16/open_eye.png b/src/libs/vmisc/share/resources/icon/16x16/open_eye.png new file mode 100644 index 000000000..14de6f961 Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/16x16/open_eye.png differ diff --git a/src/libs/vmisc/share/resources/icon/16x16/open_eye@2x.png b/src/libs/vmisc/share/resources/icon/16x16/open_eye@2x.png new file mode 100644 index 000000000..f0d6474ad Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/16x16/open_eye@2x.png differ diff --git a/src/libs/vmisc/share/resources/icon/16x16/operations.png b/src/libs/vmisc/share/resources/icon/16x16/operations.png new file mode 100644 index 000000000..76e5e17fe Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/16x16/operations.png differ diff --git a/src/libs/vmisc/share/resources/icon/16x16/operations@2x.png b/src/libs/vmisc/share/resources/icon/16x16/operations@2x.png new file mode 100644 index 000000000..a8becf80c Binary files /dev/null and b/src/libs/vmisc/share/resources/icon/16x16/operations@2x.png differ diff --git a/src/libs/vmisc/share/resources/icon/svg/closed_eye.svg b/src/libs/vmisc/share/resources/icon/svg/closed_eye.svg new file mode 100644 index 000000000..c22134f20 --- /dev/null +++ b/src/libs/vmisc/share/resources/icon/svg/closed_eye.svg @@ -0,0 +1,99 @@ + + + + + + image/svg+xml + + Closed Eye + + + + + + Closed Eye + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + + + + + + + + diff --git a/src/libs/vmisc/share/resources/icon/svg/open_eye.svg b/src/libs/vmisc/share/resources/icon/svg/open_eye.svg new file mode 100644 index 000000000..11b37c377 --- /dev/null +++ b/src/libs/vmisc/share/resources/icon/svg/open_eye.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index fd77d2ce3..26bcfaad6 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -36,7 +36,8 @@ HEADERS += \ $$PWD/tools/dialogtruedarts.h \ $$PWD/tools/dialogpointofintersectioncurves.h \ $$PWD/tools/dialogcubicbezier.h \ - $$PWD/tools/dialogcubicbezierpath.h + $$PWD/tools/dialogcubicbezierpath.h \ + $$PWD/tools/dialoggroup.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -72,7 +73,8 @@ SOURCES += \ $$PWD/tools/dialogtruedarts.cpp \ $$PWD/tools/dialogpointofintersectioncurves.cpp \ $$PWD/tools/dialogcubicbezier.cpp \ - $$PWD/tools/dialogcubicbezierpath.cpp + $$PWD/tools/dialogcubicbezierpath.cpp \ + $$PWD/tools/dialoggroup.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -107,4 +109,5 @@ FORMS += \ $$PWD/tools/dialogtruedarts.ui \ $$PWD/tools/dialogpointofintersectioncurves.ui \ $$PWD/tools/dialogcubicbezier.ui \ - $$PWD/tools/dialogcubicbezierpath.ui + $$PWD/tools/dialogcubicbezierpath.ui \ + $$PWD/tools/dialoggroup.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index 08326cce0..b9ac6d496 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -60,6 +60,7 @@ #include "dialogs/tools/dialogpointfromcircleandtangent.h" #include "dialogs/tools/dialogpointfromarcandtangent.h" #include "dialogs/tools/dialogtruedarts.h" +#include "dialogs/tools/dialoggroup.h" #include "dialogs/support/dialogeditwrongformula.h" #include "dialogs/support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialoggroup.cpp b/src/libs/vtools/dialogs/tools/dialoggroup.cpp new file mode 100644 index 000000000..d9e64ef23 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialoggroup.cpp @@ -0,0 +1,106 @@ +/************************************************************************ + ** + ** @file dialoggroup.cpp + ** @author Roman Telezhynskyi + ** @date 4 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialoggroup.h" +#include "ui_dialoggroup.h" +#include "../vtools/tools/drawTools/drawtools.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogGroup::DialogGroup(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogGroup), + group() +{ + ui->setupUi(this); + InitOkCancel(ui); + CheckState(); + + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogGroup::NameChanged); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogGroup::~DialogGroup() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogGroup::SetName(const QString &name) +{ + ui->lineEditName->setText(name); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogGroup::GetName() const +{ + return ui->lineEditName->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogGroup::ShowDialog(bool click) +{ + if (not click) + { + if (group.isEmpty()) + { + return; + } + + SetName(tr("New group")); + + setModal(true); + emit ToolTip(""); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogGroup::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + if (selected) + { + group.insert(object, tool); + } + else + { + group.remove(object); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogGroup::NameChanged() +{ + ui->lineEditName->text().isEmpty() ? flagName = false : flagName = true; + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap DialogGroup::GetGroup() const +{ + return group; +} diff --git a/src/libs/vtools/dialogs/tools/dialoggroup.h b/src/libs/vtools/dialogs/tools/dialoggroup.h new file mode 100644 index 000000000..249e0e5f7 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialoggroup.h @@ -0,0 +1,66 @@ +/************************************************************************ + ** + ** @file dialoggroup.h + ** @author Roman Telezhynskyi + ** @date 4 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGGROUP_H +#define DIALOGGROUP_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogGroup; +} + +class DialogGroup : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogGroup(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + ~DialogGroup(); + + void SetName(const QString &name); + QString GetName() const; + + QMap GetGroup() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + void NameChanged(); + +private: + Q_DISABLE_COPY(DialogGroup) + Ui::DialogGroup *ui; + QMap group; +}; + +#endif // DIALOGGROUP_H diff --git a/src/libs/vtools/dialogs/tools/dialoggroup.ui b/src/libs/vtools/dialogs/tools/dialoggroup.ui new file mode 100644 index 000000000..3983b99f8 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialoggroup.ui @@ -0,0 +1,91 @@ + + + DialogGroup + + + + 0 + 0 + 397 + 80 + + + + Group + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + Group name: + + + + + + + Unique pattern piece name + + + Choose group name + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogGroup + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogGroup + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 8e1d66333..c288f9fb8 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -694,6 +694,14 @@ void DialogTool::ChosenObject(quint32 id, const SceneObject &type) Q_UNUSED(type); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(selected); + Q_UNUSED(object); + Q_UNUSED(tool); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NamePointChanged check name of point diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index ab9353d35..2eeec1370 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -92,6 +92,7 @@ signals: public slots: void ShowVisToolTip(const QString &toolTip); virtual void ChosenObject(quint32 id, const SceneObject &type); + virtual void SelectedObject(bool selected, quint32 object, quint32 tool); void NamePointChanged(); virtual void DialogAccepted(); /** diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index fdc8d6c4b..7d7b5f03c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -166,15 +166,7 @@ QVariant VAbstractSpline::itemChange(QGraphicsItem::GraphicsItemChange change, c { if (change == QGraphicsItem::ItemSelectedChange) { - if (value == true) - { - // do stuff if selected - this->setFocus(); - } - else - { - // do stuff if not selected - } + emit ChangedToolSelection(value.toBool(), id, id); } return QGraphicsItem::itemChange(change, value); @@ -342,3 +334,10 @@ QString VAbstractSpline::name() const { return ObjectName(id); } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + setVisible(visible); +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 140276363..89f2548f2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -53,6 +53,7 @@ public: QString name() const; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 000991f4e..8e7729788 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -42,6 +42,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin firstPoint = new VSimplePoint(p1id, QColor(baseColor), *data->GetPatternUnit(), &factor); firstPoint->setParentItem(this); connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed); + connect(firstPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point1Selected); connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition); @@ -50,6 +51,7 @@ VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quin secondPoint = new VSimplePoint(p2id, QColor(baseColor), *data->GetPatternUnit(), &factor); secondPoint->setParentItem(this); connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed); + connect(secondPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point2Selected); connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(secondPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(secondPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition); @@ -90,6 +92,19 @@ void VToolDoublePoint::SetEnabled(bool enabled) SetToolEnabled(this, enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDoublePoint::GroupVisibility(quint32 object, bool visible) +{ + if (object == p1id) + { + firstPoint->setVisible(visible); + } + else if (object == p2id) + { + secondPoint->setVisible(visible); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Label1ChangePosition(const QPointF &pos) { @@ -138,6 +153,18 @@ void VToolDoublePoint::Point2Choosed() emit ChoosedTool(p2id, SceneObject::Point); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDoublePoint::Point1Selected(bool selected) +{ + emit ChangedToolSelection(selected, p1id, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolDoublePoint::Point2Selected(bool selected) +{ + emit ChangedToolSelection(selected, p2id, id); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::FullUpdateFromFile() { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index 0062b954c..8612864e1 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -56,6 +56,7 @@ public: void SetEnabled(bool enabled); + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: void Label1ChangePosition(const QPointF &pos); void Label2ChangePosition(const QPointF &pos); @@ -64,6 +65,8 @@ public slots: virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; void Point1Choosed(); void Point2Choosed(); + void Point1Selected(bool selected); + void Point2Selected(bool selected); virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 2794bd0dc..0fc8aca76 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -66,6 +66,7 @@ VToolSinglePoint::VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quin connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolSinglePoint::contextMenuEvent); connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolSinglePoint::DeleteFromLabel); connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VToolSinglePoint::PointChoosed); + connect(namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VToolSinglePoint::PointSelected); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolSinglePoint::NameChangePosition); lineName = new QGraphicsLineItem(this); this->setBrush(QBrush(Qt::NoBrush)); @@ -96,6 +97,13 @@ void VToolSinglePoint::SetEnabled(bool enabled) SetToolEnabled(lineName, enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + setVisible(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NameChangePosition handle change posion point label. @@ -167,6 +175,12 @@ void VToolSinglePoint::PointChoosed() emit ChoosedTool(id, SceneObject::Point); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::PointSelected(bool selected) +{ + setSelected(selected); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -270,15 +284,10 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, { if (change == QGraphicsItem::ItemSelectedChange) { - if (value == true) - { - // do stuff if selected - this->setFocus(); - } - else - { - // do stuff if not selected - } + namePoint->blockSignals(true); + namePoint->setSelected(value.toBool()); + namePoint->blockSignals(false); + emit ChangedToolSelection(value.toBool(), id, id); } return QGraphicsEllipseItem::itemChange(change, value); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 785ed98f9..dbacedea4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -53,12 +53,14 @@ public: void SetEnabled(bool enabled); + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: void NameChangePosition(const QPointF &pos); virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; void PointChoosed(); + void PointSelected(bool selected); virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index ddf9eb0ca..dcabb0288 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -61,6 +61,9 @@ public: QString GetLineColor() const; virtual void SetLineColor(const QString &value); +signals: + void ChangedToolSelection(bool selected, quint32 object, quint32 tool); + public slots: virtual void ShowTool(quint32 id, bool enable); virtual void ChangedActivDraw(const QString &newName); @@ -238,6 +241,7 @@ void VDrawTool::InitDrawToolConnections(VMainGraphicsScene *scene, T *tool) SCASSERT(tool != nullptr); QObject::connect(tool, &T::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + QObject::connect(tool, &T::ChangedToolSelection, scene, &VMainGraphicsScene::SelectedItem); QObject::connect(scene, &VMainGraphicsScene::NewFactor, tool, &T::SetFactor); QObject::connect(scene, &VMainGraphicsScene::DisableItem, tool, &T::Disable); QObject::connect(scene, &VMainGraphicsScene::EnableToolMove, tool, &T::EnableToolMove); diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index 5cd75cea1..acadc4f00 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -149,9 +149,8 @@ VToolLine * VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, con { VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, lineColor, typeCreation); scene->addItem(line); - connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(scene, &VMainGraphicsScene::NewFactor, line, &VToolLine::SetFactor); - connect(scene, &VMainGraphicsScene::DisableItem, line, &VToolLine::Disable); + InitDrawToolConnections(scene, line); + connect(scene, &VMainGraphicsScene::EnablePointItemSelection, line, &VToolLine::AllowSelecting); connect(scene, &VMainGraphicsScene::EnableLineItemHover, line, &VToolLine::AllowHover); doc->AddTool(id, line); @@ -327,15 +326,7 @@ QVariant VToolLine::itemChange(QGraphicsItem::GraphicsItemChange change, const Q { if (change == QGraphicsItem::ItemSelectedChange) { - if (value == true) - { - // do stuff if selected - this->setFocus(); - } - else - { - // do stuff if not selected - } + emit ChangedToolSelection(value.toBool(), id, id); } return QGraphicsItem::itemChange(change, value); @@ -479,6 +470,13 @@ void VToolLine::SetLineColor(const QString &value) SaveOption(obj); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + setVisible(visible); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLine::GetFirstPoint() const { diff --git a/src/libs/vtools/tools/drawTools/vtoolline.h b/src/libs/vtools/tools/drawTools/vtoolline.h index 084c92d80..a554c4248 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.h +++ b/src/libs/vtools/tools/drawTools/vtoolline.h @@ -63,6 +63,7 @@ public: virtual void SetTypeLine(const QString &value) Q_DECL_OVERRIDE; virtual void SetLineColor(const QString &value) Q_DECL_OVERRIDE; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index 2435b77f9..fc7662e9b 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -108,6 +108,13 @@ void VAbstractNode::SetParentType(const ParentType &value) parentType = value; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractNode::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + Q_UNUSED(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToModeling add tag to modeling tag current pattern peace. diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index 037eef068..9ebc987ce 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -54,6 +54,8 @@ public: ParentType GetParentType() const; void SetParentType(const ParentType &value); + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + protected: ParentType parentType; protected: diff --git a/src/libs/vtools/tools/vdatatool.h b/src/libs/vtools/tools/vdatatool.h index 6ebd29b38..3b939b07e 100644 --- a/src/libs/vtools/tools/vdatatool.h +++ b/src/libs/vtools/tools/vdatatool.h @@ -46,11 +46,12 @@ class VDataTool : public QObject public: explicit VDataTool(VContainer *data, QObject *parent = nullptr); virtual ~VDataTool() Q_DECL_OVERRIDE; - VContainer getData() const; - void setData(const VContainer *value); - virtual quint32 referens() const; - virtual void incrementReferens(); - virtual void decrementReferens(); + VContainer getData() const; + void setData(const VContainer *value); + virtual quint32 referens() const; + virtual void incrementReferens(); + virtual void decrementReferens(); + virtual void GroupVisibility(quint32 object, bool visible)=0; protected: /** @brief data container with data */ VContainer data; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index d876c9fef..62252cba3 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -628,6 +628,13 @@ void VToolDetail::ShowVisualization(bool show) Q_UNUSED(show) } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + Q_UNUSED(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 322b5fee9..c93769c1e 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -86,6 +86,7 @@ public: enum { Type = UserType + static_cast(Tool::Detail)}; virtual QString getTagName() const Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; virtual void FullUpdateFromGuiOk(int result); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index d895ed931..f0706e462 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -488,6 +488,13 @@ void VToolUnionDetails::decrementReferens() } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolUnionDetails::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + Q_UNUSED(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool from GUI. diff --git a/src/libs/vtools/tools/vtooluniondetails.h b/src/libs/vtools/tools/vtooluniondetails.h index 058d4ee79..af18419ac 100644 --- a/src/libs/vtools/tools/vtooluniondetails.h +++ b/src/libs/vtools/tools/vtooluniondetails.h @@ -84,6 +84,7 @@ public: virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; virtual void incrementReferens() Q_DECL_OVERRIDE; virtual void decrementReferens() Q_DECL_OVERRIDE; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/libs/vtools/undocommands/addgroup.cpp b/src/libs/vtools/undocommands/addgroup.cpp new file mode 100644 index 000000000..fbb4f05c7 --- /dev/null +++ b/src/libs/vtools/undocommands/addgroup.cpp @@ -0,0 +1,112 @@ +/************************************************************************ + ** + ** @file addgroup.cpp + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "addgroup.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../vmisc/vabstractapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +AddGroup::AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("add group")); + nodeId = doc->GetParametrId(xml); +} + +//--------------------------------------------------------------------------------------------------------------------- +AddGroup::~AddGroup() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddGroup::undo() +{ + qCDebug(vUndo, "Undo."); + + doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = doc->elementById(nodeId); + if (group.isElement()) + { + group.setAttribute(VAbstractPattern::AttrVisible, trueStr); + doc->ParseGroups(groups); + if (groups.removeChild(group).isNull()) + { + qCDebug(vUndo, "Can't delete group."); + return; + } + emit UpdateGroups(); + } + else + { + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); + return; + } + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddGroup::redo() +{ + qCDebug(vUndo, "Redo."); + + doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + groups.appendChild(xml); + doc->ParseGroups(groups); + emit UpdateGroups(); + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); +} diff --git a/src/libs/vtools/undocommands/addgroup.h b/src/libs/vtools/undocommands/addgroup.h new file mode 100644 index 000000000..ca0807fdf --- /dev/null +++ b/src/libs/vtools/undocommands/addgroup.h @@ -0,0 +1,49 @@ +/************************************************************************ + ** + ** @file addgroup.h + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef ADDGROUP_H +#define ADDGROUP_H + +#include "vundocommand.h" + +class AddGroup : public VUndoCommand +{ + Q_OBJECT +public: + AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); + virtual ~AddGroup(); + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; +signals: + void UpdateGroups(); +private: + Q_DISABLE_COPY(AddGroup) + const QString nameActivDraw; +}; + +#endif // ADDGROUP_H diff --git a/src/libs/vtools/undocommands/delgroup.cpp b/src/libs/vtools/undocommands/delgroup.cpp new file mode 100644 index 000000000..818e5e1a6 --- /dev/null +++ b/src/libs/vtools/undocommands/delgroup.cpp @@ -0,0 +1,112 @@ +/************************************************************************ + ** + ** @file delgroup.cpp + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "delgroup.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../vmisc/vabstractapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +DelGroup::DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("delete group")); + nodeId = id; + xml = doc->CloneNodeById(nodeId); +} + +//--------------------------------------------------------------------------------------------------------------------- +DelGroup::~DelGroup() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void DelGroup::undo() +{ + qCDebug(vUndo, "Undo."); + + doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + groups.appendChild(xml); + doc->ParseGroups(groups); + emit UpdateGroups(); + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DelGroup::redo() +{ + qCDebug(vUndo, "Redo."); + + //Keep first! + doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = doc->elementById(nodeId); + if (group.isElement()) + { + group.setAttribute(VAbstractPattern::AttrVisible, trueStr); + doc->ParseGroups(groups); + if (groups.removeChild(group).isNull()) + { + qCDebug(vUndo, "Can't delete group."); + return; + } + emit UpdateGroups(); + + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + } + else + { + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); + return; + } + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); +} diff --git a/src/libs/vtools/undocommands/delgroup.h b/src/libs/vtools/undocommands/delgroup.h new file mode 100644 index 000000000..a04372470 --- /dev/null +++ b/src/libs/vtools/undocommands/delgroup.h @@ -0,0 +1,49 @@ +/************************************************************************ + ** + ** @file delgroup.h + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DELGROUP_H +#define DELGROUP_H + +#include "vundocommand.h" + +class DelGroup : public VUndoCommand +{ + Q_OBJECT +public: + DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent = nullptr); + virtual ~DelGroup(); + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; +signals: + void UpdateGroups(); +private: + Q_DISABLE_COPY(DelGroup) + const QString nameActivDraw; +}; + +#endif // DELGROUP_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 46d553b32..0ce6cb9ec 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -18,7 +18,9 @@ HEADERS += \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ $$PWD/movelabel.h \ - $$PWD/movedoublelabel.h + $$PWD/movedoublelabel.h \ + $$PWD/addgroup.h \ + $$PWD/delgroup.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -37,4 +39,6 @@ SOURCES += \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ $$PWD/movelabel.cpp \ - $$PWD/movedoublelabel.cpp + $$PWD/movedoublelabel.cpp \ + $$PWD/addgroup.cpp \ + $$PWD/delgroup.cpp diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 60abcc02a..093a14051 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -152,6 +152,10 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV changeFinished = true; } } + if (change == QGraphicsItem::ItemSelectedChange) + { + emit PointSelected(value.toBool()); + } return QGraphicsItem::itemChange(change, value); } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.h b/src/libs/vwidgets/vgraphicssimpletextitem.h index dd5db5118..031879075 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.h +++ b/src/libs/vwidgets/vgraphicssimpletextitem.h @@ -63,6 +63,7 @@ signals: void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); void DeleteTool(); void PointChoosed(); + void PointSelected(bool selected); protected: QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent *event ) Q_DECL_OVERRIDE; diff --git a/src/libs/vwidgets/vmaingraphicsscene.cpp b/src/libs/vwidgets/vmaingraphicsscene.cpp index 6ad0b7ce7..d1940cdac 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.cpp +++ b/src/libs/vwidgets/vmaingraphicsscene.cpp @@ -258,6 +258,12 @@ void VMainGraphicsScene::ChoosedItem(quint32 id, const SceneObject &type) emit ChoosedObject(id, type); } +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsScene::SelectedItem(bool selected, quint32 object, quint32 tool) +{ + emit SelectedObject(selected, object, tool); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetFactor set current scale factor of scene. @@ -299,6 +305,12 @@ void VMainGraphicsScene::TogglePointSelection(bool enabled) emit EnablePointItemSelection(enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsScene::ToggleLineSelection(bool enabled) +{ + emit EnableLineItemSelection(enabled); +} + //--------------------------------------------------------------------------------------------------------------------- void VMainGraphicsScene::ToggleArcSelection(bool enabled) { diff --git a/src/libs/vwidgets/vmaingraphicsscene.h b/src/libs/vwidgets/vmaingraphicsscene.h index fc9b99c6e..e65896965 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.h +++ b/src/libs/vwidgets/vmaingraphicsscene.h @@ -55,6 +55,7 @@ public: void SetOriginsVisible(bool visible); public slots: void ChoosedItem(quint32 id, const SceneObject &type); + void SelectedItem(bool selected, quint32 object, quint32 tool); void SetFactor(qreal factor); void EnableItemMove(bool move); void EnableDetailsMode(bool mode); @@ -62,6 +63,7 @@ public slots: void ToggleLabelSelection(bool enabled); void TogglePointSelection(bool enabled); + void ToggleLineSelection(bool enabled); void ToggleArcSelection(bool enabled); void ToggleSplineSelection(bool enabled); void ToggleSplinePathSelection(bool enabled); @@ -98,6 +100,7 @@ signals: * @param type object scene type. */ void ChoosedObject(quint32 id, SceneObject type); + void SelectedObject(bool selected, quint32 object, quint32 tool); /** * @brief NewFactor send new scale factor. * @param factor scene scale factor. @@ -110,6 +113,7 @@ signals: void EnableLabelItemSelection(bool enable); void EnablePointItemSelection(bool enable); + void EnableLineItemSelection(bool enable); void EnableArcItemSelection(bool enable); void EnableSplineItemSelection(bool enable); void EnableSplinePathItemSelection(bool enable); diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 87624351f..0fafd4051 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -46,6 +46,7 @@ VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternU connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel); connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed); + connect(namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VSimplePoint::ChangedPosition); lineName = new QGraphicsLineItem(this); this->setBrush(QBrush(Qt::NoBrush)); @@ -165,6 +166,12 @@ void VSimplePoint::PointChoosed() emit Choosed(id); } +//--------------------------------------------------------------------------------------------------------------------- +void VSimplePoint::PointSelected(bool selected) +{ + emit Selected(selected, id); +} + //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::ChangedPosition(const QPointF &pos) { @@ -222,6 +229,20 @@ void VSimplePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) QGraphicsEllipseItem::hoverLeaveEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == QGraphicsItem::ItemSelectedChange) + { + namePoint->blockSignals(true); + namePoint->setSelected(value.toBool()); + namePoint->blockSignals(false); + emit Selected(value.toBool(), id); + } + + return QGraphicsEllipseItem::itemChange(change, value); +} + //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction QColor VSimplePoint::GetCurrentColor() const diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index cba340a0b..c412ee594 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -65,6 +65,7 @@ signals: * @param id point id. */ void Choosed(quint32 id); + void Selected(bool selected, quint32 id); void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); void Delete(); void NameChangedPosition(const QPointF &pos); @@ -72,14 +73,16 @@ signals: public slots: void DeleteFromLabel(); void PointChoosed(); + void PointSelected(bool selected); void ChangedPosition(const QPointF &pos); void ContextMenu(QGraphicsSceneContextMenuEvent * event); protected: - virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VSimplePoint)