diff --git a/ChangeLog.txt b/ChangeLog.txt index 70efd9b7b..16df511b4 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -23,11 +23,16 @@ - [#478] Rename 'Print preview tiled' to 'Preview Tiled PDF'. - [#472] Add 'Full Name' column to Formula dialog. - [#487] True dart point always goes to origin when the label is moved. +- [#128] New Tool: Slash and Spread. +- [#409] New feature: Export measurement file to Excel .csv. # Version 0.4.5 - [#435] Valentina doesn't change the cursor. - [#473] Tape 'Preferences' cause loss of focus. - [#485] Error when drawing a curved path. +- [#491] Valentina doesn't update fractional separator. +- [#492] Valentina crashes when add an increment. +- [#493] Error in seam allowance drawing. # Version 0.4.4 April 12, 2016 - Updated measurement templates with all measurements. Added new template Aldrich/Women measurements. diff --git a/dist/OBS_debian/debian.changelog b/dist/OBS_debian/debian.changelog index 8a0ce225c..92427ed2d 100644 --- a/dist/OBS_debian/debian.changelog +++ b/dist/OBS_debian/debian.changelog @@ -1,4 +1,4 @@ -valentina (0.4.3) trusty; urgency=low +valentina (0.4.4) trusty; urgency=low * Auto build. diff --git a/dist/debian/changelog b/dist/debian/changelog index 8a0ce225c..92427ed2d 100644 --- a/dist/debian/changelog +++ b/dist/debian/changelog @@ -1,4 +1,4 @@ -valentina (0.4.3) trusty; urgency=low +valentina (0.4.4) trusty; urgency=low * Auto build. diff --git a/dist/rpm/_service b/dist/rpm/_service index e066dabb3..f4090793f 100644 --- a/dist/rpm/_service +++ b/dist/rpm/_service @@ -1,7 +1,7 @@ https://github.com/dismine/Valentina.git - 0.4.3 + 0.4.4 valentina git %at diff --git a/dist/rpm/valentina.spec b/dist/rpm/valentina.spec index aa7863817..0ca3b9bdb 100644 --- a/dist/rpm/valentina.spec +++ b/dist/rpm/valentina.spec @@ -45,7 +45,7 @@ BuildRequires: libqt5-qtxmlpatterns-devel Requires: poppler-utils -Version: 0.4.3 +Version: 0.4.4 Release: 0 URL: https://bitbucket.org/dismine/valentina License: GPL-3.0+ @@ -161,6 +161,6 @@ rm -f dist/debian/%{name}.1.gz dist/debian/tape.1.gz dist/debian/%{name}.xml dis %changelog -* Fri Nov 27 2015 Roman Telezhinskyi +* Fri Nov 27 2015 Roman Telezhynskyi - Auto build diff --git a/scripts/asan_symbolize.py b/scripts/asan_symbolize.py index ffa57ee62..8e6fb61f7 100755 --- a/scripts/asan_symbolize.py +++ b/scripts/asan_symbolize.py @@ -11,11 +11,9 @@ import argparse import bisect import getopt import os -import pty import re import subprocess import sys -import termios symbolizers = {} DEBUG = False @@ -25,6 +23,7 @@ sysroot_path = None binary_name_filter = None fix_filename_patterns = None logfile = sys.stdin +allow_system_symbolizer = True # FIXME: merge the code that calls fix_filename(). def fix_filename(file_name): @@ -78,7 +77,7 @@ class LLVMSymbolizer(Symbolizer): cmd = [self.symbolizer_path, '--use-symbol-table=true', '--demangle=%s' % demangle, - '--functions=short', + '--functions=linkage', '--inlining=true', '--default-arch=%s' % self.default_arch] if self.system == 'Darwin': @@ -136,12 +135,13 @@ class Addr2LineSymbolizer(Symbolizer): super(Addr2LineSymbolizer, self).__init__() self.binary = binary self.pipe = self.open_addr2line() + self.output_terminator = -1 def open_addr2line(self): addr2line_tool = 'addr2line' if binutils_prefix: addr2line_tool = binutils_prefix + addr2line_tool - cmd = [addr2line_tool, '-f'] + cmd = [addr2line_tool, '-fi'] if demangle: cmd += ['--demangle'] cmd += ['-e', self.binary] @@ -154,16 +154,23 @@ class Addr2LineSymbolizer(Symbolizer): """Overrides Symbolizer.symbolize.""" if self.binary != binary: return None + lines = [] try: print >> self.pipe.stdin, offset - function_name = self.pipe.stdout.readline().rstrip() - file_name = self.pipe.stdout.readline().rstrip() + print >> self.pipe.stdin, self.output_terminator + is_first_frame = True + while True: + function_name = self.pipe.stdout.readline().rstrip() + file_name = self.pipe.stdout.readline().rstrip() + if is_first_frame: + is_first_frame = False + elif function_name in ['', '??']: + assert file_name == function_name + break + lines.append((function_name, file_name)); except Exception: - function_name = '' - file_name = '' - file_name = fix_filename(file_name) - return ['%s in %s %s' % (addr, function_name, file_name)] - + lines.append(('??', '??:0')) + return ['%s in %s %s' % (addr, function, fix_filename(file)) for (function, file) in lines] class UnbufferedLineConverter(object): """ @@ -171,6 +178,9 @@ class UnbufferedLineConverter(object): output. Uses pty to trick the child into providing unbuffered output. """ def __init__(self, args, close_stderr=False): + # Local imports so that the script can start on Windows. + import pty + import termios pid, fd = pty.fork() if pid == 0: # We're the child. Transfer control to command. @@ -261,7 +271,7 @@ def BreakpadSymbolizerFactory(binary): def SystemSymbolizerFactory(system, addr, binary): if system == 'Darwin': return DarwinSymbolizer(addr, binary) - elif system == 'Linux': + elif system == 'Linux' or system == 'FreeBSD': return Addr2LineSymbolizer(binary) @@ -341,17 +351,23 @@ class BreakpadSymbolizer(Symbolizer): class SymbolizationLoop(object): def __init__(self, binary_name_filter=None, dsym_hint_producer=None): - # Used by clients who may want to supply a different binary name. - # E.g. in Chrome several binaries may share a single .dSYM. - self.binary_name_filter = binary_name_filter - self.dsym_hint_producer = dsym_hint_producer - self.system = os.uname()[0] - if self.system not in ['Linux', 'Darwin', 'FreeBSD']: - raise Exception('Unknown system') - self.llvm_symbolizers = {} - self.last_llvm_symbolizer = None - self.dsym_hints = set([]) - self.frame_no = 0 + if sys.platform == 'win32': + # ASan on Windows uses dbghelp.dll to symbolize in-process, which works + # even in sandboxed processes. Nothing needs to be done here. + self.process_line = self.process_line_echo + else: + # Used by clients who may want to supply a different binary name. + # E.g. in Chrome several binaries may share a single .dSYM. + self.binary_name_filter = binary_name_filter + self.dsym_hint_producer = dsym_hint_producer + self.system = os.uname()[0] + if self.system not in ['Linux', 'Darwin', 'FreeBSD']: + raise Exception('Unknown system') + self.llvm_symbolizers = {} + self.last_llvm_symbolizer = None + self.dsym_hints = set([]) + self.frame_no = 0 + self.process_line = self.process_line_posix def symbolize_address(self, addr, binary, offset): # On non-Darwin (i.e. on platforms without .dSYM debug info) always use @@ -385,6 +401,8 @@ class SymbolizationLoop(object): [BreakpadSymbolizerFactory(binary), self.llvm_symbolizers[binary]]) result = symbolizers[binary].symbolize(addr, binary, offset) if result is None: + if not allow_system_symbolizer: + raise Exception('Failed to launch or use llvm-symbolizer.') # Initialize system symbolizer only if other symbolizers failed. symbolizers[binary].append_symbolizer( SystemSymbolizerFactory(self.system, addr, binary)) @@ -405,14 +423,14 @@ class SymbolizationLoop(object): def process_logfile(self): self.frame_no = 0 - while True: - line = logfile.readline() - if not line: - break + for line in logfile: processed = self.process_line(line) print '\n'.join(processed) - def process_line(self, line): + def process_line_echo(self, line): + return [line.rstrip()] + + def process_line_posix(self, line): self.current_line = line.rstrip() #0 0x7f6e35cf2e45 (/blah/foo.so+0x11fe45) stack_trace_line_format = ( @@ -437,20 +455,23 @@ class SymbolizationLoop(object): if __name__ == '__main__': - parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, - description='ASan symbolization script', - epilog='''Example of use: - asan_symbolize.py -c "$HOME/opt/cross/bin/arm-linux-gnueabi-" -s "$HOME/SymbolFiles" < asan.log''') + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description='ASan symbolization script', + epilog='Example of use:\n' + 'asan_symbolize.py -c "$HOME/opt/cross/bin/arm-linux-gnueabi-" ' + '-s "$HOME/SymbolFiles" < asan.log') parser.add_argument('path_to_cut', nargs='*', - help='pattern to be cut from the result file path ') + help='pattern to be cut from the result file path ') parser.add_argument('-d','--demangle', action='store_true', - help='demangle function names') + help='demangle function names') parser.add_argument('-s', metavar='SYSROOT', - help='set path to sysroot for sanitized binaries') + help='set path to sysroot for sanitized binaries') parser.add_argument('-c', metavar='CROSS_COMPILE', - help='set prefix for binutils') - parser.add_argument('-l','--logfile', default=sys.stdin, type=argparse.FileType('r'), - help='set log file name to parse, default is stdin') + help='set prefix for binutils') + parser.add_argument('-l','--logfile', default=sys.stdin, + type=argparse.FileType('r'), + help='set log file name to parse, default is stdin') args = parser.parse_args() if args.path_to_cut: fix_filename_patterns = args.path_to_cut diff --git a/scripts/obs_debian.sh b/scripts/obs_debian.sh index 8e0912ddb..afaff0c97 100755 --- a/scripts/obs_debian.sh +++ b/scripts/obs_debian.sh @@ -4,7 +4,7 @@ # Please, run this script from folder /scripts. # usage: -# $ ./generate_tool_cursor.sh +# $ ./obs_debian.sh # Note. For stable version enough create an archive debian.tar.gz with folder debian inside and download it. diff --git a/src/app/share/collection/bugs/IsPointOnLineSegment_RotateTool_issue.val b/src/app/share/collection/bugs/IsPointOnLineSegment_RotateTool_issue.val new file mode 100644 index 000000000..842069052 --- /dev/null +++ b/src/app/share/collection/bugs/IsPointOnLineSegment_RotateTool_issue.val @@ -0,0 +1,59 @@ + + + + 0.3.1 + cm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ +
+
diff --git a/src/app/share/collection/bugs/Issue_#493.val b/src/app/share/collection/bugs/Issue_#493.val new file mode 100644 index 000000000..2ed081c1f --- /dev/null +++ b/src/app/share/collection/bugs/Issue_#493.val @@ -0,0 +1,100 @@ + + + + 0.2.4 + mm + + + + Issue_#493.vit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+
+
diff --git a/src/app/share/collection/bugs/Issue_#493.vit b/src/app/share/collection/bugs/Issue_#493.vit new file mode 100644 index 000000000..77927926c --- /dev/null +++ b/src/app/share/collection/bugs/Issue_#493.vit @@ -0,0 +1,73 @@ + + + + 0.3.3 + false + + mm + 998 + + + + 1800-01-01 + female + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/tape/dialogs/dialogabouttape.h b/src/app/tape/dialogs/dialogabouttape.h index d3927dfd6..64039ed04 100644 --- a/src/app/tape/dialogs/dialogabouttape.h +++ b/src/app/tape/dialogs/dialogabouttape.h @@ -41,7 +41,7 @@ class DialogAboutTape : public QDialog public: explicit DialogAboutTape(QWidget *parent = 0); - ~DialogAboutTape(); + virtual ~DialogAboutTape(); protected: virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; diff --git a/src/app/tape/dialogs/dialogexporttocsv.cpp b/src/app/tape/dialogs/dialogexporttocsv.cpp new file mode 100644 index 000000000..eb11edb7c --- /dev/null +++ b/src/app/tape/dialogs/dialogexporttocsv.cpp @@ -0,0 +1,168 @@ +/************************************************************************ + ** + ** @file dialogexporttocsv.cpp + ** @author Roman Telezhynskyi + ** @date 1 6, 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 "dialogexporttocsv.h" +#include "ui_dialogexporttocsv.h" + +#include "../vmisc/vtapesettings.h" +#include "../mapplication.h" + +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogExportToCSV::DialogExportToCSV(QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogExportToCSV), + isInitialized(false) +{ + ui->setupUi(this); + + ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetCSVWithHeader()); + + foreach (int mib, QTextCodec::availableMibs()) + { + ui->comboBoxCodec->addItem(QTextCodec::codecForMib(mib)->name(), mib); + } + + ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->TapeSettings()->GetCSVCodec())); + + SetSeparator(qApp->TapeSettings()->GetCSVSeparator()); + + QPushButton *bDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults); + SCASSERT(bDefaults != nullptr); + connect(bDefaults, &QPushButton::clicked, this, &DialogExportToCSV::RestoreDefaults); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogExportToCSV::~DialogExportToCSV() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogExportToCSV::WithHeader() const +{ + return ui->checkBoxWithHeader->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +int DialogExportToCSV::SelectedMib() const +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + return ui->comboBoxCodec->itemData(ui->comboBoxCodec->currentIndex()).toInt(); +#else + return ui->comboBoxCodec->currentData().toInt(); +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +QChar DialogExportToCSV::Separator() const +{ + if (ui->radioButtonTab->isChecked()) + { + return QChar('\t'); + } + else if (ui->radioButtonSemicolon->isChecked()) + { + return QChar(';'); + } + else if (ui->radioButtonSpace->isChecked()) + { + return QChar(' '); + } + else + { + return QChar(','); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogExportToCSV::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + // retranslate designer form (single inheritance approach) + ui->retranslateUi(this); + } + + // remember to call base class implementation + QDialog::changeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogExportToCSV::showEvent(QShowEvent *event) +{ + QDialog::showEvent( event ); + if ( event->spontaneous() ) + { + return; + } + + if (isInitialized) + { + return; + } + // do your init stuff here + + setMaximumSize(size()); + setMinimumSize(size()); + + isInitialized = true;//first show windows are held +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogExportToCSV::RestoreDefaults() +{ + ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetDefCSVWithHeader()); + ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->TapeSettings()->GetDefCSVCodec())); + + SetSeparator(qApp->TapeSettings()->GetDefCSVSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogExportToCSV::SetSeparator(const QChar &separator) +{ + switch(separator.toLatin1()) + { + case '\t': + ui->radioButtonTab->setChecked(true); + break; + case ';': + ui->radioButtonSemicolon->setChecked(true); + break; + case ' ': + ui->radioButtonSpace->setChecked(true); + break; + case ',': + default: + ui->radioButtonComma->setChecked(true); + break; + } +} diff --git a/src/app/tape/dialogs/dialogexporttocsv.h b/src/app/tape/dialogs/dialogexporttocsv.h new file mode 100644 index 000000000..3630ab57f --- /dev/null +++ b/src/app/tape/dialogs/dialogexporttocsv.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file dialogexporttocsv.h + ** @author Roman Telezhynskyi + ** @date 1 6, 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 DIALOGEXPORTTOCSV_H +#define DIALOGEXPORTTOCSV_H + +#include + +namespace Ui { +class DialogExportToCSV; +} + +class DialogExportToCSV : public QDialog +{ + Q_OBJECT + +public: + explicit DialogExportToCSV(QWidget *parent = nullptr); + virtual ~DialogExportToCSV(); + + bool WithHeader() const; + int SelectedMib() const; + QChar Separator() const; + +protected: + virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; + virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; + +private slots: + void RestoreDefaults(); + +private: + Q_DISABLE_COPY(DialogExportToCSV) + Ui::DialogExportToCSV *ui; + bool isInitialized; + + void SetSeparator(const QChar &separator); +}; + +#endif // DIALOGEXPORTTOCSV_H diff --git a/src/app/tape/dialogs/dialogexporttocsv.ui b/src/app/tape/dialogs/dialogexporttocsv.ui new file mode 100644 index 000000000..c91663e38 --- /dev/null +++ b/src/app/tape/dialogs/dialogexporttocsv.ui @@ -0,0 +1,167 @@ + + + DialogExportToCSV + + + Qt::ApplicationModal + + + + 0 + 0 + 333 + 292 + + + + Export options + + + + :/tapeicon/64x64/logo.png:/tapeicon/64x64/logo.png + + + true + + + + + + Export + + + + + + With header + + + + + + + + + + 0 + 0 + + + + Codec: + + + + + + + + + + + + + + + Separator + + + + + + Tab + + + buttonGroup + + + + + + + Comma + + + true + + + buttonGroup + + + + + + + Semicolon + + + buttonGroup + + + + + + + Space + + + buttonGroup + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + + + + + + + + + buttonBox + accepted() + DialogExportToCSV + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogExportToCSV + reject() + + + 316 + 260 + + + 286 + 274 + + + + + + + + diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index e52acc0f7..a01addf1b 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -84,6 +84,14 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con type = QtWarningMsg; } +#if !defined(V_NO_DEBUG) + // I have decided to hide this annoing message for release builds. + if ((type == QtWarningMsg) && msg.contains("setGeometryDp: Unable to set geometry")) + { + type = QtDebugMsg; + } +#endif //!defined(V_NO_DEBUG) + #if defined(Q_OS_MAC) # if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 7, 0) // Try hide very annoying, Qt related, warnings in Mac OS X @@ -410,7 +418,7 @@ void MApplication::InitTrVars() } else { - trVars = new VTranslateVars(TapeSettings()->GetOsSeparator()); + trVars = new VTranslateVars(); } } diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index 8ce98fcd7..a8671ed02 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -11,6 +11,7 @@ SOURCES += \ $$PWD/dialogs/tapeconfigdialog.cpp \ $$PWD/dialogs/configpages/tapeconfigurationpage.cpp \ $$PWD/dialogs/configpages/tapepathpage.cpp \ + $$PWD/dialogs/dialogexporttocsv.cpp \ $$PWD/vlitepattern.cpp \ $$PWD/vtablesearch.cpp @@ -27,6 +28,7 @@ HEADERS += \ $$PWD/dialogs/tapeconfigdialog.h \ $$PWD/dialogs/configpages/tapeconfigurationpage.h \ $$PWD/dialogs/configpages/tapepathpage.h \ + $$PWD/dialogs/dialogexporttocsv.h \ $$PWD/vlitepattern.h \ $$PWD/vtablesearch.h @@ -34,4 +36,5 @@ FORMS += \ $$PWD/tmainwindow.ui \ $$PWD/dialogs/dialogabouttape.ui \ $$PWD/dialogs/dialognewmeasurements.ui \ - $$PWD/dialogs/dialogmdatabase.ui + $$PWD/dialogs/dialogmdatabase.ui \ + $$PWD/dialogs/dialogexporttocsv.ui diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index b66ff66b5..6ade33027 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -32,6 +32,7 @@ #include "dialogs/dialognewmeasurements.h" #include "dialogs/dialogmdatabase.h" #include "dialogs/tapeconfigdialog.h" +#include "dialogs/dialogexporttocsv.h" #include "../vpatterndb/calculator.h" #include "../ifc/ifcdef.h" #include "../ifc/xml/vvitconverter.h" @@ -39,6 +40,7 @@ #include "../ifc/xml/vpatternconverter.h" #include "../vmisc/vlockguard.h" #include "../vmisc/vsysexits.h" +#include "../vmisc/qxtcsvmodel.h" #include "vlitepattern.h" #include "../qmuparser/qmudef.h" #include "../vtools/dialogs/support/dialogeditwrongformula.h" @@ -50,6 +52,8 @@ #include #include #include +#include +#include #if defined(Q_OS_MAC) #include @@ -678,6 +682,80 @@ void TMainWindow::FileSaveAs() } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::ExportToCSV() +{ + const QString filters = tr("Comma-Separated Values (*.cvs)"); + const QString suffix("csv"); + const QString path = QDir::homePath() + "/" + tr("measurements"); + "." + suffix; + + QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters); + + if (fileName.isEmpty()) + { + return; + } + + QFileInfo f( fileName ); + if (f.suffix().isEmpty() && f.suffix() != suffix) + { + fileName += "." + suffix; + } + + DialogExportToCSV dialog(this); + if (dialog.exec() == QDialog::Accepted) + { + QxtCsvModel csv; + const int columns = ui->tableWidget->columnCount(); + { + int colCount = 0; + for (int column = 0; column < columns; ++column) + { + if (not ui->tableWidget->isColumnHidden(column)) + { + csv.insertColumn(colCount++); + } + } + } + + if (dialog.WithHeader()) + { + int colCount = 0; + for (int column = 0; column < columns; ++column) + { + if (not ui->tableWidget->isColumnHidden(column)) + { + QTableWidgetItem *header = ui->tableWidget->horizontalHeaderItem(colCount); + csv.setHeaderText(colCount, header->text()); + ++colCount; + } + } + } + + const int rows = ui->tableWidget->rowCount(); + for (int row = 0; row < rows; ++row) + { + csv.insertRow(row); + int colCount = 0; + for (int column = 0; column < columns; ++column) + { + if (not ui->tableWidget->isColumnHidden(column)) + { + QTableWidgetItem *item = ui->tableWidget->item(row, column); + csv.setText(row, colCount, item->text()); + ++colCount; + } + } + } + + csv.toCSV(fileName, dialog.WithHeader(), dialog.Separator(), QTextCodec::codecForMib(dialog.SelectedMib())); + + qApp->TapeSettings()->SetCSVSeparator(dialog.Separator()); + qApp->TapeSettings()->SetCSVCodec(dialog.SelectedMib()); + qApp->TapeSettings()->SetCSVWithHeader(dialog.WithHeader()); + } +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::AboutToShowWindowMenu() { @@ -862,6 +940,8 @@ void TMainWindow::Remove() { MFields(false); + ui->actionExportToCSV->setEnabled(false); + ui->lineEditName->blockSignals(true); ui->lineEditName->setText(""); ui->lineEditName->blockSignals(false); @@ -1012,6 +1092,9 @@ void TMainWindow::Fx() if (dialog->exec() == QDialog::Accepted) { + // Fix the bug #492. https://bitbucket.org/dismine/valentina/issues/492/valentina-crashes-when-add-an-increment + // Because of the bug need to take QTableWidgetItem twice time. Previous update "killed" the pointer. + const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName); m->SetMValue(nameField->data(Qt::UserRole).toString(), dialog->GetFormula()); MeasurementsWasSaved(false); @@ -1056,13 +1139,15 @@ void TMainWindow::AddCustom() ui->tableWidget->selectRow(currentRow); + ui->actionExportToCSV->setEnabled(true); + MeasurementsWasSaved(false); } //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::AddKnown() { - DialogMDataBase *dialog = new DialogMDataBase(m->ListKnown(), this); + QScopedPointer dialog (new DialogMDataBase(m->ListKnown(), this)); if (dialog->exec() == QDialog::Accepted) { qint32 currentRow; @@ -1110,9 +1195,10 @@ void TMainWindow::AddKnown() ui->tableWidget->selectRow(currentRow); + ui->actionExportToCSV->setEnabled(true); + MeasurementsWasSaved(false); } - delete dialog; } //--------------------------------------------------------------------------------------------------------------------- @@ -1292,7 +1378,7 @@ void TMainWindow::ShowMData() QString formula; try { - formula = qApp->TrVars()->FormulaToUser(meash->GetFormula()); + formula = qApp->TrVars()->FormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator()); } catch (qmu::QmuParserError &e) { @@ -1478,7 +1564,7 @@ void TMainWindow::SaveMValue() try { - const QString formula = qApp->TrVars()->FormulaFromUser(text, true); + const QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator()); m->SetMValue(nameField->data(Qt::UserRole).toString(), formula); } catch (qmu::QmuParserError &e) // Just in case something bad will happen @@ -1728,6 +1814,7 @@ void TMainWindow::SetupMenu() connect(ui->actionSaveAs, &QAction::triggered, this, &TMainWindow::FileSaveAs); ui->actionSaveAs->setShortcuts(QKeySequence::SaveAs); + connect(ui->actionExportToCSV, &QAction::triggered, this, &TMainWindow::ExportToCSV); connect(ui->actionReadOnly, &QAction::triggered, this, &TMainWindow::ReadOnly); connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences); @@ -2254,7 +2341,7 @@ void TMainWindow::RefreshTable() QString formula; try { - formula = qApp->TrVars()->FormulaToUser(meash->GetFormula()); + formula = qApp->TrVars()->FormulaToUser(meash->GetFormula(), qApp->Settings()->GetOsSeparator()); } catch (qmu::QmuParserError &e) { @@ -2298,6 +2385,11 @@ void TMainWindow::RefreshTable() ui->tableWidget->resizeRowsToContents(); ui->tableWidget->horizontalHeader()->setStretchLastSection(true); ui->tableWidget->blockSignals(false); + + if (ui->tableWidget->rowCount() > 0) + { + ui->actionExportToCSV->setEnabled(true); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -2410,16 +2502,24 @@ bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer QString f; if (fromUser) { - f = qApp->TrVars()->FormulaFromUser(formula, true); + f = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } else { f = formula; } f.replace("\n", " "); - Calculator *cal = new Calculator(); - const qreal result = UnitConvertor(cal->EvalFormula(data->PlainVariables(), f), mUnit, pUnit); - delete cal; + QScopedPointer cal(new Calculator()); + qreal result = cal->EvalFormula(data->PlainVariables(), f); + + if (qIsInf(result) || qIsNaN(result)) + { + label->setText(tr("Error") + " (" + postfix + ")."); + label->setToolTip(tr("Invalid value")); + return false; + } + + result = UnitConvertor(result, mUnit, pUnit); label->setText(qApp->LocaleToString(result) + " " +postfix); label->setToolTip(tr("Value")); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 241ee05e3..587387ee7 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -79,6 +79,7 @@ protected: private slots: void FileSave(); void FileSaveAs(); + void ExportToCSV(); void AboutToShowWindowMenu(); void ShowWindow(); void AboutApplication(); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index acf79fbc1..ff09cf868 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -913,6 +913,7 @@ + @@ -1249,6 +1250,17 @@ QAction::NoRole + + + false + + + Export to CSV + + + QAction::NoRole + + diff --git a/src/app/tape/vlitepattern.cpp b/src/app/tape/vlitepattern.cpp index 1908979a2..1b55e5cfe 100644 --- a/src/app/tape/vlitepattern.cpp +++ b/src/app/tape/vlitepattern.cpp @@ -59,6 +59,12 @@ QString VLitePattern::GenerateLabel(const LabelType &type, const QString &reserv return QString(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VLitePattern::GenerateSuffix() const +{ + return QString(); +} + //--------------------------------------------------------------------------------------------------------------------- void VLitePattern::UpdateToolData(const quint32 &id, VContainer *data) { diff --git a/src/app/tape/vlitepattern.h b/src/app/tape/vlitepattern.h index 170178298..a4ee1b2f0 100644 --- a/src/app/tape/vlitepattern.h +++ b/src/app/tape/vlitepattern.h @@ -43,6 +43,7 @@ public: virtual void DecrementReferens(quint32 id) const Q_DECL_OVERRIDE; virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const Q_DECL_OVERRIDE; + virtual QString GenerateSuffix() const Q_DECL_OVERRIDE; virtual void UpdateToolData(const quint32 &id, VContainer *data) Q_DECL_OVERRIDE; diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 045e3bcef..a50edb882 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -80,6 +80,14 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con type = QtWarningMsg; } +#if !defined(V_NO_DEBUG) + // I have decided to hide this annoing message for release builds. + if ((type == QtWarningMsg) && msg.contains("setGeometryDp: Unable to set geometry")) + { + type = QtDebugMsg; + } +#endif //!defined(V_NO_DEBUG) + #if defined(Q_OS_MAC) # if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 7, 0) // Try hide very annoying, Qt related, warnings in Mac OS X @@ -613,7 +621,7 @@ void VApplication::InitTrVars() { if (trVars == nullptr) { - trVars = new VTranslateVars(ValentinaSettings()->GetOsSeparator()); + trVars = new VTranslateVars(); } } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 117787659..7e440d8a3 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -33,6 +33,7 @@ #include "../vwidgets/vgraphicssimpletextitem.h" #include "../vwidgets/vcontrolpointspline.h" #include "../vwidgets/vsimplepoint.h" +#include "../vwidgets/vsimplecurve.h" #include "../vpropertyexplorer/vproperties.h" #include "vformulaproperty.h" #include "../vpatterndb/vformula.h" @@ -74,7 +75,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) == 42, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); switch (item->type()) { @@ -174,9 +175,16 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) currentItem = item->parentItem(); ShowItemOptions(currentItem); break; + case VSimpleCurve::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; case VToolTrueDarts::Type: ShowOptionsToolTrueDarts(item); break; + case VToolRotation::Type: + ShowOptionsToolRotation(item); + break; default: break; } @@ -191,7 +199,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) == 42, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -288,6 +296,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolTrueDarts::Type: UpdateOptionsToolTrueDarts(); break; + case VToolRotation::Type: + UpdateOptionsToolRotation(); + break; default: break; } @@ -323,7 +334,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) == 42, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -414,6 +425,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolTrueDarts::Type: ChangeDataToolTrueDarts(prop); break; + case VToolRotation::Type: + ChangeDataToolRotation(prop); + break; default: break; } @@ -481,7 +495,6 @@ void VToolOptionsPropertyBrowser::AddPropertyObjectName(Tool *i, const QString & AddProperty(itemName, AttrName); } - //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString &propertyName) @@ -502,6 +515,17 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName2(Tool *i, const QString & AddProperty(itemName, AttrName2); } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyOperationSuffix(Tool *i, const QString &propertyName, bool readOnly) +{ + auto itemSuffix = new VStringProperty(propertyName); + itemSuffix->setClearButtonEnable(true); + itemSuffix->setValue(i->Suffix()); + itemSuffix->setReadOnly(readOnly); + AddProperty(itemSuffix, AttrSuffix); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyCrossPoint(Tool *i, const QString &propertyName) @@ -645,6 +669,43 @@ void VToolOptionsPropertyBrowser::SetPointName2(const QString &name) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetOperationSuffix(const QString &suffix) +{ + if (Tool *item = qgraphicsitem_cast(currentItem)) + { + if (suffix == item->Suffix()) + { + return; + } + + if (suffix.isEmpty()) + { + idToProperty[AttrSuffix]->setValue(item->Suffix()); + return; + } + + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = VContainer::AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not VContainer::IsUnique(name)) + { + idToProperty[AttrSuffix]->setValue(item->Suffix()); + return; + } + } + + item->SetSuffix(suffix); + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- template Type VToolOptionsPropertyBrowser::GetCrossPoint(const QVariant &value) @@ -934,9 +995,6 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCutArc(VProperty *property) case 4: // AttrLength i->SetFormula(value.value()); break; - case 27: // AttrTypeColor - i->SetLineColor(value.toString()); - break; default: qWarning()<<"Unknown property type. id = "<SetFormula(value.value()); break; - case 27: // AttrTypeColor - i->SetLineColor(value.toString()); - break; default: qWarning()<<"Unknown property type. id = "<SetFormula(value.value()); break; - case 27: // AttrTypeColor - i->SetLineColor(value.toString()); - break; default: qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolRotation *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + case 5: // AttrAngle + i->SetFormulaAngle(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<GetFormula(), AttrLength); - AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); } //--------------------------------------------------------------------------------------------------------------------- @@ -1637,7 +1712,6 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Length"), i->GetFormula(), AttrLength); - AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); } //--------------------------------------------------------------------------------------------------------------------- @@ -1649,7 +1723,6 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *it AddPropertyObjectName(i, tr("Point label")); AddPropertyFormula(tr("Length"), i->GetFormula(), AttrLength); - AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); } //--------------------------------------------------------------------------------------------------------------------- @@ -1907,6 +1980,17 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCurveIntersectAxis(QGraphicsIte AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolRotation(QGraphicsItem *item) +{ + VToolRotation *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool rotation")); + + AddPropertyOperationSuffix(i, tr("Suffix")); + AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -2044,9 +2128,6 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCutArc() QVariant valueFormula; valueFormula.setValue(i->GetFormula()); idToProperty[AttrLength]->setValue(valueFormula); - - const qint32 index = VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()); - idToProperty[AttrColor]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- @@ -2059,9 +2140,6 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSpline() QVariant valueFormula; valueFormula.setValue(i->GetFormula()); idToProperty[AttrLength]->setValue(valueFormula); - - const qint32 index = VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()); - idToProperty[AttrColor]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- @@ -2074,9 +2152,6 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSplinePath() QVariant valueFormula; valueFormula.setValue(i->GetFormula()); idToProperty[AttrLength]->setValue(valueFormula); - - const qint32 index = VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()); - idToProperty[AttrColor]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- @@ -2365,6 +2440,17 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCurveIntersectAxis() idToProperty[AttrAngle]->setValue(valueAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() +{ + VToolRotation *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrSuffix]->setValue(i->Suffix()); + + QVariant valueAngle; + valueAngle.setValue(i->GetFormulaAngle()); + idToProperty[AttrAngle]->setValue(valueAngle); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { @@ -2405,6 +2491,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const << AttrVCrossPoint /* 34 */ << AttrHCrossPoint /* 35 */ << AttrLength1 /* 36 */ - << AttrLength2; /* 37 */ + << AttrLength2 /* 37 */ + << AttrSuffix; /* 38 */ return attr; } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 6ffd7a12b..e8ba646e1 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -74,6 +74,9 @@ private: template void SetPointName2(const QString &name); + template + void SetOperationSuffix(const QString &suffix); + template Type GetCrossPoint(const QVariant &value); @@ -95,6 +98,9 @@ private: template void AddPropertyPointName2(Tool *i, const QString &propertyName); + template + void AddPropertyOperationSuffix(Tool *i, const QString &propertyName, bool readOnly = false); + template void AddPropertyCrossPoint(Tool *i, const QString &propertyName); @@ -144,6 +150,7 @@ private: void ChangeDataToolTriangle(VPE::VProperty *property); void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); + void ChangeDataToolRotation(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -174,6 +181,7 @@ private: void ShowOptionsToolTriangle(QGraphicsItem *item); void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); + void ShowOptionsToolRotation(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -204,6 +212,7 @@ private: void UpdateOptionsToolTriangle(); void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); + void UpdateOptionsToolRotation(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index bddd259f3..bd431689e 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) == 42, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -335,7 +335,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); - const QSharedPointer spl = data->GeometricObject(splineId); + const QSharedPointer spl = data->GeometricObject(splineId); SCASSERT(spl != nullptr); return QString(tr("%1 - cut %2")) .arg(PointName(tool.getId())) @@ -344,7 +344,8 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); - const QSharedPointer splPath = data->GeometricObject(splinePathId); + const QSharedPointer splPath = + data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); return QString(tr("%1 - cut %2")) .arg(PointName(tool.getId())) @@ -384,6 +385,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodeSpline: case Tool::NodeSplinePath: case Tool::Group: + case Tool::Rotation: return QString(); } } diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index 724495f91..c308b3ff4 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #define DIALOG_MAX_FORMULA_HEIGHT 64 @@ -143,7 +144,7 @@ void DialogIncrements::FillIncrements() QString formula; try { - formula = qApp->TrVars()->FormulaToUser(incr->GetFormula()); + formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator()); } catch (qmu::QmuParserError &e) { @@ -309,9 +310,15 @@ bool DialogIncrements::EvalIncrementFormula(const QString &formula, bool fromUse f = formula; } f.replace("\n", " "); - Calculator *cal = new Calculator(); + QScopedPointer cal(new Calculator()); const qreal result = cal->EvalFormula(data->PlainVariables(), f); - delete cal; + + if (qIsInf(result) || qIsNaN(result)) + { + label->setText(tr("Error") + " (" + postfix + ")."); + label->setToolTip(tr("Invalid value")); + return false; + } label->setText(qApp->LocaleToString(result) + " " + postfix); label->setToolTip(tr("Value")); @@ -681,6 +688,9 @@ void DialogIncrements::Fx() if (dialog->exec() == QDialog::Accepted) { + // Fix the bug #492. https://bitbucket.org/dismine/valentina/issues/492/valentina-crashes-when-add-an-increment + // Because of the bug need to take QTableWidgetItem twice time. Previous update "killed" the pointer. + const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0); doc->SetIncrementFormula(nameField->text(), dialog->GetFormula()); FullUpdateTree(Document::LiteParse); ui->tableWidgetIncrement->selectRow(row); @@ -748,7 +758,7 @@ void DialogIncrements::ShowIncrementDetails() QString formula; try { - formula = qApp->TrVars()->FormulaToUser(incr->GetFormula()); + formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator()); } catch (qmu::QmuParserError &e) { diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index aa5b0949f..9803a5753 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -130,17 +130,8 @@ MainWindow::MainWindow(QWidget *parent) } CreateActions(); - CreateMenus(); - ToolBarDraws(); - ToolBarStages(); - InitToolButtons(); InitScenes(); - helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working.")); - ui->statusBar->addWidget(helpLabel); - - ToolBarTools(); - doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); @@ -150,6 +141,17 @@ MainWindow::MainWindow(QWidget *parent) connect(doc, &VPattern::SetCurrentPP, this, &MainWindow::GlobalChangePP); qApp->setCurrentDocument(doc); + InitDocksContain(); + CreateMenus(); + ToolBarDraws(); + ToolBarStages(); + InitToolButtons(); + + helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working.")); + ui->statusBar->addWidget(helpLabel); + + ToolBarTools(); + connect(qApp->getUndoStack(), &QUndoStack::cleanChanged, this, &MainWindow::PatternWasModified); InitAutoSave(); @@ -157,7 +159,6 @@ MainWindow::MainWindow(QWidget *parent) ui->toolBox->setCurrentIndex(0); ReadSettings(); - InitDocksContain(); setCurrentFile(""); WindowsLocale(); @@ -613,6 +614,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur 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::DialogApplied, this, applyDialogSlot); connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); @@ -1004,12 +1006,22 @@ void MainWindow::ClosedDialogUnionDetails(int result) 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::ToolRotation(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::Rotation, + ":/cursor/rotation_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogGroup(int result) { @@ -1737,6 +1749,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength); connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); + connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); } //--------------------------------------------------------------------------------------------------------------------- @@ -1777,12 +1790,16 @@ 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) == 42, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; dialogTool = nullptr; qCDebug(vMainWindow, "Dialog closed."); + + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + switch ( currentTool ) { case Tool::Arrow: @@ -1904,9 +1921,10 @@ void MainWindow::CancelTool() case Tool::Group: ui->toolButtonGroup->setChecked(false); break; + case Tool::Rotation: + ui->toolButtonRotation->setChecked(false); + break; } - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); // Crash: using CRTL+Z while using line tool. // related bug report: @@ -3109,6 +3127,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonArcWithLength->setEnabled(drawTools); ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); + ui->toolButtonRotation->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3353,12 +3372,14 @@ void MainWindow::CreateMenus() //Add Undo/Redo actions. undoAction = qApp->getUndoStack()->createUndoAction(this, tr("&Undo")); + connect(undoAction, &QAction::triggered, toolOptions, &VToolOptionsPropertyBrowser::RefreshOptions); undoAction->setShortcuts(QKeySequence::Undo); undoAction->setIcon(QIcon::fromTheme("edit-undo")); ui->menuPatternPiece->insertAction(ui->actionLast_tool, undoAction); ui->toolBarTools->addAction(undoAction); redoAction = qApp->getUndoStack()->createRedoAction(this, tr("&Redo")); + connect(redoAction, &QAction::triggered, toolOptions, &VToolOptionsPropertyBrowser::RefreshOptions); redoAction->setShortcuts(QKeySequence::Redo); redoAction->setIcon(QIcon::fromTheme("edit-redo")); ui->menuPatternPiece->insertAction(ui->actionLast_tool, redoAction); @@ -3379,7 +3400,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) == 42, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3530,6 +3551,10 @@ void MainWindow::LastUsedTool() ui->toolButtonGroup->setChecked(true); ToolGroup(true); break; + case Tool::Rotation: + ui->toolButtonRotation->setChecked(true); + ToolRotation(true); + break; } } @@ -4714,12 +4739,12 @@ void MainWindow::ToolSelectAllDrawObjects() const } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::ToolSelectGroupObjects() const +void MainWindow::ToolSelectOperationObjects() const { // Only true for rubber band selection emit EnableLabelSelection(true); emit EnablePointSelection(true); - emit EnableLineSelection(true); + emit EnableLineSelection(false); emit EnableArcSelection(true); emit EnableSplineSelection(true); emit EnableSplinePathSelection(true); @@ -4727,7 +4752,7 @@ void MainWindow::ToolSelectGroupObjects() const // Hovering emit EnableLabelHover(true); emit EnablePointHover(true); - emit EnableLineHover(true); + emit EnableLineHover(false); emit EnableArcHover(true); emit EnableSplineHover(true); emit EnableSplinePathHover(true); @@ -4737,6 +4762,17 @@ void MainWindow::ToolSelectGroupObjects() const ui->view->AllowRubberBand(true); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolSelectGroupObjects() const +{ + ToolSelectOperationObjects(); + // Only true for rubber band selection + emit EnableLineSelection(true); + + // Hovering + emit EnableLineHover(true); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolSelectDetail() const { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 98b383942..6708c07dd 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -122,6 +122,7 @@ public slots: void ToolPointOfIntersection(bool checked); void ToolUnionDetails(bool checked); void ToolGroup(bool checked); + void ToolRotation(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); @@ -372,6 +373,7 @@ private: void ToolSelectPointArc() const; void ToolSelectCurve() const; void ToolSelectAllDrawObjects() const; + void ToolSelectOperationObjects() const; void ToolSelectGroupObjects() const; void ToolSelectDetail() const; }; diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 3226e1efc..cc2724466 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -983,6 +983,32 @@ + + + + false + + + Rotate objects + + + ... + + + + :/toolicon/32x32/rotation.png:/toolicon/32x32/rotation.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 1063918f4..cfd41aa80 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -66,5 +66,7 @@ cursor/cubic_bezier_path_cursor@2x.png cursor/group_plus_cursor.png cursor/group_plus_cursor@2x.png + cursor/rotation_cursor.png + cursor/rotation_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/rotation_cursor.png b/src/app/valentina/share/resources/cursor/rotation_cursor.png new file mode 100644 index 000000000..3a769ac46 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/rotation_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/rotation_cursor@2x.png b/src/app/valentina/share/resources/cursor/rotation_cursor@2x.png new file mode 100644 index 000000000..55d2765c2 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/rotation_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 8b5d0bec5..89e67fe78 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -64,5 +64,7 @@ toolicon/32x32/cubic_bezier_path@2x.png toolicon/32x32/group_plus.png toolicon/32x32/group_plus@2x.png + toolicon/32x32/rotation.png + toolicon/32x32/rotation@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/rotation.png b/src/app/valentina/share/resources/toolicon/32x32/rotation.png new file mode 100644 index 000000000..f1fa60133 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/rotation.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/rotation@2x.png b/src/app/valentina/share/resources/toolicon/32x32/rotation@2x.png new file mode 100644 index 000000000..3a7337253 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/rotation@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/rotation.svg b/src/app/valentina/share/resources/toolicon/svg/rotation.svg new file mode 100644 index 000000000..5da456343 --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/rotation.svg @@ -0,0 +1,82 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 31c89cbf0..d6fd0c0c4 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -51,6 +51,7 @@ #include #include #include +#include const QString VPattern::AttrReadOnly = QStringLiteral("readOnly"); @@ -305,8 +306,7 @@ quint32 VPattern::SPointActiveDraw() const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - if (domElement.tagName() == VToolSinglePoint::TagName && - domElement.attribute(AttrType, "") == VToolBasePoint::ToolType) + if (domElement.tagName() == TagPoint && domElement.attribute(AttrType, "") == VToolBasePoint::ToolType) { return GetParametrId(domElement); } @@ -527,7 +527,7 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const { scene = sceneDetail; } - QStringList tags = QStringList() << TagPoint << TagLine << TagSpline << TagArc << TagTools; + const QStringList tags = QStringList() << TagPoint << TagLine << TagSpline << TagArc << TagTools << TagOperation; const QDomNodeList nodeList = node.childNodes(); const qint32 num = nodeList.size(); for (qint32 i = 0; i < num; ++i) @@ -557,6 +557,10 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const qCDebug(vXML, "Tag tools."); ParseToolsElement(scene, domElement, parse, domElement.attribute(AttrType, "")); break; + case 5: // TagOperation + qCDebug(vXML, "Tag operation."); + ParseOperationElement(scene, domElement, parse, domElement.attribute(AttrType, "")); + break; default: VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName())); throw e; @@ -596,7 +600,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document { if (element.tagName() == VToolDetail::TagNode) { - const quint32 id = GetParametrUInt(element, VToolDetail::AttrIdObject, NULL_ID_STR); + const quint32 id = GetParametrUInt(element, AttrIdObject, NULL_ID_STR); const qreal mx = qApp->toPixel(GetParametrDouble(element, AttrMx, "0.0")); const qreal my = qApp->toPixel(GetParametrDouble(element, AttrMy, "0.0")); const bool reverse = GetParametrUInt(element, VToolDetail::AttrReverse, "0"); @@ -654,7 +658,7 @@ void VPattern::ParseDetails(const QDomElement &domElement, const Document &parse const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - if (domElement.tagName() == VToolDetail::TagName) + if (domElement.tagName() == TagDetail) { ParseDetailElement(domElement, parse); } @@ -840,7 +844,7 @@ void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &do void VPattern::SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool) { ToolsCommonAttributes(domElement, id); - idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); + idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); } @@ -1279,7 +1283,7 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par qreal my = 0; PointsCommonAttributes(domElement, id, mx, my); - const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); + const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); QSharedPointer point; try @@ -1291,8 +1295,7 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par Q_UNUSED(e); return;// Just ignore } - data->UpdateGObject(id, new VPointF(point->toQPointF(), point->name(), mx, my, idObject, - Draw::Modeling)); + data->UpdateGObject(id, new VPointF(*point, point->name(), mx, my, idObject, Draw::Modeling)); VNodePoint::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool); } catch (const VExceptionBadId &e) @@ -1410,11 +1413,8 @@ void VPattern::ParseToolCutSpline(VMainGraphicsScene *scene, QDomElement &domEle const QString formula = GetParametrString(domElement, AttrLength, "0"); QString f = formula;//need for saving fixed formula; const quint32 splineId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, NULL_ID_STR); - const QString color = GetParametrString(domElement, AttrColor, - ColorBlack); - VToolCutSpline::Create(id, name, f, splineId, mx, my, color, scene, this, data, parse, - Source::FromFile); + VToolCutSpline::Create(id, name, f, splineId, mx, my, scene, this, data, parse, Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. if (f != formula) { @@ -1455,11 +1455,8 @@ void VPattern::ParseToolCutSplinePath(VMainGraphicsScene *scene, QDomElement &do QString f = formula;//need for saving fixed formula; const quint32 splinePathId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, NULL_ID_STR); - const QString color = GetParametrString(domElement, AttrColor, - ColorBlack); - VToolCutSplinePath::Create(id, name, f, splinePathId, mx, my, color, scene, this, data, parse, - Source::FromFile); + VToolCutSplinePath::Create(id, name, f, splinePathId, mx, my, scene, this, data, parse, Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. if (f != formula) { @@ -1499,9 +1496,8 @@ void VPattern::ParseToolCutArc(VMainGraphicsScene *scene, QDomElement &domElemen const QString formula = GetParametrString(domElement, AttrLength, "0"); QString f = formula;//need for saving fixed formula; const quint32 arcId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); - const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - VToolCutArc::Create(id, name, f, arcId, mx, my, color, scene, this, data, parse, Source::FromFile); + VToolCutArc::Create(id, name, f, arcId, mx, my, scene, this, data, parse, Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. if (f != formula) { @@ -2330,7 +2326,7 @@ void VPattern::ParseNodeArc(const QDomElement &domElement, const Document &parse quint32 id = 0; ToolsCommonAttributes(domElement, id); - const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); + const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); VArc *arc = nullptr; try @@ -2401,6 +2397,49 @@ void VPattern::ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &do } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = NULL_ID; + + ToolsCommonAttributes(domElement, id); + const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + const QString angle = GetParametrString(domElement, AttrAngle, "10"); + QString a = angle;//need for saving fixed formula; + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VToolRotation::ExtractData(this, domElement, source, destination); + + VToolRotation::Create(id, center, a, suffix, source, destination, scene, this, data, parse, Source::FromFile); + //Rewrite attribute formula. Need for situation when we have wrong formula. + if (a != angle) + { + SetAttribute(domElement, AttrAngle, a); + modified = true; + haveLiteChange(); + } + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of rotation"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + catch (qmu::QmuParserError &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of rotation"), domElement); + excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr())); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const { @@ -2416,11 +2455,10 @@ qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) // Replace line return character with spaces for calc if exist QString f = formula; f.replace("\n", " "); - Calculator *cal = new Calculator(); + QScopedPointer cal(new Calculator()); const qreal result = cal->EvalFormula(data->PlainVariables(), f); - delete cal; - *ok = true; + (qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true; return result; } catch (qmu::QmuParserError &e) @@ -2644,6 +2682,27 @@ void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &d } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse, + const QString &type) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(not type.isEmpty(), Q_FUNC_INFO, "type of operation is empty"); + + const QStringList opers = QStringList() << VToolRotation::ToolType; /*0*/ + + switch (opers.indexOf(type)) + { + case 0: //VToolRotation::ToolType + ParseToolRotation(scene, domElement, parse); + break; + default: + VException e(tr("Unknown operation type '%1'.").arg(type)); + throw e; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseIncrementsElement parse increments tag. @@ -2814,10 +2873,9 @@ void VPattern::SetIncrementDescription(const QString &name, const QString &text) */ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedName) const { - QDomNodeList drawList = elementsByTagName(TagDraw); - if (type == LabelType::NewPatternPiece) { + const QDomNodeList drawList = elementsByTagName(TagDraw); QString name; int i = 0; for (;;) @@ -2838,25 +2896,7 @@ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedNa } else if (type == LabelType::NewLabel) { - if (drawList.isEmpty()) - { - const QString label = GetLabelBase(0); - qCDebug(vXML, "Point label: %s", qUtf8Printable(label)); - return label; - } - - int index = 0; - for (int i = 0; i < drawList.size(); ++i) - { - QDomElement node = drawList.at(i).toElement(); - if (node.attribute(AttrName) == nameActivPP) - { - index = i; - break; - } - } - - QString labelBase = GetLabelBase(static_cast(index)); + const QString labelBase = GetLabelBase(static_cast(GetIndexActivPP())); qint32 num = 1; QString name; @@ -2876,6 +2916,40 @@ QString VPattern::GenerateLabel(const LabelType &type, const QString &reservedNa return QString(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GenerateSuffix() const +{ + const QString suffixBase = GetLabelBase(static_cast(GetIndexActivPP())).toLower(); + const QStringList uniqueNames = data->AllUniqueNames(); + qint32 num = 1; + QString suffix; + for (;;) + { + suffix = QString("%1%2").arg(suffixBase).arg(num); + + for (int i=0; i < uniqueNames.size(); ++i) + { + if (not data->IsUnique(uniqueNames.at(i) + suffix)) + { + break; + } + + if (i == uniqueNames.size()-1) + { + qCDebug(vXML, "Suffix is: %s", qUtf8Printable(suffix)); + return suffix; + } + } + + if (num == INT_MAX) + { + break; + } + ++num; + } + return QString(); +} + //--------------------------------------------------------------------------------------------------------------------- bool VPattern::IsDefCustom() const { @@ -3130,7 +3204,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) == 42, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used."); QRectF rec; @@ -3237,6 +3311,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::TrueDarts: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::Rotation: + rec = ToolBoundingRect(rec, tool.getId()); + break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index a08c7b362..c23accf08 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -77,6 +77,7 @@ public: void SetIncrementDescription(const QString &name, const QString &text); virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const Q_DECL_OVERRIDE; + virtual QString GenerateSuffix() const Q_DECL_OVERRIDE; bool IsDefCustom() const; void SetDefCustom(bool value); @@ -125,6 +126,8 @@ private: const Document &parse, const QString& type); void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, const Document &parse, const QString& type); + void ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse, + const QString& type); void ParseIncrementsElement(const QDomNode& node); void PrepareForParse(const Document &parse); void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id); @@ -185,6 +188,8 @@ private: void ParseNodeArc(const QDomElement &domElement, const Document &parse); void ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; QDomElement MakeEmptyIncrement(const QString &name); diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index dcbd260be..65d74d3ff 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -128,6 +128,8 @@ const QString AttrCCenter = QStringLiteral("cCenter"); const QString AttrTangent = QStringLiteral("tangent"); const QString AttrCRadius = QStringLiteral("cRadius"); const QString AttrArc = QStringLiteral("arc"); +const QString AttrSuffix = QStringLiteral("suffix"); +const QString AttrIdObject = QStringLiteral("idObject"); const QString TypeLineNone = QStringLiteral("none"); const QString TypeLineLine = QStringLiteral("hair"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index a88c39d3f..39d65b2f9 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -130,6 +130,8 @@ extern const QString AttrCCenter; extern const QString AttrTangent; extern const QString AttrCRadius; extern const QString AttrArc; +extern const QString AttrSuffix; +extern const QString AttrIdObject; extern const QString TypeLineNone; extern const QString TypeLineLine; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index d8aa89e47..5868055e2 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -14,6 +14,7 @@ schema/pattern/v0.2.6.xsd schema/pattern/v0.2.7.xsd schema/pattern/v0.3.0.xsd + schema/pattern/v0.3.1.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.1.xsd b/src/libs/ifc/schema/pattern/v0.3.1.xsd new file mode 100644 index 000000000..d5af28adf --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.1.xsd @@ -0,0 +1,515 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index ca528a4ab..a8bc66609 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -38,6 +38,7 @@ const QString VAbstractPattern::TagPattern = QStringLiteral("pattern"); const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation"); const QString VAbstractPattern::TagModeling = QStringLiteral("modeling"); const QString VAbstractPattern::TagDetails = QStringLiteral("details"); +const QString VAbstractPattern::TagDetail = QStringLiteral("detail"); const QString VAbstractPattern::TagAuthor = QStringLiteral("author"); const QString VAbstractPattern::TagDescription = QStringLiteral("description"); const QString VAbstractPattern::TagNotes = QStringLiteral("notes"); @@ -54,6 +55,7 @@ const QString VAbstractPattern::TagLine = QStringLiteral("line"); const QString VAbstractPattern::TagSpline = QStringLiteral("spline"); const QString VAbstractPattern::TagArc = QStringLiteral("arc"); const QString VAbstractPattern::TagTools = QStringLiteral("tools"); +const QString VAbstractPattern::TagOperation = QStringLiteral("operation"); const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); @@ -1170,6 +1172,28 @@ void VAbstractPattern::InsertTag(const QStringList &tags, const QDomElement &ele SetVersion(); } +//--------------------------------------------------------------------------------------------------------------------- +int VAbstractPattern::GetIndexActivPP() const +{ + const QDomNodeList drawList = elementsByTagName(TagDraw); + + int index = 0; + if (not drawList.isEmpty()) + { + for (int i = 0; i < drawList.size(); ++i) + { + QDomElement node = drawList.at(i).toElement(); + if (node.attribute(AttrName) == nameActivPP) + { + index = i; + break; + } + } + } + + return index; +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::ListIncrements() const { @@ -1201,6 +1225,7 @@ QStringList VAbstractPattern::ListExpressions() const list << ListArcExpressions(); list << ListSplineExpressions(); list << ListIncrementExpressions(); + list << ListOperationExpressions(); return list; } @@ -1208,6 +1233,10 @@ QStringList VAbstractPattern::ListExpressions() const //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::ListPointExpressions() const { + // Check if new tool doesn't bring new attribute with a formula. + // If no just increment number + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); for (int i=0; i < list.size(); ++i) @@ -1275,6 +1304,10 @@ QStringList VAbstractPattern::ListPointExpressions() const //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::ListArcExpressions() const { + // Check if new tool doesn't bring new attribute with a formula. + // If no just increment number + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); for (int i=0; i < list.size(); ++i) @@ -1332,6 +1365,10 @@ QStringList VAbstractPattern::ListSplineExpressions() const //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::ListPathPointExpressions() const { + // Check if new tool doesn't bring new attribute with a formula. + // If no just increment number + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); for (int i=0; i < list.size(); ++i) @@ -1391,6 +1428,33 @@ QStringList VAbstractPattern::ListIncrementExpressions() const return expressions; } +//--------------------------------------------------------------------------------------------------------------------- +QStringList VAbstractPattern::ListOperationExpressions() const +{ + // Check if new tool doesn't bring new attribute with a formula. + // If no just increment number + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43); + + QStringList expressions; + const QDomNodeList list = elementsByTagName(TagOperation); + for (int i=0; i < list.size(); ++i) + { + const QDomElement dom = list.at(i).toElement(); + + // Each tag can contains several attributes. + try + { + expressions.append(GetParametrString(dom, AttrAngle)); + } + catch (VExceptionEmptyParameter &e) + { + Q_UNUSED(e) + } + } + + return expressions; +} + //--------------------------------------------------------------------------------------------------------------------- bool VAbstractPattern::IsVariable(const QString &token) const { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 8524b4f9f..172f7cce3 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -74,6 +74,7 @@ public: virtual void DecrementReferens(quint32 id) const=0; virtual QString GenerateLabel(const LabelType &type, const QString &reservedName = QString())const=0; + virtual QString GenerateSuffix() const=0; virtual void UpdateToolData(const quint32 &id, VContainer *data)=0; @@ -132,6 +133,7 @@ public: static const QString TagCalculation; static const QString TagModeling; static const QString TagDetails; + static const QString TagDetail; static const QString TagAuthor; static const QString TagDescription; static const QString TagImage; @@ -148,6 +150,7 @@ public: static const QString TagSpline; static const QString TagArc; static const QString TagTools; + static const QString TagOperation; static const QString TagGradation; static const QString TagHeights; static const QString TagSizes; @@ -210,7 +213,7 @@ public: signals: /** - * @brief ChangedActivDraw change active pattern peace. + * @brief ChangedActivPP change active pattern peace. * @param newName new pattern peace name. */ void ChangedActivPP(const QString &newName); @@ -282,6 +285,7 @@ protected: QDomElement CheckTagExists(const QString &tag); void InsertTag(const QStringList &tags, const QDomElement &element); + int GetIndexActivPP() const; private: Q_DISABLE_COPY(VAbstractPattern) @@ -292,6 +296,7 @@ private: QStringList ListSplineExpressions() const; QStringList ListPathPointExpressions() const; QStringList ListIncrementExpressions() const; + QStringList ListOperationExpressions() const; bool IsVariable(const QString& token) const; bool IsPostfixOperator(const QString& token) const; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 46e09ae74..5068702ef 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.3.0"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.0.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.1"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.1.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -111,8 +111,10 @@ 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"); + return QStringLiteral("://schema/pattern/v0.2.7.xsd"); case (0x000300): + return QStringLiteral("://schema/pattern/v0.3.0.xsd"); + case (0x000301): return CurrentSchema; default: InvalidVersion(ver); @@ -128,97 +130,62 @@ void VPatternConverter::ApplyPatches() switch (ver) { case (0x000100): - { ToV0_1_1(); - const QString schema = XSDSchema(0x000101); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000101), fileName); V_FALLTHROUGH - } case (0x000101): - { ToV0_1_2(); - const QString schema = XSDSchema(0x000102); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000102), fileName); V_FALLTHROUGH - } case (0x000102): - { ToV0_1_3(); - const QString schema = XSDSchema(0x000103); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000103), fileName); V_FALLTHROUGH - } case (0x000103): - { ToV0_1_4(); - const QString schema = XSDSchema(0x000104); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000104), fileName); V_FALLTHROUGH - } case (0x000104): - { ToV0_2_0(); - const QString schema = XSDSchema(0x000200); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000200), fileName); V_FALLTHROUGH - } case (0x000200): - { ToV0_2_1(); - const QString schema = XSDSchema(0x000201); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000201), fileName); V_FALLTHROUGH - } case (0x000201): - { ToV0_2_2(); - const QString schema = XSDSchema(0x000202); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000202), fileName); V_FALLTHROUGH - } case (0x000202): - { ToV0_2_3(); - const QString schema = XSDSchema(0x000203); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000203), fileName); V_FALLTHROUGH - } case (0x000203): - { ToV0_2_4(); - const QString schema = XSDSchema(0x000204); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000204), fileName); V_FALLTHROUGH - } case (0x000204): - { ToV0_2_5(); - const QString schema = XSDSchema(0x000205); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000205), fileName); V_FALLTHROUGH - } case (0x000205): - { ToV0_2_6(); - const QString schema = XSDSchema(0x000206); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000206), fileName); V_FALLTHROUGH - } case (0x000206): - { ToV0_2_7(); - const QString schema = XSDSchema(0x000207); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000207), fileName); V_FALLTHROUGH - } case (0x000207): - { ToV0_3_0(); - const QString schema = XSDSchema(0x000300); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000300), fileName); V_FALLTHROUGH - } case (0x000300): + ToV0_3_1(); + ValidateXML(XSDSchema(0x000301), fileName); + V_FALLTHROUGH + case (0x000301): break; default: break; @@ -347,6 +314,14 @@ void VPatternConverter::ToV0_3_0() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_1() +{ + SetVersion(QStringLiteral("0.3.1")); + RemoveColorToolCutV0_3_1(); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { @@ -808,6 +783,26 @@ void VPatternConverter::ConvertMeasurementsToV0_2_1() ConvertPathPointExpressionsToV0_2_0(names); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::RemoveColorToolCutV0_3_1() +{ + const QDomNodeList list = elementsByTagName("point"); + for (int i=0; i < list.size(); ++i) + { + QDomElement element = list.at(i).toElement(); + if (not element.isNull()) + { + const QString type = element.attribute(QStringLiteral("type")); + if (type == QStringLiteral("cutArc") || + type == QStringLiteral("cutSpline") || + type == QStringLiteral("cutSplinePath")) + { + element.removeAttribute(QStringLiteral("color")); + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- QString VPatternConverter::MUnitV0_1_4() const { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 9cf256872..55be6f196 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -69,6 +69,7 @@ private: void ToV0_2_6(); void ToV0_2_7(); void ToV0_3_0(); + void ToV0_3_1(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); @@ -77,6 +78,8 @@ private: void ConvertMeasurementsToV0_2_1(); + void RemoveColorToolCutV0_3_1(); + QSet FixIncrementsToV0_2_0(); QString FixIncrementInFormulaToV0_2_0(const QString &formula, const QSet &names); void FixPointExpressionsToV0_2_0(const QSet &names); diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp index 75d9cdb57..0cf65d017 100644 --- a/src/libs/ifc/xml/vvitconverter.cpp +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -107,33 +107,21 @@ void VVITConverter::ApplyPatches() switch (ver) { case (0x000200): - { ToV0_3_0(); - const QString schema = XSDSchema(0x000300); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000300), fileName); V_FALLTHROUGH - } case (0x000300): - { ToV0_3_1(); - const QString schema = XSDSchema(0x000301); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000301), fileName); V_FALLTHROUGH - } case (0x000301): - { ToV0_3_2(); - const QString schema = XSDSchema(0x000302); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000302), fileName); V_FALLTHROUGH - } case (0x000302): - { ToV0_3_3(); - const QString schema = XSDSchema(0x000303); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000303), fileName); V_FALLTHROUGH - } case (0x000303): break; default: diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp index b65c80f94..e1385205c 100644 --- a/src/libs/ifc/xml/vvstconverter.cpp +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -105,26 +105,17 @@ void VVSTConverter::ApplyPatches() switch (ver) { case (0x000300): - { ToV0_4_0(); - const QString schema = XSDSchema(0x000400); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000400), fileName); V_FALLTHROUGH - } case (0x000400): - { ToV0_4_1(); - const QString schema = XSDSchema(0x000401); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000401), fileName); V_FALLTHROUGH - } case (0x000401): - { ToV0_4_2(); - const QString schema = XSDSchema(0x000402); - ValidateXML(schema, fileName); + ValidateXML(XSDSchema(0x000402), fileName); V_FALLTHROUGH - } case (0x000402): break; default: diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index bf77ec920..346931428 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -34,6 +34,7 @@ #include "../qmuparser/qmutokenparser.h" #include +#include const QString VMeasurements::TagVST = QStringLiteral("vst"); const QString VMeasurements::TagVIT = QStringLiteral("vit"); @@ -878,11 +879,10 @@ qreal VMeasurements::EvalFormula(VContainer *data, const QString &formula, bool // Replace line return character with spaces for calc if exist QString f = formula; f.replace("\n", " "); - Calculator *cal = new Calculator(); + QScopedPointer cal(new Calculator()); const qreal result = cal->EvalFormula(data->PlainVariables(), f); - delete cal; - *ok = true; + (qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true; return result; } catch (qmu::QmuParserError &e) diff --git a/src/libs/vgeometry/vabstractarc.cpp b/src/libs/vgeometry/vabstractarc.cpp new file mode 100644 index 000000000..3de722e4f --- /dev/null +++ b/src/libs/vgeometry/vabstractarc.cpp @@ -0,0 +1,208 @@ +/************************************************************************ + ** + ** @file vabstractarc.cpp + ** @author Roman Telezhynskyi + ** @date 10 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 "vabstractarc.h" +#include "vabstractarc_p.h" + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::VAbstractArc(const GOType &type, const quint32 &idObject, const Draw &mode) + : VAbstractCurve(type, idObject, mode), d (new VAbstractArcData()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2, quint32 idObject, Draw mode) + : VAbstractCurve(type, idObject, mode), d (new VAbstractArcData(center, f1, formulaF1, f2, formulaF2)) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, qreal f2, quint32 idObject, Draw mode) + : VAbstractCurve(type, idObject, mode), d (new VAbstractArcData(center, f1, f2)) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::VAbstractArc(const GOType &type, const QString &formulaLength, const VPointF ¢er, + qreal f1, const QString &formulaF1, quint32 idObject, Draw mode) + : VAbstractCurve(type, idObject, mode), d (new VAbstractArcData(formulaLength, center, f1, formulaF1)) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, quint32 idObject, Draw mode) + : VAbstractCurve(type, idObject, mode), d (new VAbstractArcData(center, f1)) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::VAbstractArc(const VAbstractArc &arc) + : VAbstractCurve(arc), d (arc.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc &VAbstractArc::operator=(const VAbstractArc &arc) +{ + if ( &arc == this ) + { + return *this; + } + VAbstractCurve::operator=(arc); + d = arc.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArc::~VAbstractArc() +{} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractArc::GetFormulaF1() const +{ + return d->formulaF1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::SetFormulaF1(const QString &formula, qreal value) +{ + d->formulaF1 = formula; + d->f1 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VAbstractArc::GetStartAngle() const +{ + return d->f1; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractArc::GetFormulaF2() const +{ + return d->formulaF2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::SetFormulaF2(const QString &formula, qreal value) +{ + d->formulaF2 = formula; + d->f2 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VAbstractArc::GetEndAngle() const +{ + return d->f2; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPointF VAbstractArc::GetCenter() const +{ + return d->center; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::SetCenter(const VPointF &point) +{ + d->center = point; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractArc::GetFormulaLength() const +{ + return d->formulaLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::SetFormulaLength(const QString &formula, qreal value) +{ + d->formulaLength = formula; + FindF2(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::setId(const quint32 &id) +{ + VAbstractCurve::setId(id); + CreateName(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractArc::NameForHistory(const QString &toolName) const +{ + QString name = toolName + QString(" %1").arg(GetCenter().name()); + + if (VAbstractCurve::id() != NULL_ID) + { + name += QString("_%1").arg(VAbstractCurve::id()); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + return name; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractArc::IsFlipped() const +{ + return d->isFlipped; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VAbstractArc::AngleArc() const +{ + { + const qreal angleDiff = qAbs(GetStartAngle() - GetEndAngle()); + if (VFuzzyComparePossibleNulls(angleDiff, 0) || VFuzzyComparePossibleNulls(angleDiff, 360)) + { + return 360; + } + } + QLineF l1(0, 0, 100, 0); + l1.setAngle(GetStartAngle()); + QLineF l2(0, 0, 100, 0); + l2.setAngle(GetEndAngle()); + + qreal ang = l1.angleTo(l2); + + if (IsFlipped()) + { + ang = 360 - ang; + } + + return ang; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::SetFlipped(bool value) +{ + d->isFlipped = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractArc::SetFormulaLength(const QString &formula) +{ + d->formulaLength = formula; +} diff --git a/src/libs/vgeometry/vabstractarc.h b/src/libs/vgeometry/vabstractarc.h new file mode 100644 index 000000000..b57665540 --- /dev/null +++ b/src/libs/vgeometry/vabstractarc.h @@ -0,0 +1,80 @@ +/************************************************************************ + ** + ** @file vabstractarc.h + ** @author Roman Telezhynskyi + ** @date 10 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 VABSTRACTARC_H +#define VABSTRACTARC_H + +#include "vabstractcurve.h" + +class VAbstractArcData; +class VPointF; + +class VAbstractArc : public VAbstractCurve +{ +public: + explicit VAbstractArc(const GOType &type, const quint32 &idObject = NULL_ID, const Draw &mode = Draw::Calculation); + VAbstractArc (const GOType &type, const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); + VAbstractArc (const GOType &type, const VPointF ¢er, qreal f1, qreal f2, quint32 idObject = 0, + Draw mode = Draw::Calculation); + VAbstractArc (const GOType &type, const QString &formulaLength, const VPointF ¢er, qreal f1, + const QString &formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); + VAbstractArc (const GOType &type, const VPointF ¢er, qreal f1, quint32 idObject = 0, + Draw mode = Draw::Calculation); + explicit VAbstractArc(const VAbstractArc &arc); + VAbstractArc& operator= (const VAbstractArc &arc); + virtual ~VAbstractArc(); + + QString GetFormulaF1 () const; + void SetFormulaF1 (const QString &formula, qreal value); + virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; + + QString GetFormulaF2 () const; + void SetFormulaF2 (const QString &formula, qreal value); + virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; + + VPointF GetCenter () const; + void SetCenter (const VPointF &point); + + QString GetFormulaLength () const; + void SetFormulaLength (const QString &formula, qreal value); + + virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; + + bool IsFlipped() const; + qreal AngleArc() const; +protected: + void SetFlipped(bool value); + virtual void FindF2(qreal length)=0; + void SetFormulaLength(const QString &formula); +private: + QSharedDataPointer d; +}; + +#endif // VABSTRACTARC_H diff --git a/src/libs/vgeometry/vabstractarc_p.h b/src/libs/vgeometry/vabstractarc_p.h new file mode 100644 index 000000000..8f1444312 --- /dev/null +++ b/src/libs/vgeometry/vabstractarc_p.h @@ -0,0 +1,148 @@ +/************************************************************************ + ** + ** @file VAbstractArcData.h + ** @author Roman Telezhynskyi + ** @date 10 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 VABSTRACTARC_P_H +#define VABSTRACTARC_P_H + +#include +#include "vgeometrydef.h" +#include "../vmisc/vabstractapplication.h" +#include "vpointf.h" + +#ifdef Q_CC_GNU + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Weffc++" +#endif + +class VAbstractArcData : public QSharedData +{ +public: + VAbstractArcData(); + VAbstractArcData(const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2, const QString &formulaF2); + VAbstractArcData(const QString &formulaLength, VPointF center, qreal f1, QString formulaF1); + VAbstractArcData(const VPointF ¢er, qreal f1); + VAbstractArcData(const VPointF ¢er, qreal f1, qreal f2); + VAbstractArcData(const VAbstractArcData &arc); + virtual ~VAbstractArcData(); + + /** @brief f1 start angle in degree. */ + qreal f1; + + /** @brief formulaF1 formula for start angle. */ + QString formulaF1; + + /** @brief f2 end angle in degree. */ + qreal f2; + + /** @brief formulaF2 formula for end angle. */ + QString formulaF2; + + /** @brief center center point of arc. */ + VPointF center; + + bool isFlipped; + + QString formulaLength; + +private: + VAbstractArcData &operator=(const VAbstractArcData &) Q_DECL_EQ_DELETE; +}; + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::VAbstractArcData() + : f1(0), + formulaF1(), + f2(0), + formulaF2(), + center(), + isFlipped(false), + formulaLength() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::VAbstractArcData(const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2) + : f1(f1), + formulaF1(formulaF1), + f2(f2), + formulaF2(formulaF2), + center(center), + isFlipped(false), + formulaLength() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::VAbstractArcData(const QString &formulaLength, VPointF center, qreal f1, QString formulaF1) + : f1(f1), + formulaF1(formulaF1), + f2(0), + formulaF2("0"), + center(center), + isFlipped(false), + formulaLength(formulaLength) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::VAbstractArcData(const VPointF ¢er, qreal f1) + : f1(f1), + formulaF1(QString().number(f1)), + f2(0), + formulaF2("0"), + center(center), + isFlipped(false), + formulaLength() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::VAbstractArcData(const VPointF ¢er, qreal f1, qreal f2) + : f1(f1), + formulaF1(QString().number(f1)), + f2(f2), + formulaF2(QString().number(f2)), + center(center), + isFlipped(false), + formulaLength() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::VAbstractArcData(const VAbstractArcData &arc) + : QSharedData(arc), + f1(arc.f1), + formulaF1(arc.formulaF1), + f2(arc.f2), + formulaF2(arc.formulaF2), + center(arc.center), + isFlipped(arc.isFlipped), + formulaLength(arc.formulaLength) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractArcData::~VAbstractArcData() +{} + +#endif // VABSTRACTARCDATA_H diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index feb04cd51..34a8d66e5 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -97,7 +97,7 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF & const qreal parT = GetParmT(length); - QLineF seg1_2 ( GetP1 ().toQPointF(), GetControlPoint1 () ); + QLineF seg1_2 ( GetP1 (), GetControlPoint1 () ); seg1_2.setLength(seg1_2.length () * parT); const QPointF p12 = seg1_2.p2(); @@ -109,7 +109,7 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF & seg12_23.setLength(seg12_23.length () * parT); const QPointF p123 = seg12_23.p2(); - QLineF seg3_4 ( GetControlPoint2 (), GetP4 ().toQPointF() ); + QLineF seg3_4 ( GetControlPoint2 (), GetP4 () ); seg3_4.setLength(seg3_4.length () * parT); const QPointF p34 = seg3_4.p2(); @@ -547,7 +547,7 @@ qreal VAbstractCubicBezier::LengthT(qreal t) const qDebug()<<"Wrong value t."; return 0; } - QLineF seg1_2 ( GetP1 ().toQPointF(), GetControlPoint1 () ); + QLineF seg1_2 ( GetP1 (), GetControlPoint1 () ); seg1_2.setLength(seg1_2.length () * t); const QPointF p12 = seg1_2.p2(); @@ -559,7 +559,7 @@ qreal VAbstractCubicBezier::LengthT(qreal t) const seg12_23.setLength(seg12_23.length () * t); const QPointF p123 = seg12_23.p2(); - QLineF seg3_4 ( GetControlPoint2 (), GetP4 ().toQPointF() ); + QLineF seg3_4 ( GetControlPoint2 (), GetP4 () ); seg3_4.setLength(seg3_4.length () * t); const QPointF p34 = seg3_4.p2(); @@ -571,5 +571,5 @@ qreal VAbstractCubicBezier::LengthT(qreal t) const seg123_234.setLength(seg123_234.length () * t); const QPointF p1234 = seg123_234.p2(); - return LengthBezier ( GetP1().toQPointF(), p12, p123, p1234); + return LengthBezier ( GetP1(), p12, p123, p1234); } diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index ec79e104c..cca2f7a61 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -244,6 +244,18 @@ void VAbstractCurve::SetDuplicate(quint32 number) CreateName(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractCurve::GetColor() const +{ + return d->color; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCurve::SetColor(const QString &color) +{ + d->color = color; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VAbstractCurve::CurveIntersectLine(const QVector &points, const QLineF &line) { diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index 1b3f5c8a5..19ad0331b 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -69,6 +69,9 @@ public: quint32 GetDuplicate() const; void SetDuplicate(quint32 number); + QString GetColor() const; + void SetColor(const QString &color); + static QVector CurveIntersectLine(const QVector &points, const QLineF &line); virtual QString NameForHistory(const QString &toolName) const=0; diff --git a/src/libs/vgeometry/vabstractcurve_p.h b/src/libs/vgeometry/vabstractcurve_p.h index 0bcdbc26c..3d5920bb5 100644 --- a/src/libs/vgeometry/vabstractcurve_p.h +++ b/src/libs/vgeometry/vabstractcurve_p.h @@ -31,6 +31,8 @@ #include +#include "../ifc/ifcdef.h" + #ifdef Q_CC_GNU #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" @@ -41,11 +43,11 @@ class VAbstractCurveData : public QSharedData public: VAbstractCurveData () - : duplicate(0) + : duplicate(0), color(ColorBlack) {} VAbstractCurveData(const VAbstractCurveData &curve) - : QSharedData(curve), duplicate(curve.duplicate) + : QSharedData(curve), duplicate(curve.duplicate), color(curve.color) {} virtual ~VAbstractCurveData(); @@ -53,6 +55,8 @@ public: /** @brief duplicate helps create unique name for curves that connects the same start and finish points. */ quint32 duplicate; + QString color; + private: VAbstractCurveData &operator=(const VAbstractCurveData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 2936c1036..3c710f4b5 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -42,7 +42,8 @@ * @brief VArc default constructor. */ VArc::VArc () - :VAbstractCurve(GOType::Arc), d (new VArcData) + : VAbstractArc(GOType::Arc), + d (new VArcData) {} //--------------------------------------------------------------------------------------------------------------------- @@ -53,34 +54,36 @@ VArc::VArc () * @param f1 start angle (degree). * @param f2 end angle (degree). */ -VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, - QString formulaF2, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::Arc, idObject, mode), - d (new VArcData(center, radius, formulaRadius, f1, formulaF1, f2, formulaF2)) +VArc::VArc (const VPointF ¢er, qreal radius, const QString &formulaRadius, qreal f1, const QString &formulaF1, + qreal f2, const QString &formulaF2, quint32 idObject, Draw mode) + : VAbstractArc(GOType::Arc, center, f1, formulaF1, f2, formulaF2, idObject, mode), + d (new VArcData(radius, formulaRadius)) { CreateName(); } //--------------------------------------------------------------------------------------------------------------------- -VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2) - : VAbstractCurve(GOType::Arc, NULL_ID, Draw::Calculation), d (new VArcData(center, radius, f1, f2)) +VArc::VArc(const VPointF ¢er, qreal radius, qreal f1, qreal f2) + : VAbstractArc(GOType::Arc, center, f1, f2, NULL_ID, Draw::Calculation), + d (new VArcData(radius)) { CreateName(); } //--------------------------------------------------------------------------------------------------------------------- -VArc::VArc(qreal length, QString formulaLength, VPointF center, qreal radius, QString formulaRadius, qreal f1, - QString formulaF1, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::Arc, idObject, mode), - d (new VArcData(formulaLength, center, radius, formulaRadius, f1, formulaF1)) +VArc::VArc(qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius, + const QString &formulaRadius, qreal f1, const QString &formulaF1, quint32 idObject, Draw mode) + : VAbstractArc(GOType::Arc, formulaLength, center, f1, formulaF1, idObject, mode), + d (new VArcData(radius, formulaRadius)) { CreateName(); FindF2(length); } //--------------------------------------------------------------------------------------------------------------------- -VArc::VArc(qreal length, VPointF center, qreal radius, qreal f1) - : VAbstractCurve(GOType::Arc, NULL_ID, Draw::Calculation), d (new VArcData(center, radius, f1)) +VArc::VArc(qreal length, const VPointF ¢er, qreal radius, qreal f1) + : VAbstractArc(GOType::Arc, center, f1, NULL_ID, Draw::Calculation), + d (new VArcData(radius)) { CreateName(); FindF2(length); @@ -92,7 +95,7 @@ VArc::VArc(qreal length, VPointF center, qreal radius, qreal f1) * @param arc arc */ VArc::VArc(const VArc &arc) - : VAbstractCurve(arc), d (arc.d) + : VAbstractArc(arc), d (arc.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -107,11 +110,24 @@ VArc &VArc::operator =(const VArc &arc) { return *this; } - VAbstractCurve::operator=(arc); + VAbstractArc::operator=(arc); d = arc.d; return *this; } +//--------------------------------------------------------------------------------------------------------------------- +VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + const VPointF center = GetCenter().Rotate(originPoint, degrees); + + const QPointF p1 = VPointF::RotatePF(originPoint, GetP1(), degrees); + const QPointF p2 = VPointF::RotatePF(originPoint, GetP2(), degrees); + + VArc arc(center, GetRadius(), QLineF(center, p1).angle(), QLineF(center, p2).angle()); + arc.setName(name() + prefix); + return arc; +} + //--------------------------------------------------------------------------------------------------------------------- VArc::~VArc() {} @@ -124,7 +140,7 @@ VArc::~VArc() qreal VArc::GetLength() const { qreal length = d->radius * qDegreesToRadians(AngleArc()); - if (d->isFlipped) + if (IsFlipped()) { length *= -1; } @@ -140,8 +156,8 @@ qreal VArc::GetLength() const QPointF VArc::GetP1() const { QPointF p1 ( GetCenter().x () + d->radius, GetCenter().y () ); - QLineF centerP1(GetCenter().toQPointF(), p1); - centerP1.setAngle(d->f1); + QLineF centerP1(GetCenter(), p1); + centerP1.setAngle(GetStartAngle()); return centerP1.p2(); } @@ -153,40 +169,11 @@ QPointF VArc::GetP1() const QPointF VArc::GetP2 () const { QPointF p2 ( GetCenter().x () + d->radius, GetCenter().y () ); - QLineF centerP2(GetCenter().toQPointF(), p2); - centerP2.setAngle(d->f2); + QLineF centerP2(GetCenter(), p2); + centerP2.setAngle(GetEndAngle()); return centerP2.p2(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AngleArc calculate arc angle. - * @return angle in degree. - */ -qreal VArc::AngleArc() const -{ - { - const qreal angleDiff = qAbs(d->f1 - d->f2); - if (VFuzzyComparePossibleNulls(angleDiff, 0) || VFuzzyComparePossibleNulls(angleDiff, 360)) - { - return 360; - } - } - QLineF l1(0, 0, 100, 0); - l1.setAngle(d->f1); - QLineF l2(0, 0, 100, 0); - l2.setAngle(d->f2); - - qreal ang = l1.angleTo(l2); - - if (d->isFlipped) - { - ang = 360 - ang; - } - - return ang; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetPoints return list of points needed for drawing arc. @@ -198,7 +185,7 @@ QVector VArc::GetPoints() const QVector sectionAngle; QPointF pStart; - d->isFlipped ? pStart = GetP2() : pStart = GetP1(); + IsFlipped() ? pStart = GetP2() : pStart = GetP1(); { qreal angle = AngleArc(); @@ -234,7 +221,7 @@ QVector VArc::GetPoints() const { const qreal lDistance = GetRadius() * 4.0/3.0 * qTan(qDegreesToRadians(sectionAngle.at(i)) * 0.25); - const QPointF center = GetCenter().toQPointF(); + const QPointF center = GetCenter(); QLineF lineP1P2(pStart, center); lineP1P2.setAngle(lineP1P2.angle() - 90.0); @@ -299,14 +286,14 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const qreal n = qRadiansToDegrees(len/d->radius); // n - is angle in degrees - QLineF line(GetCenter().toQPointF(), GetP1()); + QLineF line(GetCenter(), GetP1()); line.setAngle(line.angle()+n); - arc1 = VArc (d->center, d->radius, d->formulaRadius, d->f1, d->formulaF1, line.angle(), + arc1 = VArc (GetCenter(), d->radius, d->formulaRadius, GetStartAngle(), GetFormulaF1(), line.angle(), QString().setNum(line.angle()), getIdObject(), getMode()); - arc2 = VArc (d->center, d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), d->f2, - d->formulaF2, getIdObject(), getMode()); + arc2 = VArc (GetCenter(), d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), GetEndAngle(), + GetFormulaF2(), getIdObject(), getMode()); return line.p2(); } @@ -319,34 +306,6 @@ QPointF VArc::CutArc(const qreal &length) const return this->CutArc(length, arc1, arc2); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setId keep id arc in data. - * @param id id arc in data. - */ -void VArc::setId(const quint32 &id) -{ - VAbstractCurve::setId(id); - CreateName(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VArc::NameForHistory(const QString &toolName) const -{ - QString name = toolName + QString(" %1").arg(this->GetCenter().name()); - - if (VAbstractCurve::id() != NULL_ID) - { - name += QString("_%1").arg(VAbstractCurve::id()); - } - - if (GetDuplicate() > 0) - { - name += QString("_%1").arg(GetDuplicate()); - } - return name; -} - //--------------------------------------------------------------------------------------------------------------------- void VArc::CreateName() { @@ -368,7 +327,7 @@ void VArc::CreateName() //--------------------------------------------------------------------------------------------------------------------- void VArc::FindF2(qreal length) { - length < 0 ? d->isFlipped = true : d->isFlipped = false; + SetFlipped(length < 0); if (length >= MaxLength()) { @@ -377,16 +336,15 @@ void VArc::FindF2(qreal length) qreal arcAngle = qAbs(qRadiansToDegrees(length/d->radius)); - if (d->isFlipped) + if (IsFlipped()) { arcAngle = arcAngle * -1; } QLineF startAngle(0, 0, 100, 0); - startAngle.setAngle(d->f1 + arcAngle);// We use QLineF just because it is easy way correct angle value + startAngle.setAngle(GetStartAngle() + arcAngle);// We use QLineF just because it is easy way correct angle value - d->f2 = startAngle.angle(); - d->formulaF2 = QString().number(d->f2); + SetFormulaF2(QString().number(startAngle.angle()), startAngle.angle()); } //--------------------------------------------------------------------------------------------------------------------- @@ -395,60 +353,6 @@ qreal VArc::MaxLength() const return M_2PI*d->radius; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF1 return start angle. - * @return angle in degree. - */ -QString VArc::GetFormulaF1() const -{ - return d->formulaF1; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VArc::SetFormulaF1(const QString &formula, qreal value) -{ - d->formulaF1 = formula; - d->f1 = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF1 return formula for start angle. - * @return string with formula. - */ -qreal VArc::GetStartAngle() const -{ - return d->f1; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF2 return end angle. - * @return angle in degree. - */ -QString VArc::GetFormulaF2() const -{ - return d->formulaF2; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VArc::SetFormulaF2(const QString &formula, qreal value) -{ - d->formulaF2 = formula; - d->f2 = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF2 return formula for end angle. - * @return string with formula. - */ -qreal VArc::GetEndAngle() const -{ - return d->f2; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetRadius return arc radius. @@ -475,32 +379,3 @@ qreal VArc::GetRadius() const { return d->radius; } - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetCenter return center point. - * @return center point. - */ -VPointF VArc::GetCenter() const -{ - return d->center; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VArc::SetCenter(const VPointF &value) -{ - d->center = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VArc::GetFormulaLength() const -{ - return d->formulaLength; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VArc::SetFormulaLength(const QString &formula, qreal value) -{ - d->formulaLength = formula; - FindF2(value); -} diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 5548b5b31..6b485c7ba 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -29,7 +29,7 @@ #ifndef VARC_H #define VARC_H -#include "vabstractcurve.h" +#include "vabstractarc.h" #include "vpointf.h" #include @@ -39,55 +39,41 @@ class VArcData; /** * @brief VArc class for anticlockwise arc. */ -class VArc: public VAbstractCurve +class VArc: public VAbstractArc { Q_DECLARE_TR_FUNCTIONS(VArc) public: VArc (); - VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, - QString formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); - VArc (VPointF center, qreal radius, qreal f1, qreal f2); - VArc (qreal length, QString formulaLength, VPointF center, qreal radius, QString formulaRadius, qreal f1, - QString formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); - VArc (qreal length, VPointF center, qreal radius, qreal f1); + VArc (const VPointF ¢er, qreal radius, const QString &formulaRadius, qreal f1, const QString &formulaF1, + qreal f2, const QString &formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); + VArc (const VPointF ¢er, qreal radius, qreal f1, qreal f2); + VArc (qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius, const QString &formulaRadius, + qreal f1, const QString &formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); + VArc (qreal length, const VPointF ¢er, qreal radius, qreal f1); VArc(const VArc &arc); VArc& operator= (const VArc &arc); + VArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; virtual ~VArc() Q_DECL_OVERRIDE; - QString GetFormulaF1 () const; - void SetFormulaF1 (const QString &formula, qreal value); - virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; + QString GetFormulaRadius () const; + void SetFormulaRadius (const QString &formula, qreal value); + qreal GetRadius () const; - QString GetFormulaF2 () const; - void SetFormulaF2 (const QString &formula, qreal value); - virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; + virtual qreal GetLength () const Q_DECL_OVERRIDE; - QString GetFormulaRadius () const; - void SetFormulaRadius (const QString &formula, qreal value); - qreal GetRadius () const; + QPointF GetP1() const; + QPointF GetP2 () const; - VPointF GetCenter () const; - void SetCenter (const VPointF &value); - - QString GetFormulaLength () const; - void SetFormulaLength (const QString &formula, qreal value); - virtual qreal GetLength () const Q_DECL_OVERRIDE; - - QPointF GetP1() const; - QPointF GetP2 () const; - qreal AngleArc() const; virtual QVector GetPoints () const Q_DECL_OVERRIDE; - QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; - QPointF CutArc (const qreal &length) const; - virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; - virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; + + QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; + QPointF CutArc (const qreal &length) const; protected: virtual void CreateName() Q_DECL_OVERRIDE; + virtual void FindF2(qreal length) Q_DECL_OVERRIDE; private: QSharedDataPointer d; - void FindF2(qreal length); - qreal MaxLength() const; }; diff --git a/src/libs/vgeometry/varc_p.h b/src/libs/vgeometry/varc_p.h index 70c3b6393..f6aac25b7 100644 --- a/src/libs/vgeometry/varc_p.h +++ b/src/libs/vgeometry/varc_p.h @@ -32,7 +32,6 @@ #include #include "vgeometrydef.h" #include "../vmisc/vabstractapplication.h" -#include "vpointf.h" #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -42,72 +41,48 @@ class VArcData : public QSharedData { public: - - VArcData () - : f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()), - center(VPointF()), isFlipped(false), formulaLength() - {} - - VArcData (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, - QString formulaF2) - : f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius), - center(center), isFlipped(false), formulaLength() - {} - - VArcData(VPointF center, qreal radius, qreal f1, qreal f2) - : f1(f1), formulaF1(QString().number(f1)), - f2(f2), formulaF2(QString().number(f2)), - radius(radius), formulaRadius(QString().number(qApp->fromPixel(radius))), - center(center), isFlipped(false), formulaLength() - {} - - VArcData (QString formulaLength, VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1) - : f1(f1), formulaF1(formulaF1), f2(0), formulaF2("0"), radius(radius), formulaRadius(formulaRadius), - center(center), isFlipped(false), formulaLength(formulaLength) - {} - - VArcData(VPointF center, qreal radius, qreal f1) - : f1(f1), formulaF1(QString().number(f1)), f2(0), formulaF2("0"), radius(radius), - formulaRadius(QString().number(qApp->fromPixel(radius))), center(center), isFlipped(false), formulaLength() - {} - - VArcData(const VArcData &arc) - : QSharedData(arc), f1(arc.f1), formulaF1(arc.formulaF1), f2(arc.f2), formulaF2(arc.formulaF2), - radius(arc.radius), formulaRadius(arc.formulaRadius), center(arc.center), isFlipped(arc.isFlipped), - formulaLength(arc.formulaLength) - {} - + VArcData(); + VArcData(qreal radius, QString formulaRadius); + VArcData(qreal radius); + VArcData(const VArcData &arc); virtual ~VArcData(); - /** @brief f1 start angle in degree. */ - qreal f1; - - /** @brief formulaF1 formula for start angle. */ - QString formulaF1; - - /** @brief f2 end angle in degree. */ - qreal f2; - - /** @brief formulaF2 formula for end angle. */ - QString formulaF2; - /** @brief radius arc radius. */ qreal radius; /** @brief formulaRadius formula for arc radius. */ QString formulaRadius; - /** @brief center center point of arc. */ - VPointF center; - - bool isFlipped; - - QString formulaLength; - private: VArcData &operator=(const VArcData &) Q_DECL_EQ_DELETE; }; +//--------------------------------------------------------------------------------------------------------------------- +VArcData::VArcData() + : radius(0), + formulaRadius(QString()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VArcData::VArcData(qreal radius, QString formulaRadius) + : radius(radius), + formulaRadius(formulaRadius) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VArcData::VArcData(qreal radius) + : radius(radius), + formulaRadius(QString().number(qApp->fromPixel(radius))) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VArcData::VArcData(const VArcData &arc) + : QSharedData(arc), + radius(arc.radius), + formulaRadius(arc.formulaRadius) +{} + +//--------------------------------------------------------------------------------------------------------------------- VArcData::~VArcData() {} diff --git a/src/libs/vgeometry/vcubicbezier.cpp b/src/libs/vgeometry/vcubicbezier.cpp index d8503d15c..12489c5aa 100644 --- a/src/libs/vgeometry/vcubicbezier.cpp +++ b/src/libs/vgeometry/vcubicbezier.cpp @@ -61,6 +61,18 @@ VCubicBezier &VCubicBezier::operator=(const VCubicBezier &curve) return *this; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezier VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + const VPointF p1 = GetP1().Rotate(originPoint, degrees); + const VPointF p2 = GetP2().Rotate(originPoint, degrees); + const VPointF p3 = GetP3().Rotate(originPoint, degrees); + const VPointF p4 = GetP4().Rotate(originPoint, degrees); + VCubicBezier curve(p1, p2, p3, p4); + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezier::~VCubicBezier() { @@ -117,13 +129,13 @@ void VCubicBezier::SetP4(const VPointF &p) //--------------------------------------------------------------------------------------------------------------------- qreal VCubicBezier::GetStartAngle() const { - return QLineF(GetP1().toQPointF(), GetP2().toQPointF()).angle(); + return QLineF(GetP1(), GetP2()).angle(); } //--------------------------------------------------------------------------------------------------------------------- qreal VCubicBezier::GetEndAngle() const { - return QLineF(GetP4().toQPointF(), GetP3().toQPointF()).angle(); + return QLineF(GetP4(), GetP3()).angle(); } //--------------------------------------------------------------------------------------------------------------------- @@ -133,7 +145,7 @@ qreal VCubicBezier::GetEndAngle() const */ qreal VCubicBezier::GetLength() const { - return LengthBezier (GetP1().toQPointF(), GetP2().toQPointF(), GetP3().toQPointF(), GetP4().toQPointF()); + return LengthBezier (GetP1(), GetP2(), GetP3(), GetP4()); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,17 +155,17 @@ qreal VCubicBezier::GetLength() const */ QVector VCubicBezier::GetPoints() const { - return GetCubicBezierPoints(GetP1().toQPointF(), GetP2().toQPointF(), GetP3().toQPointF(), GetP4().toQPointF()); + return GetCubicBezierPoints(GetP1(), GetP2(), GetP3(), GetP4()); } //--------------------------------------------------------------------------------------------------------------------- QPointF VCubicBezier::GetControlPoint1() const { - return GetP2().toQPointF(); + return GetP2(); } //--------------------------------------------------------------------------------------------------------------------- QPointF VCubicBezier::GetControlPoint2() const { - return GetP3().toQPointF(); + return GetP3(); } diff --git a/src/libs/vgeometry/vcubicbezier.h b/src/libs/vgeometry/vcubicbezier.h index 57b9193f8..64d0009cd 100644 --- a/src/libs/vgeometry/vcubicbezier.h +++ b/src/libs/vgeometry/vcubicbezier.h @@ -42,6 +42,7 @@ public: VCubicBezier(const VPointF &p1, const VPointF &p2, const VPointF &p3, const VPointF &p4, quint32 idObject = 0, Draw mode = Draw::Calculation); VCubicBezier &operator=(const VCubicBezier &curve); + VCubicBezier Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; virtual ~VCubicBezier(); virtual VPointF GetP1() const Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp index cf463b794..2f427616e 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -79,6 +79,19 @@ VCubicBezierPath &VCubicBezierPath::operator=(const VCubicBezierPath &curve) return *this; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath VCubicBezierPath::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + const QVector points = GetCubicPath(); + VCubicBezierPath curve; + for(int i=0; i < points.size(); ++i) + { + curve.append(points.at(i).Rotate(originPoint, degrees)); + } + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezierPath::~VCubicBezierPath() { @@ -99,7 +112,7 @@ const VPointF &VCubicBezierPath::at(int indx) const //--------------------------------------------------------------------------------------------------------------------- void VCubicBezierPath::append(const VPointF &point) { - if (d->path.size() > 0 && d->path.last().toQPointF() != point.toQPointF()) + if (d->path.size() > 0 && d->path.last() != point) { return; } @@ -143,18 +156,18 @@ VSpline VCubicBezierPath::GetSpline(qint32 index) const const qint32 base = SubSplOffset(index); // Correction the first control point of each next spline curve except for the first. - QPointF p2 = d->path.at(base + 1).toQPointF(); + QPointF p2 = d->path.at(base + 1); if (base + 1 > 1) { - const QPointF b = d->path.at(base).toQPointF(); - QLineF foot1(b, d->path.at(base - 1).toQPointF()); + const QPointF b = d->path.at(base); + QLineF foot1(b, d->path.at(base - 1)); QLineF foot2(b, p2); foot2.setAngle(foot1.angle() + 180); p2 = foot2.p2(); } - VSpline spl(d->path.at(base), p2, d->path.at(base + 2).toQPointF(), d->path.at(base + 3)); + VSpline spl(d->path.at(base), p2, d->path.at(base + 2), d->path.at(base + 3)); return spl; } diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h index aa84f87e5..d17008049 100644 --- a/src/libs/vgeometry/vcubicbezierpath.h +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -45,6 +45,7 @@ public: VCubicBezierPath(const VCubicBezierPath &curve); VCubicBezierPath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); VCubicBezierPath &operator=(const VCubicBezierPath &curve); + VCubicBezierPath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; virtual ~VCubicBezierPath(); VPointF &operator[](int indx); diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index cd2327b88..49ef67d6a 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -39,7 +39,7 @@ * @brief VEllipticalArc default constructor. */ VEllipticalArc::VEllipticalArc() - :VAbstractCurve(GOType::EllipticalArc), d (new VEllipticalArcData) + : VAbstractArc(GOType::EllipticalArc), d (new VEllipticalArcData) {} //--------------------------------------------------------------------------------------------------------------------- @@ -51,41 +51,40 @@ VEllipticalArc::VEllipticalArc() * @param f1 start angle (degree). * @param f2 end angle (degree). */ -VEllipticalArc::VEllipticalArc (VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, qreal f2, - QString formulaF2, qreal rotationAngle, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::EllipticalArc, idObject, mode), - d (new VEllipticalArcData(center, radius1, radius2, formulaRadius1, formulaRadius2, - f1, formulaF1, f2, formulaF2, rotationAngle)) +VEllipticalArc::VEllipticalArc (const VPointF ¢er, qreal radius1, qreal radius2, const QString &formulaRadius1, + const QString &formulaRadius2, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2, qreal rotationAngle, quint32 idObject, Draw mode) + : VAbstractArc(GOType::EllipticalArc, center, f1, formulaF1, f2, formulaF2, idObject, mode), + d (new VEllipticalArcData(radius1, radius2, formulaRadius1, formulaRadius2, rotationAngle)) { CreateName(); } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc::VEllipticalArc(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle) - : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), - d (new VEllipticalArcData(center, radius1, radius2, f1, f2, rotationAngle)) +VEllipticalArc::VEllipticalArc(const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal f2, + qreal rotationAngle) + : VAbstractArc(GOType::EllipticalArc, center, f1, f2, NULL_ID, Draw::Calculation), + d (new VEllipticalArcData(radius1, radius2, rotationAngle)) { CreateName(); } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc::VEllipticalArc(qreal length, QString formulaLength, VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, qreal rotationAngle, - quint32 idObject, Draw mode) - : VAbstractCurve(GOType::EllipticalArc, idObject, mode), - d (new VEllipticalArcData(formulaLength, center, radius1, radius2, formulaRadius1, formulaRadius2, - f1, formulaF1, rotationAngle)) +VEllipticalArc::VEllipticalArc(qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius1, + qreal radius2, const QString &formulaRadius1, const QString &formulaRadius2, qreal f1, + const QString &formulaF1, qreal rotationAngle, quint32 idObject, Draw mode) + : VAbstractArc(GOType::EllipticalArc, formulaLength, center, f1, formulaF1, idObject, mode), + d (new VEllipticalArcData(radius1, radius2, formulaRadius1, formulaRadius2, rotationAngle)) { CreateName(); FindF2(length); } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc::VEllipticalArc(qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1, - qreal rotationAngle) - : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), - d (new VEllipticalArcData(center, radius1, radius2, f1, rotationAngle)) +VEllipticalArc::VEllipticalArc(qreal length, const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, + qreal rotationAngle) + : VAbstractArc(GOType::EllipticalArc, center, f1, NULL_ID, Draw::Calculation), + d (new VEllipticalArcData(radius1, radius2, rotationAngle)) { CreateName(); FindF2(length); @@ -97,7 +96,7 @@ VEllipticalArc::VEllipticalArc(qreal length, VPointF center, qreal radius1, qrea * @param arc arc */ VEllipticalArc::VEllipticalArc(const VEllipticalArc &arc) - : VAbstractCurve(arc), d (arc.d) + : VAbstractArc(arc), d (arc.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -112,11 +111,24 @@ VEllipticalArc &VEllipticalArc::operator =(const VEllipticalArc &arc) { return *this; } - VAbstractCurve::operator=(arc); + VAbstractArc::operator=(arc); d = arc.d; return *this; } +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc VEllipticalArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + const VPointF center = GetCenter().Rotate(originPoint, degrees); + const QPointF p1 = VPointF::RotatePF(originPoint, GetP1(), degrees); + const QPointF p2 = VPointF::RotatePF(originPoint, GetP2(), degrees); + const qreal f1 = QLineF(center, p1).angle() - GetRotationAngle(); + const qreal f2 = QLineF(center, p2).angle() - GetRotationAngle(); + VEllipticalArc elArc(center, GetRadius1(), GetRadius2(), f1, f2, GetRotationAngle()); + elArc.setName(name() + prefix); + return elArc; +} + //--------------------------------------------------------------------------------------------------------------------- VEllipticalArc::~VEllipticalArc() {} @@ -130,7 +142,7 @@ qreal VEllipticalArc::GetLength() const { qreal length = PathLength(GetPoints()); - if (d->isFlipped) + if (IsFlipped()) { length = length * -1; } @@ -145,7 +157,7 @@ qreal VEllipticalArc::GetLength() const */ QPointF VEllipticalArc::GetP1() const { - return GetPoint(d->f1); + return GetPoint(GetStartAngle()); } //--------------------------------------------------------------------------------------------------------------------- @@ -155,7 +167,7 @@ QPointF VEllipticalArc::GetP1() const */ QPointF VEllipticalArc::GetP2 () const { - return GetPoint(d->f2); + return GetPoint(GetEndAngle()); } //--------------------------------------------------------------------------------------------------------------------- @@ -165,74 +177,121 @@ QPointF VEllipticalArc::GetP2 () const */ QPointF VEllipticalArc::GetPoint (qreal angle) const { + // Original idea http://alex-black.ru/article.php?content=109#head_3 if (angle > 360 || angle < 0) {// Filter incorect value of angle - QLineF dummy(0,0, 100, 0); + QLineF dummy(0, 0, 100, 0); dummy.setAngle(angle); angle = dummy.angle(); } // p - point without rotation - qreal x = qAbs((d->radius1 * d->radius2)/ - (qSqrt(d->radius2*d->radius2+d->radius1*d->radius1*qTan(M_PI*angle/180)*qTan(M_PI*angle/180)))); - qreal y = qAbs(qTan(M_PI*angle/180) * x); + qreal x = 0; + qreal y = 0; - if (angle > 90 && angle <= 180) - { - x = -x; + qreal angleRad = qDegreesToRadians(angle); + const int n = GetQuadransRad(angleRad); + if (VFuzzyComparePossibleNulls(angleRad, 0) || VFuzzyComparePossibleNulls(angleRad, M_2PI) || + VFuzzyComparePossibleNulls(angleRad, -M_2PI)) + { // 0 (360, -360) degress + x = d->radius1; + y = 0; } - else if (angle > 180 && angle < 270) - { - x = -x; - y = -y; - } - else if (angle > 270) - { - y = -y; - } - else if (VFuzzyComparePossibleNulls(angle, 90)) - { + else if (VFuzzyComparePossibleNulls(angleRad, M_PI_2) || VFuzzyComparePossibleNulls(angleRad, -3 * M_PI_2)) + { // 90 (-270) degress x = 0; y = d->radius2; } - else if (VFuzzyComparePossibleNulls(angle, 270)) - { + else if (VFuzzyComparePossibleNulls(angleRad, M_PI) || VFuzzyComparePossibleNulls(angleRad, -M_PI)) + { // 180 (-180) degress + x = -d->radius1; + y = 0; + } + else if (VFuzzyComparePossibleNulls(angleRad, 3 * M_PI_2) || VFuzzyComparePossibleNulls(angleRad, -M_PI_2)) + { // 270 (-90) degress x = 0; y = -d->radius2; } - QPointF p ( GetCenter().x () + x, GetCenter().y () + y); + else + { // cases between + const qreal r1Pow = qPow(d->radius1, 2); + const qreal r2Pow = qPow(d->radius2, 2); + const qreal angleTan = qTan(angleRad); + const qreal angleTan2 = qPow(angleTan, 2); + x = qSqrt((r1Pow * r2Pow) / (r1Pow * angleTan2 + r2Pow)); + y = angleTan * x; + } + + switch (n) + { + case 1: + x = +x; + y = +y; + break; + case 2: + x = -x; + y = +y; + break; + case 3: + x = -x; + y = -y; + break; + case 4: + x = +x; + y = -y; + break; + default: + break; + } + + QPointF p (GetCenter().x() + x, GetCenter().y() + y); // rotation of point - QLineF line(GetCenter().toQPointF(), p); + QLineF line(GetCenter(), p); line.setAngle(line.angle() + GetRotationAngle()); return line.p2(); } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AngleArc calculate arc angle. - * @return angle in degree. - */ -qreal VEllipticalArc::AngleArc() const +int VEllipticalArc::GetQuadransRad(qreal &rad) { - if ((qFuzzyIsNull(d->f1) && qFuzzyCompare(d->f2, 360)) || - (qFuzzyCompare(d->f1, 360) && qFuzzyIsNull(d->f2))) + if (rad > M_PI) { - return 360; - } - QLineF l1(0, 0, 100, 100); - l1.setAngle(d->f1); - QLineF l2(0, 0, 100, 100); - l2.setAngle(d->f2); - - qreal ang = l1.angleTo(l2); - - if (d->isFlipped) - { - ang = 360 - ang; + rad = rad - M_2PI; } - return ang; + if (rad < -M_PI) + { + rad = rad + M_2PI; + } + + int n = 0; + if (rad > 0) + { + if (rad >= 0 && rad <= M_PI_2) + { + n = 1; + rad = -rad; + } + else if (rad > M_PI_2 && rad <= M_PI) + { + n = 2; + rad = M_PI+rad; + } + } + else + { + if (rad <= 0 && rad >= -M_PI_2) + { + n = 4; + } + else if (rad < -M_PI_2 && rad >= -M_PI) + { + n = 3; + rad = M_PI-rad; + } + } + return n; } //--------------------------------------------------------------------------------------------------------------------- @@ -247,7 +306,7 @@ QVector VEllipticalArc::GetAngles() const if (qFuzzyIsNull(angle)) {// Return the array that includes one angle - sectionAngle.append(d->f1); + sectionAngle.append(GetStartAngle()); return sectionAngle; } @@ -284,7 +343,7 @@ QVector VEllipticalArc::GetPoints() const QVector sectionAngle = GetAngles(); qreal currentAngle; - d->isFlipped ? currentAngle = GetEndAngle() : currentAngle = GetStartAngle(); + IsFlipped() ? currentAngle = GetEndAngle() : currentAngle = GetStartAngle(); for (int i = 0; i < sectionAngle.size(); ++i) { QPointF startPoint = GetPoint(currentAngle); @@ -348,13 +407,13 @@ QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllip } // the first arc has given length and startAngle just like in the origin arc - arc1 = VEllipticalArc (len, QString().setNum(length), d->center, d->radius1, d->radius2, - d->formulaRadius1, d->formulaRadius2, d->f1, d->formulaF1, d->rotationAngle, + arc1 = VEllipticalArc (len, QString().setNum(length), GetCenter(), d->radius1, d->radius2, + d->formulaRadius1, d->formulaRadius2, GetStartAngle(), GetFormulaF1(), d->rotationAngle, getIdObject(), getMode()); // the second arc has startAngle just like endAngle of the first arc // and it has endAngle just like endAngle of the origin arc - arc2 = VEllipticalArc (d->center, d->radius1, d->radius2, d->formulaRadius1, d->formulaRadius2, - arc1.GetEndAngle(), arc1.GetFormulaF2(), d->f2, d->formulaF2, d->rotationAngle, + arc2 = VEllipticalArc (GetCenter(), d->radius1, d->radius2, d->formulaRadius1, d->formulaRadius2, + arc1.GetEndAngle(), arc1.GetFormulaF2(), GetEndAngle(), GetFormulaF2(), d->rotationAngle, getIdObject(), getMode()); return arc1.GetP1(); } @@ -368,34 +427,6 @@ QPointF VEllipticalArc::CutArc(const qreal &length) const return this->CutArc(length, arc1, arc2); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setId keep id arc in data. - * @param id id arc in data. - */ -void VEllipticalArc::setId(const quint32 &id) -{ - VAbstractCurve::setId(id); - CreateName(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VEllipticalArc::NameForHistory(const QString &toolName) const -{ - QString name = toolName + QString(" %1").arg(this->GetCenter().name()); - - if (VAbstractCurve::id() != NULL_ID) - { - name += QString("_%1").arg(VAbstractCurve::id()); - } - - if (GetDuplicate() > 0) - { - name += QString("_%1").arg(GetDuplicate()); - } - return name; -} - //--------------------------------------------------------------------------------------------------------------------- void VEllipticalArc::CreateName() { @@ -420,7 +451,7 @@ void VEllipticalArc::FindF2(qreal length) qreal gap = 180; if (length < 0) { - d->isFlipped = true; + SetFlipped(true); gap = -gap; } while (length > MaxLength()) @@ -432,15 +463,21 @@ void VEllipticalArc::FindF2(qreal length) // first approximation of angle between start and end angles qreal endAngle = GetStartAngle() + gap; - d->f2 = endAngle; // we need to set the end anngle, because we want to use GetLength() + + // we need to set the end angle, because we want to use GetLength() + SetFormulaF2(QString::number(endAngle), endAngle); qreal lenBez = GetLength(); // first approximation of length - qreal eps = 0.001 * qAbs(length); + const qreal eps = ToPixel(0.1, Unit::Mm); while (qAbs(lenBez - length) > eps) { gap = gap/2; + if (gap < 0.0001) + { + break; + } if (lenBez > length) { // we selected too big end angle endAngle = endAngle - qAbs(gap); @@ -450,75 +487,21 @@ void VEllipticalArc::FindF2(qreal length) endAngle = endAngle + qAbs(gap); } // we need to set d->f2, because we use it when we calculate GetLength - d->f2 = endAngle; + SetFormulaF2(QString::number(endAngle), endAngle); lenBez = GetLength(); } - d->formulaF2 = QString().number(d->f2); - d->formulaLength = QString().number(qApp->fromPixel(lenBez)); + SetFormulaF2(QString::number(endAngle), endAngle); + SetFormulaLength(QString::number(qApp->fromPixel(lenBez))); } //--------------------------------------------------------------------------------------------------------------------- qreal VEllipticalArc::MaxLength() const { - const qreal h = ((d->radius1-d->radius2)*(d->radius1-d->radius2))/((d->radius1+d->radius2)*(d->radius1+d->radius2)); - const qreal ellipseLength = M_PI*(d->radius1+d->radius2)*(1+3*h/(10+qSqrt(4-3*h))); + const qreal h = qPow(d->radius1 - d->radius2, 2) / qPow(d->radius1 + d->radius2, 2); + const qreal ellipseLength = M_PI * (d->radius1 + d->radius2) * (1+3*h/(10+qSqrt(4-3*h))); return ellipseLength; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF1 return start angle. - * @return angle in degree. - */ -QString VEllipticalArc::GetFormulaF1() const -{ - return d->formulaF1; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VEllipticalArc::SetFormulaF1(const QString &formula, qreal value) -{ - d->formulaF1 = formula; - d->f1 = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF1 return formula for start angle. - * @return string with formula. - */ -qreal VEllipticalArc::GetStartAngle() const -{ - return d->f1; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF2 return end angle. - * @return angle in degree. - */ -QString VEllipticalArc::GetFormulaF2() const -{ - return d->formulaF2; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VEllipticalArc::SetFormulaF2(const QString &formula, qreal value) -{ - d->formulaF2 = formula; - d->f2 = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetF2 return formula for end angle. - * @return string with formula. - */ -qreal VEllipticalArc::GetEndAngle() const -{ - return d->f2; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetRadius return arc major radius. @@ -582,32 +565,3 @@ qreal VEllipticalArc::GetRadius2() const { return d->radius2; } - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetCenter return center point. - * @return center point. - */ -VPointF VEllipticalArc::GetCenter() const -{ - return d->center; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VEllipticalArc::SetCenter(const VPointF &value) -{ - d->center = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VEllipticalArc::GetFormulaLength() const -{ - return d->formulaLength; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VEllipticalArc::SetFormulaLength(const QString &formula, qreal value) -{ - d->formulaLength = formula; - FindF2(value); -} diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index a52ac3884..064060a86 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -29,78 +29,63 @@ #ifndef VELLIPTICALARC_H #define VELLIPTICALARC_H -#include "vabstractcurve.h" +#include "vabstractarc.h" #include "vpointf.h" #include class VEllipticalArcData; -class VEllipticalArc : public VAbstractCurve +class VEllipticalArc : public VAbstractArc { Q_DECLARE_TR_FUNCTIONS(VEllipticalArc) public: VEllipticalArc(); - VEllipticalArc (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, - qreal f1, QString formulaF1, qreal f2, QString formulaF2, qreal rotationAngle, - quint32 idObject = 0, Draw mode = Draw::Calculation); - - VEllipticalArc (VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle); - - VEllipticalArc (qreal length, QString formulaLength, VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, - qreal rotationAngle, quint32 idObject = 0, Draw mode = Draw::Calculation); - - VEllipticalArc (qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle); + VEllipticalArc (const VPointF ¢er, qreal radius1, qreal radius2, const QString &formulaRadius1, + const QString &formulaRadius2, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2, qreal rotationAngle, quint32 idObject = 0, Draw mode = Draw::Calculation); + VEllipticalArc (const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle); + VEllipticalArc (qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius1, qreal radius2, + const QString &formulaRadius1, const QString &formulaRadius2, qreal f1, const QString &formulaF1, + qreal rotationAngle, quint32 idObject = 0, Draw mode = Draw::Calculation); + VEllipticalArc (qreal length, const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle); VEllipticalArc(const VEllipticalArc &arc); VEllipticalArc& operator= (const VEllipticalArc &arc); + VEllipticalArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; virtual ~VEllipticalArc() Q_DECL_OVERRIDE; - QString GetFormulaF1 () const; - void SetFormulaF1 (const QString &formula, qreal value); - virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; + qreal GetRotationAngle() const; - QString GetFormulaF2 () const; - void SetFormulaF2 (const QString &formula, qreal value); - virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; + QString GetFormulaRadius1 () const; + void SetFormulaRadius1 (const QString &formula, qreal value); + qreal GetRadius1 () const; - qreal GetRotationAngle() const; + QString GetFormulaRadius2 () const; + void SetFormulaRadius2 (const QString &formula, qreal value); + qreal GetRadius2 () const; - QString GetFormulaRadius1 () const; - void SetFormulaRadius1 (const QString &formula, qreal value); - qreal GetRadius1 () const; + virtual qreal GetLength () const Q_DECL_OVERRIDE; - QString GetFormulaRadius2 () const; - void SetFormulaRadius2 (const QString &formula, qreal value); - qreal GetRadius2 () const; + QPointF GetP1() const; + QPointF GetP2() const; - VPointF GetCenter () const; - void SetCenter (const VPointF &value); - - QString GetFormulaLength () const; - void SetFormulaLength (const QString &formula, qreal value); - virtual qreal GetLength () const Q_DECL_OVERRIDE; - - QPointF GetP1() const; - QPointF GetP2 () const; - - qreal AngleArc() const; - QVector GetAngles () const; virtual QVector GetPoints () const Q_DECL_OVERRIDE; - QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; - QPointF CutArc (const qreal &length) const; - virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; - virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; + + QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; + QPointF CutArc (const qreal &length) const; protected: virtual void CreateName() Q_DECL_OVERRIDE; + virtual void FindF2(qreal length) Q_DECL_OVERRIDE; private: QSharedDataPointer d; - void FindF2(qreal length); - qreal MaxLength() const; - QPointF GetPoint (qreal angle) const; + QVector GetAngles () const; + qreal MaxLength() const; + QPointF GetPoint (qreal angle) const; + + static int GetQuadransRad(qreal &rad); }; Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE); diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h index 03e2fc6fe..aa3c04194 100644 --- a/src/libs/vgeometry/vellipticalarc_p.h +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -13,81 +13,68 @@ class VEllipticalArcData : public QSharedData { public: - - VEllipticalArcData () - : f1(0), f2(0), formulaF1(QString()), formulaF2(QString()), - radius1(0), radius2(0), formulaRadius1(QString()), formulaRadius2(QString()), - center(VPointF()), isFlipped(false), formulaLength(), rotationAngle(0) - {} - - VEllipticalArcData (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, - qreal f1, QString formulaF1, qreal f2, QString formulaF2, qreal rotationAngle) - : f1(f1), f2(f2), formulaF1(formulaF1), formulaF2(formulaF2), - radius1(radius1), radius2(radius2), formulaRadius1(formulaRadius1), formulaRadius2(formulaRadius2), - center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) - {} - - VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle) - : f1(f1), f2(f2), formulaF1(QString().number(f1)), - formulaF2(QString().number(f2)), radius1(radius1), radius2(radius2), - formulaRadius1(QString().number(qApp->fromPixel(radius1))), - formulaRadius2(QString().number(qApp->fromPixel(radius2))), - center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) - {} - - VEllipticalArcData (QString formulaLength, VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, - qreal rotationAngle) - : f1(f1), f2(0), formulaF1(formulaF1), formulaF2("0"), radius1(radius1),radius2(radius2), - formulaRadius1(formulaRadius1), formulaRadius2(formulaRadius2), - center(center), isFlipped(false), formulaLength(formulaLength), rotationAngle(rotationAngle) - {} - - VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle) - : f1(f1), f2(0), formulaF1(QString().number(f1)), formulaF2("0"), - radius1(radius1), radius2(radius2), - formulaRadius1(QString().number(qApp->fromPixel(radius1))), - formulaRadius2(QString().number(qApp->fromPixel(radius2))), - center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) - {} - - VEllipticalArcData(const VEllipticalArcData &arc) - : QSharedData(arc), f1(arc.f1), f2(arc.f2), formulaF1(arc.formulaF1), formulaF2(arc.formulaF2), - radius1(arc.radius1), radius2(arc.radius2), - formulaRadius1(arc.formulaRadius1), formulaRadius2(arc.formulaRadius2), - center(arc.center), isFlipped(arc.isFlipped), formulaLength(arc.formulaLength), - rotationAngle(arc.rotationAngle) - {} + VEllipticalArcData (); + VEllipticalArcData (qreal radius1, qreal radius2, const QString &formulaRadius1, const QString &formulaRadius2, + qreal rotationAngle); + VEllipticalArcData(qreal radius1, qreal radius2, qreal rotationAngle); + VEllipticalArcData(const VEllipticalArcData &arc); virtual ~VEllipticalArcData(); - /** @brief f1 start angle in degree. */ - qreal f1; - /** @brief f2 end angle in degree. */ - qreal f2; - /** @brief formulaF1 formula for start angle. */ - QString formulaF1; - /** @brief formulaF2 formula for end angle. */ - QString formulaF2; /** @brief radius1 elliptical arc major radius. */ - qreal radius1; + qreal radius1; /** @brief radius2 elliptical arc minor radius. */ - qreal radius2; + qreal radius2; /** @brief formulaRadius1 formula for elliptical arc major radius. */ - QString formulaRadius1; + QString formulaRadius1; /** @brief formulaRadius2 formula for elliptical arc minor radius. */ - QString formulaRadius2; - /** @brief center center point of arc. */ - VPointF center; - bool isFlipped; - QString formulaLength; + QString formulaRadius2; /** @brief rotationAngle in degree. */ - qreal rotationAngle; + qreal rotationAngle; private: VEllipticalArcData &operator=(const VEllipticalArcData &) Q_DECL_EQ_DELETE; }; +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArcData::VEllipticalArcData() + : radius1(0), + radius2(0), + formulaRadius1(), + formulaRadius2(), + rotationAngle(0) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArcData::VEllipticalArcData(qreal radius1, qreal radius2, const QString &formulaRadius1, + const QString &formulaRadius2, qreal rotationAngle) + : radius1(radius1), + radius2(radius2), + formulaRadius1(formulaRadius1), + formulaRadius2(formulaRadius2), + rotationAngle(rotationAngle) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArcData::VEllipticalArcData(qreal radius1, qreal radius2, qreal rotationAngle) + : radius1(radius1), + radius2(radius2), + formulaRadius1(QString().number(qApp->fromPixel(radius1))), + formulaRadius2(QString().number(qApp->fromPixel(radius2))), + rotationAngle(rotationAngle) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArcData::VEllipticalArcData(const VEllipticalArcData &arc) + : QSharedData(arc), + radius1(arc.radius1), + radius2(arc.radius2), + formulaRadius1(arc.formulaRadius1), + formulaRadius2(arc.formulaRadius2), + rotationAngle(arc.rotationAngle) +{} + +//--------------------------------------------------------------------------------------------------------------------- VEllipticalArcData::~VEllipticalArcData() {} diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index 60586d110..2b05f9b20 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -13,7 +13,8 @@ SOURCES += \ $$PWD/vcubicbezier.cpp \ $$PWD/vabstractcubicbezier.cpp \ $$PWD/vabstractcubicbezierpath.cpp \ - $$PWD/vcubicbezierpath.cpp + $$PWD/vcubicbezierpath.cpp \ + $$PWD/vabstractarc.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -41,4 +42,6 @@ HEADERS += \ $$PWD/vabstractcubicbezier.h \ $$PWD/vabstractcubicbezierpath.h \ $$PWD/vcubicbezierpath.h \ - $$PWD/vcubicbezierpath_p.h + $$PWD/vcubicbezierpath_p.h \ + $$PWD/vabstractarc.h \ + $$PWD/vabstractarc_p.h diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index f083d1353..ae9d200a5 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -29,8 +29,6 @@ #ifndef VGEOMETRYDEF_H #define VGEOMETRYDEF_H -#include - enum class Draw : char { Calculation, Modeling, Layout }; enum class GOType : char { Point, Arc, EllipticalArc, Spline, SplinePath, CubicBezier, CubicBezierPath, Unknown }; enum class SplinePointPosition : char { FirstPoint, LastPoint }; diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index 2eca45687..9355610d2 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -506,7 +506,7 @@ double VGObject::GetEpsilon(const QPointF &p1, const QPointF &p2) { const double dx1 = p2.x() - p1.x(); const double dy1 = p2.y() - p1.y(); - const double epsilon = 0.03 * (dx1 * dx1 + dy1 * dy1); //-V636 + const double epsilon = 0.06 * (dx1 * dx1 + dy1 * dy1); //-V636 return epsilon; } diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index bd58c4170..99ea48418 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -85,13 +85,13 @@ public: static QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k); static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); static bool IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2); + static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2); static QVector GetReversePoints(const QVector &points); static int GetLengthContour(const QVector &contour, const QVector &newPoints); private: QSharedDataPointer d; - static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2); static double PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPointF &t); static double GetEpsilon(const QPointF &p1, const QPointF &p2); diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index b37f4e95e..67de60447 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -28,6 +28,7 @@ #include "vpointf.h" #include "vpointf_p.h" +#include #include #include @@ -100,13 +101,16 @@ VPointF &VPointF::operator =(const VPointF &point) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief toQPointF convert to QPointF - * @return QPointF point - */ -QPointF VPointF::toQPointF() const +VPointF::operator QPointF() const { - return QPointF(d->_x, d->_y); + return toQPointF(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + const QPointF p = RotatePF(originPoint, toQPointF(), degrees); + return VPointF(p, name() + prefix, mx(), my()); } //--------------------------------------------------------------------------------------------------------------------- @@ -149,6 +153,12 @@ void VPointF::setMy(qreal my) d->_my = my; } +//--------------------------------------------------------------------------------------------------------------------- +QPointF VPointF::toQPointF() const +{ + return QPointF(d->_x, d->_y); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief x return x coordinate @@ -188,3 +198,11 @@ void VPointF::setY(const qreal &value) { d->_y = value; } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees) +{ + QLineF axis(originPoint, point); + axis.setAngle(axis.angle() + degrees); + return axis.p2(); +} diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 7494a1405..904af4b05 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -58,6 +58,8 @@ public: const Draw &mode = Draw::Calculation); virtual ~VPointF() Q_DECL_OVERRIDE; VPointF &operator=(const VPointF &point); + operator QPointF() const; + VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; qreal mx() const; qreal my() const; void setMx(qreal mx); @@ -67,6 +69,8 @@ public: void setX(const qreal &value); qreal y() const; void setY(const qreal &value); + + static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); private: QSharedDataPointer d; }; diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 51d1b839a..5cd4b8fc9 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -101,12 +101,26 @@ VSpline::VSpline(VPointF p1, VPointF p4, qreal angle1, const QString &angle1Form const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length, const QString &c2LengthFormula, quint32 idObject, Draw mode) : VAbstractCubicBezier(GOType::Spline, idObject, mode), - d(new VSplineData(p1, p4, angle1, angle1Formula, angle2,angle2Formula, c1Length, c1LengthFormula, c2Length, + d(new VSplineData(p1, p4, angle1, angle1Formula, angle2, angle2Formula, c1Length, c1LengthFormula, c2Length, c2LengthFormula)) { CreateName(); } +//--------------------------------------------------------------------------------------------------------------------- +VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + const VPointF p1 = GetP1().Rotate(originPoint, degrees); + const VPointF p4 = GetP4().Rotate(originPoint, degrees); + + const QPointF p2 = VPointF::RotatePF(originPoint, GetP2(), degrees); + const QPointF p3 = VPointF::RotatePF(originPoint, GetP3(), degrees); + + VSpline spl(p1, p2, p3, p4); + spl.setName(name() + prefix); + return spl; +} + //--------------------------------------------------------------------------------------------------------------------- VSpline::~VSpline() {} @@ -118,7 +132,7 @@ VSpline::~VSpline() */ qreal VSpline::GetLength () const { - return LengthBezier ( GetP1().toQPointF(), GetP2(), GetP3(), GetP4().toQPointF()); + return LengthBezier ( GetP1(), GetP2(), GetP3(), GetP4()); } //--------------------------------------------------------------------------------------------------------------------- @@ -142,7 +156,7 @@ QPointF VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2) const */ QVector VSpline::GetPoints () const { - return GetCubicBezierPoints(GetP1().toQPointF(), GetP2(), GetP3(), GetP4().toQPointF()); + return GetCubicBezierPoints(GetP1(), GetP2(), GetP3(), GetP4()); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,7 +348,7 @@ void VSpline::SetC2Length(qreal length, const QString &formula) */ qreal VSpline::GetKasm1() const { - return QLineF(d->p1.toQPointF(), GetP2()).length() / VSplineData::GetL(d->p1.toQPointF(), d->p4.toQPointF(), + return QLineF(d->p1, GetP2()).length() / VSplineData::GetL(d->p1, d->p4, d->kCurve); } @@ -345,7 +359,7 @@ qreal VSpline::GetKasm1() const */ qreal VSpline::GetKasm2() const { - return QLineF(d->p4.toQPointF(), GetP3()).length() / VSplineData::GetL(d->p1.toQPointF(), d->p4.toQPointF(), + return QLineF(d->p4, GetP3()).length() / VSplineData::GetL(d->p1, d->p4, d->kCurve); } @@ -455,8 +469,8 @@ qreal VSpline::ParamT (const QPointF &pBt) const { QVector ts; // Calculate t coefficient for each axis - ts += CalcT (GetP1().toQPointF().x(), GetP2().x(), GetP3().x(), GetP4().toQPointF().x(), pBt.x()); - ts += CalcT (GetP1().toQPointF().y(), GetP2().y(), GetP3().y(), GetP4().toQPointF().y(), pBt.y()); + ts += CalcT (GetP1().x(), GetP2().x(), GetP3().x(), GetP4().x(), pBt.x()); + ts += CalcT (GetP1().y(), GetP2().y(), GetP3().y(), GetP4().y(), pBt.y()); if (ts.isEmpty()) { @@ -471,10 +485,10 @@ qreal VSpline::ParamT (const QPointF &pBt) const for (int i=0; i< ts.size(); ++i) { const qreal t = ts.at(i); - const QPointF p0 = GetP1().toQPointF(); + const QPointF p0 = GetP1(); const QPointF p1 = GetP2(); const QPointF p2 = GetP3(); - const QPointF p3 = GetP4().toQPointF(); + const QPointF p3 = GetP4(); //The explicit form of the Cubic Bézier curve const qreal pointX = pow(1-t, 3)*p0.x() + 3*pow(1-t, 2)*t*p1.x() + 3*(1-t)*pow(t, 2)*p2.x() + pow(t, 3)*p3.x(); const qreal pointY = pow(1-t, 3)*p0.y() + 3*pow(1-t, 2)*t*p1.y() + 3*(1-t)*pow(t, 2)*p2.y() + pow(t, 3)*p3.y(); diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index c92e4f907..5b0de7ac7 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -52,6 +52,7 @@ public: VSpline (VPointF p1, VPointF p4, qreal angle1, const QString &angle1Formula, qreal angle2, const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length, const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation); + VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; virtual ~VSpline(); VSpline &operator=(const VSpline &spl); diff --git a/src/libs/vgeometry/vspline_p.h b/src/libs/vgeometry/vspline_p.h index c8e6e02ba..c8d59e6ba 100644 --- a/src/libs/vgeometry/vspline_p.h +++ b/src/libs/vgeometry/vspline_p.h @@ -136,7 +136,7 @@ VSplineData::VSplineData(VPointF p1, VPointF p4, qreal angle1, qreal angle2, qre c2LengthF("0"), kCurve(kCurve) { - const qreal L = GetL(p1.toQPointF(), p4.toQPointF(), kCurve); + const qreal L = GetL(p1, p4, kCurve); QLineF p1p2(p1.x(), p1.y(), p1.x() + L * kAsm1, p1.y()); p1p2.setAngle(angle1); @@ -163,7 +163,7 @@ VSplineData::VSplineData(VPointF p1, QPointF p2, QPointF p3, VPointF p4) c2LengthF("0"), kCurve(1) { - QLineF p1p2(p1.toQPointF(), p2); + QLineF p1p2(p1, p2); angle1 = p1p2.angle(); angle1F = QString().number(angle1); @@ -171,7 +171,7 @@ VSplineData::VSplineData(VPointF p1, QPointF p2, QPointF p3, VPointF p4) c1Length = p1p2.length(); c1LengthF = QString().number(qApp->fromPixel(c1Length)); - QLineF p4p3(p4.toQPointF(), p3); + QLineF p4p3(p4, p3); angle2 = p4p3.angle(); angle2F = QString().number(angle2); diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 64a2a5590..f210ccbe4 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -57,12 +57,7 @@ VSplinePath::VSplinePath(const QVector &points, qreal kCurve, qui return; } - QVector newPoints; - for (int i=0; i < points.size(); ++i) - { - newPoints.append(VSplinePoint()); - } - + QVector newPoints(points.size()); for (qint32 i = 1; i <= points.size()-1; ++i) { const VFSplinePoint &p1 = points.at(i-1); @@ -106,6 +101,30 @@ VSplinePath::VSplinePath(const VSplinePath &splPath) d(splPath.d) {} +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VSplinePath::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +{ + QVector newPoints(CountPoints()); + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + const VSplinePoint &p1 = d->path.at(i-1); + const VSplinePoint &p2 = d->path.at(i); + VSpline spl = GetSpline(i).Rotate(originPoint, degrees); + + newPoints[i-1].SetP(p1.P()); + newPoints[i-1].SetAngle2(p1.Angle2(), spl.GetStartAngleFormula()); + newPoints[i-1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula()); + + newPoints[i].SetP(p2.P()); + newPoints[i].SetAngle1(p2.Angle1(), spl.GetEndAngleFormula()); + newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula()); + } + + VSplinePath splPath(newPoints); + splPath.setName(name() + prefix); + return splPath; +} + //--------------------------------------------------------------------------------------------------------------------- VSplinePath::~VSplinePath() {} @@ -117,7 +136,7 @@ VSplinePath::~VSplinePath() */ void VSplinePath::append(const VSplinePoint &point) { - if (d->path.size() > 0 && d->path.last().P().toQPointF() == point.P().toQPointF()) //-V807 + if (d->path.size() > 0 && d->path.last().P() == point.P()) //-V807 { return; } diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index a683065c1..2b0b7608b 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -50,6 +50,7 @@ public: Draw mode = Draw::Calculation); VSplinePath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); VSplinePath(const VSplinePath& splPath); + VSplinePath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; virtual ~VSplinePath() Q_DECL_OVERRIDE; VSplinePath &operator=(const VSplinePath &path); diff --git a/src/libs/vlayout/vabstractdetail.cpp b/src/libs/vlayout/vabstractdetail.cpp index 3e65dafe2..c820722d1 100644 --- a/src/libs/vlayout/vabstractdetail.cpp +++ b/src/libs/vlayout/vabstractdetail.cpp @@ -29,6 +29,8 @@ #include "vabstractdetail.h" #include "vabstractdetail_p.h" +#include "../vgeometry/vgobject.h" + #include #include #include @@ -327,37 +329,83 @@ QVector VAbstractDetail::CheckLoops(const QVector &points) continue; } + enum LoopIntersectType { NoIntersection, BoundedIntersection, ParallelIntersection }; + QPointF crosPoint; - QLineF::IntersectType intersect = QLineF::NoIntersection; + LoopIntersectType status = NoIntersection; const QLineF line1(points.at(i), points.at(i+1)); // Because a path can contains several loops we will seek the last and only then remove the loop(s) // That's why we parse from the end for (j = count-2; j >= i+2; --j) { const QLineF line2(points.at(j), points.at(j+1)); - intersect = line1.intersect(line2, &crosPoint); - if (intersect == QLineF::BoundedIntersection && not (i == 0 && j+1 == count-1 && closed)) + const QLineF::IntersectType intersect = line1.intersect(line2, &crosPoint); + if (intersect == QLineF::NoIntersection) + { // According to the documentation QLineF::NoIntersection indicates that the lines do not intersect; + // i.e. they are parallel. But parallel also mean they can be on the same line. + // Method IsPointOnLineviaPDP will check it. + if (VGObject::IsPointOnLineviaPDP(points.at(j), points.at(i), points.at(i+1)) + // Next cases are valid for us. + && line1.p2() != line2.p2() + && line1.p1() != line2.p1() + && line1.p2() != line2.p1() + && line1.p1() != line2.p2()) + { + // Left to catch case where segments are on the same line, but do not have real intersections. + QLineF tmpLine1 = line1; + QLineF tmpLine2 = line2; + + tmpLine1.setAngle(tmpLine1.angle()+90); + + QPointF tmpCrosPoint; + const QLineF::IntersectType tmpIntrs1 = tmpLine1.intersect(tmpLine2, &tmpCrosPoint); + + tmpLine1 = line1; + tmpLine2.setAngle(tmpLine2.angle()+90); + + const QLineF::IntersectType tmpIntrs2 = tmpLine1.intersect(tmpLine2, &tmpCrosPoint); + + if (tmpIntrs1 == QLineF::BoundedIntersection || tmpIntrs2 == QLineF::BoundedIntersection) + { // Now we really sure that lines are on the same lines and have real intersections. + status = ParallelIntersection; + break; + } + } + } + else if (intersect == QLineF::BoundedIntersection && not (i == 0 && j+1 == count-1 && closed)) { // Break, but not if intersects the first edge and the last edge in closed path if (line1.p1() != crosPoint && line1.p2() != crosPoint && line2.p1() != crosPoint && line2.p2() != crosPoint) { // Break, but not if loop creates crosPoint when it is first or last point of lines + status = BoundedIntersection; break; } } - intersect = QLineF::NoIntersection; + status = NoIntersection; } - if (intersect == QLineF::BoundedIntersection) + switch (status) { - /*We have found loop.*/ - ekvPoints.append(points.at(i)); - ekvPoints.append(crosPoint); - i = j; - } - else - { - /*We have not found loop.*/ - ekvPoints.append(points.at(i)); + case ParallelIntersection: + /*We have found a loop.*/ + // Theoretically there is no big difference which point j or j+1 to select. + // In the end we will draw a line in any case. + ekvPoints.append(points.at(i)); + ekvPoints.append(points.at(j+1)); + i = j; + break; + case BoundedIntersection: + /*We have found a loop.*/ + ekvPoints.append(points.at(i)); + ekvPoints.append(crosPoint); + i = j; + break; + case NoIntersection: + /*We have not found loop.*/ + ekvPoints.append(points.at(i)); + break; + default: + break; } } return ekvPoints; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 9aa894976..2353e421f 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -102,6 +102,7 @@ enum class Tool : ToolVisHolderType TrueDarts, UnionDetails, Group, + Rotation, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -110,6 +111,7 @@ enum class Vis : ToolVisHolderType ControlPointSpline = static_cast(Tool::LAST_ONE_DO_NOT_USE), GraphicsSimpleTextItem, SimplePoint, + SimpleCurve, Line, Path, ToolAlongLine, @@ -139,7 +141,8 @@ enum class Vis : ToolVisHolderType ToolCutSplinePath, ToolLineIntersectAxis, ToolCurveIntersectAxis, - ToolTrueDarts + ToolTrueDarts, + ToolRotation }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, LineAngle, CurveAngle, ArcRadius, @@ -629,4 +632,95 @@ static inline bool VFuzzyComparePossibleNulls(double p1, double p2) } } +/**************************************************************************** +** This file is derived from code bearing the following notice: +** The sole author of this file, Adam Higerd, has explicitly disclaimed all +** copyright interest and protection for the content within. This file has +** been placed in the public domain according to United States copyright +** statute and case law. In jurisdictions where this public domain dedication +** is not legally recognized, anyone who receives a copy of this file is +** permitted to use, modify, duplicate, and redistribute this file, in whole +** or in part, with no restrictions or conditions. In these jurisdictions, +** this file shall be copyright (C) 2006-2008 by Adam Higerd. +****************************************************************************/ + +#define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface qxt_d; +#define QXT_DECLARE_PUBLIC(PUB) friend class PUB; +#define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this); +#define QXT_D(PUB) PUB##Private& d = qxt_d() +#define QXT_P(PUB) PUB& p = qxt_p() + +template +class QxtPrivate +{ +public: + QxtPrivate(): qxt_p_ptr(nullptr) + {} + virtual ~QxtPrivate() + {} + inline void QXT_setPublic(PUB* pub) + { + qxt_p_ptr = pub; + } + +protected: + inline PUB& qxt_p() + { + return *qxt_p_ptr; + } + inline const PUB& qxt_p() const + { + return *qxt_p_ptr; + } + inline PUB* qxt_ptr() + { + return qxt_p_ptr; + } + inline const PUB* qxt_ptr() const + { + return qxt_p_ptr; + } + +private: + Q_DISABLE_COPY(QxtPrivate) + PUB* qxt_p_ptr; +}; + +template +class QxtPrivateInterface +{ + friend class QxtPrivate; +public: + QxtPrivateInterface() : pvt(new PVT) + {} + ~QxtPrivateInterface() + { + delete pvt; + } + + inline void setPublic(PUB* pub) + { + pvt->QXT_setPublic(pub); + } + inline PVT& operator()() + { + return *static_cast(pvt); + } + inline const PVT& operator()() const + { + return *static_cast(pvt); + } + inline PVT * operator->() + { + return static_cast(pvt); + } + inline const PVT * operator->() const + { + return static_cast(pvt); + } +private: + Q_DISABLE_COPY(QxtPrivateInterface) + QxtPrivate* pvt; +}; + #endif // DEF_H diff --git a/src/libs/vmisc/qxtcsvmodel.cpp b/src/libs/vmisc/qxtcsvmodel.cpp new file mode 100644 index 000000000..a413a066c --- /dev/null +++ b/src/libs/vmisc/qxtcsvmodel.cpp @@ -0,0 +1,729 @@ +/**************************************************************************** +** Copyright (c) 2006 - 2011, the LibQxt project. +** See the Qxt AUTHORS file for a list of authors and copyright holders. +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the LibQxt project nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +** +*****************************************************************************/ + +/*! +\class QxtCsvModel +\brief The QxtCsvModel class provides a QAbstractTableModel for CSV Files + */ + +#include "qxtcsvmodel.h" + +#include +#include +#include + +class QxtCsvModelPrivate : public QxtPrivate +{ +public: + QxtCsvModelPrivate() : csvData(), header(), maxColumn(0), quoteMode(QxtCsvModel::DefaultQuoteMode) + {} + QXT_DECLARE_PUBLIC(QxtCsvModel) + + QList csvData; + QStringList header; + int maxColumn; + QxtCsvModel::QuoteMode quoteMode; +}; + +#ifdef Q_CC_GNU + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Weffc++" +#endif + +/*! + Creates an empty QxtCsvModel with parent \a parent. + */ +QxtCsvModel::QxtCsvModel(QObject *parent) : QAbstractTableModel(parent) +{ + QXT_INIT_PRIVATE(QxtCsvModel); +} + +/*! + Creates a QxtCsvModel with the parent \a parent and content loaded from \a file. + + See \a setSource for information on the \a withHeader and \a separator properties, or + if you need control over the quoting method or codec used to parse the file. + + \sa setSource + */ +QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent, bool withHeader, QChar separator) + : QAbstractTableModel(parent) +{ + QXT_INIT_PRIVATE(QxtCsvModel); + setSource(file, withHeader, separator); +} + +/*! + \overload + + Creates a QxtCsvModel with the parent \a parent and content loaded from \a file. + + See \a setSource for information on the \a withHeader and \a separator properties, or + if you need control over the quoting method or codec used to parse the file. + + \sa setSource + */ +QxtCsvModel::QxtCsvModel(const QString filename, QObject *parent, bool withHeader, QChar separator) + : QAbstractTableModel(parent) +{ + QXT_INIT_PRIVATE(QxtCsvModel); + QFile src(filename); + setSource(&src, withHeader, separator); +} + +#ifdef Q_CC_GNU +#pragma GCC diagnostic pop +#endif + +QxtCsvModel::~QxtCsvModel() +{} + +/*! + \reimp + */ +int QxtCsvModel::rowCount(const QModelIndex& parent) const +{ + if (parent.row() != -1 && parent.column() != -1) + { + return 0; + } + return qxt_d().csvData.count(); +} + +/*! + \reimp + */ +int QxtCsvModel::columnCount(const QModelIndex& parent) const +{ + if (parent.row() != -1 && parent.column() != -1) + { + return 0; + } + return qxt_d().maxColumn; +} + +/*! + \reimp + */ +QVariant QxtCsvModel::data(const QModelIndex& index, int role) const +{ + if (index.parent() != QModelIndex()) + { + return QVariant(); + } + if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole) + { + if (index.row() < 0 || index.column() < 0 || index.row() >= rowCount()) + { + return QVariant(); + } + const QStringList& row = qxt_d().csvData[index.row()]; + if (index.column() >= row.length()) + { + return QVariant(); + } + return row[index.column()]; + } + return QVariant(); +} + +/*! + \reimp + */ +QVariant QxtCsvModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (section < qxt_d().header.count() && orientation == Qt::Horizontal && (role == Qt::DisplayRole + || role == Qt::EditRole + || role == Qt::UserRole)) + { + return qxt_d().header[section]; + } + else + { + return QAbstractTableModel::headerData(section, orientation, role); + } +} + +/*! + \overload + + Reads in a CSV file from the provided \a file using \a codec. + */ +void QxtCsvModel::setSource(const QString filename, bool withHeader, QChar separator, QTextCodec* codec) +{ + QFile src(filename); + setSource(&src, withHeader, separator, codec); +} + +/*! + Reads in a CSV file from the provided \a file using \a codec. + + The value of \a separator will be used to delimit fields, subject to the specified \a quoteMode. + If \a withHeader is set to true, the first line of the file will be used to populate the model's + horizontal header. + + \sa quoteMode + */ +void QxtCsvModel::setSource(QIODevice *file, bool withHeader, QChar separator, QTextCodec* codec) +{ + QxtCsvModelPrivate* d_ptr = &qxt_d(); + bool headerSet = !withHeader; + if (not file->isOpen()) + { + file->open(QIODevice::ReadOnly); + } + if (withHeader) + { + d_ptr->maxColumn = 0; + } + else + { + d_ptr->maxColumn = d_ptr->header.size(); + } + d_ptr->csvData.clear(); + QStringList row; + QString field; + QChar quote; + QChar ch, buffer(0); + bool readCR = false; + QTextStream stream(file); + if (codec) + { + stream.setCodec(codec); + } + else + { + stream.setAutoDetectUnicode(true); + } + while (not stream.atEnd()) + { + if (buffer != QChar(0)) + { + ch = buffer; + buffer = QChar(0); + } + else + { + stream >> ch; + } + if (ch == '\n' && readCR) + { + continue; + } + else if (ch == '\r') + { + readCR = true; + } + else + { + readCR = false; + } + if (ch != separator && (ch.category() == QChar::Separator_Line || ch.category() == QChar::Separator_Paragraph + || ch.category() == QChar::Other_Control)) + { + row << field; + field.clear(); + if (not row.isEmpty()) + { + if (not headerSet) + { + d_ptr->header = row; + headerSet = true; + } + else + { + d_ptr->csvData.append(row); + } + if (row.length() > d_ptr->maxColumn) + { + d_ptr->maxColumn = row.length(); + } + } + row.clear(); + } + else if ((d_ptr->quoteMode & DoubleQuote && ch == '"') || (d_ptr->quoteMode & SingleQuote && ch == '\'')) + { + quote = ch; + do + { + stream >> ch; + if (ch == '\\' && d_ptr->quoteMode & BackslashEscape) + { + stream >> ch; + } + else if (ch == quote) + { + if (d_ptr->quoteMode & TwoQuoteEscape) + { + stream >> buffer; + if (buffer == quote) + { + buffer = QChar(0); + field.append(ch); + continue; + } + } + break; + } + field.append(ch); + } while (!stream.atEnd()); + } + else if (ch == separator) + { + row << field; + field.clear(); + } + else + { + field.append(ch); + } + } + if (not field.isEmpty()) + { + row << field; + } + if (not row.isEmpty()) + { + if (not headerSet) + { + d_ptr->header = row; + } + else + { + d_ptr->csvData.append(row); + } + } + file->close(); +} + +/*! + Sets the horizontal headers of the model to the values provided in \a data. + */ +void QxtCsvModel::setHeaderData(const QStringList& data) +{ + qxt_d().header = data; + emit headerDataChanged(Qt::Horizontal, 0, data.count()); +} + +/*! + \reimp + */ +bool QxtCsvModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role) +{ + if (orientation != Qt::Horizontal) + { + return false; // We don't support the vertical header + } + + if (role != Qt::DisplayRole && role != Qt::EditRole) + { + return false; // We don't support any other roles + } + + if (section < 0) + { + return false; // Bogus input + } + + while (section > qxt_d().header.size()) + { + qxt_d().header << QString(); + } + qxt_d().header[section] = value.toString(); + emit headerDataChanged(Qt::Horizontal, section, section); + return true; +} + +/*! + \reimp + */ +bool QxtCsvModel::setData(const QModelIndex& index, const QVariant& data, int role) +{ + if (index.parent() != QModelIndex()) + { + return false; + } + + if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole) + { + if (index.row() >= rowCount() || index.column() >= columnCount() || index.row() < 0 || index.column() < 0) + { + return false; + } + QStringList& row = qxt_d().csvData[index.row()]; + while (row.length() <= index.column()) + { + row << QString(); + } + row[index.column()] = data.toString(); + emit dataChanged(index, index); + return true; + } + return false; +} + +/*! + \reimp + */ +bool QxtCsvModel::insertRow(int row, const QModelIndex& parent) +{ + return insertRows(row, 1, parent); +} + +/*! + \reimp + */ +bool QxtCsvModel::insertRows(int row, int count, const QModelIndex& parent) +{ + if (parent != QModelIndex() || row < 0) + { + return false; + } + emit beginInsertRows(parent, row, row + count); + QxtCsvModelPrivate& d_ptr = qxt_d(); + if (row >= rowCount()) + { + for(int i = 0; i < count; i++) + { + d_ptr.csvData << QStringList(); + } + } + else + { + for(int i = 0; i < count; i++) + { + d_ptr.csvData.insert(row, QStringList()); + } + } + emit endInsertRows(); + return true; +} + +/*! + \reimp + */ +bool QxtCsvModel::removeRow(int row, const QModelIndex& parent) +{ + return removeRows(row, 1, parent); +} + +/*! + \reimp + */ +bool QxtCsvModel::removeRows(int row, int count, const QModelIndex& parent) +{ + if (parent != QModelIndex() || row < 0) + { + return false; + } + if (row >= rowCount()) + { + return false; + } + if (row + count >= rowCount()) + { + count = rowCount() - row; + } + emit beginRemoveRows(parent, row, row + count); + QxtCsvModelPrivate& d_ptr = qxt_d(); + for (int i = 0;i < count;i++) + { + d_ptr.csvData.removeAt(row); + } + emit endRemoveRows(); + return true; +} + +/*! + \reimp + */ +bool QxtCsvModel::insertColumn(int col, const QModelIndex& parent) +{ + return insertColumns(col, 1, parent); +} + +/*! + \reimp + */ +bool QxtCsvModel::insertColumns(int col, int count, const QModelIndex& parent) +{ + if (parent != QModelIndex() || col < 0) + { + return false; + } + beginInsertColumns(parent, col, col + count - 1); + QxtCsvModelPrivate& d_ptr = qxt_d(); + for (int i = 0; i < rowCount(); i++) + { + QStringList& row = d_ptr.csvData[i]; + while (col >= row.length()) + { + row.append(QString()); + } + for (int j = 0; j < count; j++) + { + row.insert(col, QString()); + } + } + for (int i = 0; i < count ;i++) + { + d_ptr.header.insert(col, QString()); + } + d_ptr.maxColumn += count; + endInsertColumns(); + return true; +} + +/*! + \reimp + */ +bool QxtCsvModel::removeColumn(int col, const QModelIndex& parent) +{ + return removeColumns(col, 1, parent); +} + +/*! + \reimp + */ +bool QxtCsvModel::removeColumns(int col, int count, const QModelIndex& parent) +{ + if (parent != QModelIndex() || col < 0) + { + return false; + } + if (col >= columnCount()) + { + return false; + } + if (col + count >= columnCount()) + { + count = columnCount() - col; + } + emit beginRemoveColumns(parent, col, col + count); + QxtCsvModelPrivate& d_ptr = qxt_d(); + QString before, after; + for (int i = 0; i < rowCount(); i++) + { + for (int j = 0; j < count; j++) + { + d_ptr.csvData[i].removeAt(col); + } + } + for (int i = 0; i < count; i++) + { + d_ptr.header.removeAt(col); + } + emit endRemoveColumns(); + return true; +} + +static QString qxt_addCsvQuotes(QxtCsvModel::QuoteMode mode, QString field) +{ + bool addDoubleQuotes = ((mode & QxtCsvModel::DoubleQuote) && field.contains('"')); + bool addSingleQuotes = ((mode & QxtCsvModel::SingleQuote) && field.contains('\'')); + bool quoteField = (mode & QxtCsvModel::AlwaysQuoteOutput) || addDoubleQuotes || addSingleQuotes; + if (quoteField && !addDoubleQuotes && !addSingleQuotes) + { + if (mode & QxtCsvModel::DoubleQuote) + { + addDoubleQuotes = true; + } + else if(mode & QxtCsvModel::SingleQuote) + { + addSingleQuotes = true; + } + } + if (mode & QxtCsvModel::BackslashEscape) + { + if (addDoubleQuotes) + { + return '"' + field.replace("\\", "\\\\").replace("\"", "\\\"") + '"'; + } + if (addSingleQuotes) + { + return '\'' + field.replace("\\", "\\\\").replace("'", "\\'") + '\''; + } + } + else + { + if (addDoubleQuotes) + { + return '"' + field.replace("\"", "\"\"") + '"'; + } + if (addSingleQuotes) + { + return '\'' + field.replace("'", "''") + '\''; + } + } + return field; +} + +/*! + Outputs the content of the model as a CSV file to the device \a dest using \a codec. + + Fields in the output file will be separated by \a separator. Set \a withHeader to true + to output a row of headers at the top of the file. + */ +void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator, QTextCodec* codec) const +{ + const QxtCsvModelPrivate& d_ptr = qxt_d(); + int row, col, rows, cols; + rows = rowCount(); + cols = columnCount(); + QString data; + if (not dest->isOpen()) + { + dest->open(QIODevice::WriteOnly | QIODevice::Truncate); + } + QTextStream stream(dest); + if (codec) + { + stream.setCodec(codec); + } + if (withHeader) + { + data = ""; + for (col = 0; col < cols; ++col) + { + if (col > 0) + { + data += separator; + } + data += qxt_addCsvQuotes(d_ptr.quoteMode, d_ptr.header.at(col)); + } + stream << data << endl; + } + for (row = 0; row < rows; ++row) + { + const QStringList& rowData = d_ptr.csvData[row]; + data = ""; + for (col = 0; col < cols; ++col) + { + if (col > 0) + { + data += separator; + } + if (col < rowData.length()) + { + data += qxt_addCsvQuotes(d_ptr.quoteMode, rowData.at(col)); + } + else + { + data += qxt_addCsvQuotes(d_ptr.quoteMode, QString()); + } + } + stream << data << endl; + } + stream << flush; + dest->close(); +} + +/*! + \overload + + Outputs the content of the model as a CSV file to the file specified by \a filename using \a codec. + + Fields in the output file will be separated by \a separator. Set \a withHeader to true + to output a row of headers at the top of the file. + */ +void QxtCsvModel::toCSV(const QString filename, bool withHeader, QChar separator, QTextCodec* codec) const +{ + QFile dest(filename); + toCSV(&dest, withHeader, separator, codec); +} + +/*! + \reimp + */ +Qt::ItemFlags QxtCsvModel::flags(const QModelIndex& index) const +{ + return Qt::ItemIsEditable | QAbstractTableModel::flags(index); +} + +/*! + * Returns the current quoting mode. + * \sa setQuoteMode + */ +QxtCsvModel::QuoteMode QxtCsvModel::quoteMode() const +{ + return qxt_d().quoteMode; +} + +/*! + * Sets the current quoting mode. The default quoting mode is BothQuotes | BackslashEscape. + * + * The quoting mode determines what kinds of quoting is used for reading and writing CSV files. + * \sa quoteMode + * \sa QuoteOption + */ +void QxtCsvModel::setQuoteMode(QuoteMode mode) +{ + qxt_d().quoteMode = mode; +} + +/*! + Sets the content of the cell at row \a row and column \a column to \a value. + + \sa text + */ +void QxtCsvModel::setText(int row, int column, const QString& value) +{ + setData(index(row, column), value); +} + +/*! + Fetches the content of the cell at row \a row and column \a column. + + \sa setText + */ +QString QxtCsvModel::text(int row, int column) const +{ + return data(index(row, column)).toString(); +} + +/*! + Sets the content of the header for column \a column to \a value. + + \sa headerText + */ +void QxtCsvModel::setHeaderText(int column, const QString& value) +{ + setHeaderData(column, Qt::Horizontal, value); +} + +/*! + Fetches the content of the cell at row \a row and column \a column. + + \sa setText + */ +QString QxtCsvModel::headerText(int column) const +{ + return headerData(column, Qt::Horizontal).toString(); +} diff --git a/src/libs/vmisc/qxtcsvmodel.h b/src/libs/vmisc/qxtcsvmodel.h new file mode 100644 index 000000000..18869fd89 --- /dev/null +++ b/src/libs/vmisc/qxtcsvmodel.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** Copyright (c) 2006 - 2011, the LibQxt project. +** See the Qxt AUTHORS file for a list of authors and copyright holders. +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the LibQxt project nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +** +*****************************************************************************/ + +#ifndef QXTCSVMODEL_H +#define QXTCSVMODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include +class QTextCodec; + +class QxtCsvModelPrivate; +class QxtCsvModel : public QAbstractTableModel +{ + Q_OBJECT +public: + QxtCsvModel(QObject *parent = nullptr); + explicit QxtCsvModel(QIODevice *file, QObject *parent = nullptr, bool withHeader = false, QChar separator = ','); + explicit QxtCsvModel(const QString filename, QObject *parent = nullptr, bool withHeader = false, + QChar separator = ','); + virtual ~QxtCsvModel(); + + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; + virtual int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + virtual bool setData(const QModelIndex& index, const QVariant& data, int role = Qt::EditRole) Q_DECL_OVERRIDE; + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, + int role = Qt::DisplayRole) Q_DECL_OVERRIDE; + void setHeaderData(const QStringList& data); + + QString text(int row, int column) const; + void setText(int row, int column, const QString& value); + + QString headerText(int column) const; + void setHeaderText(int column, const QString& value); + + + bool insertRow(int row, const QModelIndex& parent = QModelIndex()); + virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE; + + bool removeRow(int row, const QModelIndex& parent = QModelIndex()); + virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE; + + bool insertColumn(int col, const QModelIndex& parent = QModelIndex()); + virtual bool insertColumns(int col, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE; + + bool removeColumn(int col, const QModelIndex& parent = QModelIndex()); + virtual bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE; + + void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr); + void setSource(const QString filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr); + + void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr) const; + void toCSV(const QString filename, bool withHeader = false, QChar separator = ',', + QTextCodec* codec = nullptr) const; + + enum QuoteOption { NoQuotes = 0, + SingleQuote = 1, + DoubleQuote = 2, + BothQuotes = 3, + NoEscape = 0, + TwoQuoteEscape = 4, + BackslashEscape = 8, + AlwaysQuoteOutput = 16, + DefaultQuoteMode = BothQuotes | BackslashEscape | AlwaysQuoteOutput }; + Q_DECLARE_FLAGS(QuoteMode, QuoteOption) + + QuoteMode quoteMode() const; + void setQuoteMode(QuoteMode mode); + + virtual Qt::ItemFlags flags(const QModelIndex& index) const Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QxtCsvModel) + QXT_DECLARE_PRIVATE(QxtCsvModel) +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QxtCsvModel::QuoteMode) + +#endif // QXTCSVMODEL_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 4010be461..b75dfda45 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -9,7 +9,8 @@ SOURCES += \ $$PWD/projectversion.cpp \ $$PWD/vcommonsettings.cpp \ $$PWD/vtapesettings.cpp \ - $$PWD/commandoptions.cpp + $$PWD/commandoptions.cpp \ + $$PWD/qxtcsvmodel.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -27,7 +28,8 @@ HEADERS += \ $$PWD/debugbreak.h \ $$PWD/vlockguard.h \ $$PWD/vsysexits.h \ - $$PWD/commandoptions.h + $$PWD/commandoptions.h \ + $$PWD/qxtcsvmodel.h # Qt's versions # 5.0.0, 5.0.1, 5.0.2 diff --git a/src/libs/vmisc/vtapesettings.cpp b/src/libs/vmisc/vtapesettings.cpp index f28a893cb..5dfc482ee 100644 --- a/src/libs/vmisc/vtapesettings.cpp +++ b/src/libs/vmisc/vtapesettings.cpp @@ -30,12 +30,17 @@ #include #include +#include const QString VTapeSettings::SettingDataBaseGeometry = QStringLiteral("database/geometry"); const QString VTapeSettings::SettingDefHeight = QStringLiteral("gradation/defHeight"); const QString VTapeSettings::SettingDefSize = QStringLiteral("gradation/defHeight"); +const QString VTapeSettings::SettingCSVWithHeader = QStringLiteral("csv/withHeader"); +const QString VTapeSettings::SettingCSVCodec = QStringLiteral("csv/withCodec"); +const QString VTapeSettings::SettingCSVSeparator = QStringLiteral("csv/withSeparator"); + //--------------------------------------------------------------------------------------------------------------------- VTapeSettings::VTapeSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) @@ -78,3 +83,88 @@ int VTapeSettings::GetDefSize() const { return value(SettingDefSize, 50).toInt(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetCSVWithHeader(bool withHeader) +{ + setValue(SettingCSVWithHeader, withHeader); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VTapeSettings::GetCSVWithHeader() const +{ + return value(SettingCSVWithHeader, GetDefCSVWithHeader()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VTapeSettings::GetDefCSVWithHeader() const +{ + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetCSVCodec(int mib) +{ + setValue(SettingCSVCodec, mib); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VTapeSettings::GetCSVCodec() const +{ + return value(SettingCSVCodec, GetDefCSVCodec()).toInt(); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VTapeSettings::GetDefCSVCodec() const +{ + return QTextCodec::codecForLocale()->mibEnum(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetCSVSeparator(const QChar &separator) +{ + switch(separator.toLatin1()) + { + case '\t': + setValue(SettingCSVSeparator, 0); + break; + case ';': + setValue(SettingCSVSeparator, 1); + break; + case ' ': + setValue(SettingCSVSeparator, 2); + break; + case ',': + default: + setValue(SettingCSVSeparator, 3); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QChar VTapeSettings::GetCSVSeparator() const +{ + const quint8 separator = static_cast(value(SettingCSVSeparator, 3).toUInt()); + switch(separator) + { + case 0: + return QChar('\t'); + break; + case 1: + return QChar(';'); + break; + case 2: + return QChar(' '); + break; + case 3: + default: + return QChar(','); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QChar VTapeSettings::GetDefCSVSeparator() const +{ + return QChar(','); +} diff --git a/src/libs/vmisc/vtapesettings.h b/src/libs/vmisc/vtapesettings.h index ba5424921..51afe5cae 100644 --- a/src/libs/vmisc/vtapesettings.h +++ b/src/libs/vmisc/vtapesettings.h @@ -47,12 +47,27 @@ public: void SetDefSize(int value); int GetDefSize() const; + void SetCSVWithHeader(bool withHeader); + bool GetCSVWithHeader() const; + bool GetDefCSVWithHeader() const; + + void SetCSVCodec(int mib); + int GetCSVCodec() const; + int GetDefCSVCodec() const; + + void SetCSVSeparator(const QChar &separator); + QChar GetCSVSeparator() const; + QChar GetDefCSVSeparator() const; + private: Q_DISABLE_COPY(VTapeSettings) static const QString SettingDataBaseGeometry; static const QString SettingDefHeight; static const QString SettingDefSize; + static const QString SettingCSVWithHeader; + static const QString SettingCSVCodec; + static const QString SettingCSVSeparator; }; #endif // VTAPESETTINGS_H diff --git a/src/libs/vpatterndb/calculator.h b/src/libs/vpatterndb/calculator.h index c3d89c22d..8f6030247 100644 --- a/src/libs/vpatterndb/calculator.h +++ b/src/libs/vpatterndb/calculator.h @@ -48,9 +48,8 @@ class VContainer; * //Need delete dialog here because parser in dialog don't allow use correct separator for parsing here. * //Don't know why. * delete dialog; - * Calculator *cal = new Calculator(); + * QScopedPointer cal(new Calculator()); * result = cal->EvalFormula(data->PlainVariables(), formula); - * delete cal;//Here can be memory leak, but dialog already check this formula and probability very low. * } */ class Calculator:public qmu::QmuFormulaBase diff --git a/src/libs/vpatterndb/variables/vcurvevariable.cpp b/src/libs/vpatterndb/variables/vcurvevariable.cpp index db118bdea..904a56976 100644 --- a/src/libs/vpatterndb/variables/vcurvevariable.cpp +++ b/src/libs/vpatterndb/variables/vcurvevariable.cpp @@ -68,6 +68,11 @@ VCurveVariable::~VCurveVariable() //--------------------------------------------------------------------------------------------------------------------- bool VCurveVariable::Filter(quint32 id) { + if (id == NULL_ID) + { + return false; + } + if (d->parentId != NULL_ID)//Do not check if value zero {// Not all curves have parents. Only those who was created after cutting the parent curve. return d->id == id || d->parentId == id; diff --git a/src/libs/vpatterndb/variables/vlineangle.cpp b/src/libs/vpatterndb/variables/vlineangle.cpp index f28d8136f..508070e01 100644 --- a/src/libs/vpatterndb/variables/vlineangle.cpp +++ b/src/libs/vpatterndb/variables/vlineangle.cpp @@ -91,7 +91,7 @@ void VLineAngle::SetValue(const VPointF *p1, const VPointF *p2) SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); //Correct angle. Try avoid results like 6,7563e-15. - const qreal angle = qFloor(QLineF(p1->toQPointF(), p2->toQPointF()).angle() * 100000.) / 100000.; + const qreal angle = qFloor(QLineF(*p1, *p2).angle() * 100000.) / 100000.; VInternalVariable::SetValue(angle); } diff --git a/src/libs/vpatterndb/variables/vlinelength.cpp b/src/libs/vpatterndb/variables/vlinelength.cpp index 0fc09989f..f2ff3634c 100644 --- a/src/libs/vpatterndb/variables/vlinelength.cpp +++ b/src/libs/vpatterndb/variables/vlinelength.cpp @@ -85,7 +85,7 @@ void VLengthLine::SetValue(const VPointF *p1, const VPointF *p2) SCASSERT(p1 != nullptr); SCASSERT(p2 != nullptr); - VInternalVariable::SetValue(FromPixel(QLineF(p1->toQPointF(), p2->toQPointF()).length(), d->patternUnit)); + VInternalVariable::SetValue(FromPixel(QLineF(*p1, *p2).length(), d->patternUnit)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 29d084499..b28ca3120 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -56,7 +56,7 @@ Q_LOGGING_CATEGORY(vCon, "v.container") quint32 VContainer::_id = NULL_ID; qreal VContainer::_size = 50; qreal VContainer::_height = 176; -QSet VContainer::uniqueNames = QSet(); +QSet VContainer::uniqueNames = QSet(); //--------------------------------------------------------------------------------------------------------------------- /** @@ -557,6 +557,14 @@ bool VContainer::IsUnique(const QString &name) return (!uniqueNames.contains(name) && !builInFunctions.contains(name)); } +//--------------------------------------------------------------------------------------------------------------------- +QStringList VContainer::AllUniqueNames() +{ + QStringList names = builInFunctions; + names.append(uniqueNames.toList()); + return names; +} + //--------------------------------------------------------------------------------------------------------------------- const Unit *VContainer::GetPatternUnit() const { diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 645c6f3b6..dce71b92f 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -167,6 +167,7 @@ public: const QHash PlainVariables() const; static bool IsUnique(const QString &name); + static QStringList AllUniqueNames(); const Unit *GetPatternUnit() const; const VTranslateVars *GetTrVars() const; @@ -178,7 +179,7 @@ private: static quint32 _id; static qreal _size; static qreal _height; - static QSet uniqueNames; + static QSet uniqueNames; QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index 1314d3d39..d7a2e8db2 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -371,7 +371,7 @@ QVector VDetail::ContourPoints(const VContainer *data) const case (Tool::NodePoint): { const QSharedPointer point = data->GeometricObject(at(i).getId()); - points.append(point->toQPointF()); + points.append(*point); } break; case (Tool::NodeArc): @@ -412,7 +412,7 @@ QVector VDetail::SeamAllowancePoints(const VContainer *data) const case (Tool::NodePoint): { const QSharedPointer point = data->GeometricObject(at(i).getId()); - QPointF pEkv = point->toQPointF(); + QPointF pEkv = *point; pEkv.setX(pEkv.x()+at(i).getMx()); pEkv.setY(pEkv.y()+at(i).getMy()); pointsEkv.append(pEkv); @@ -555,14 +555,14 @@ QPointF VDetail::StartSegment(const VContainer *data, const int &i, bool reverse { if (at(CountNode()-1).getTypeTool() == Tool::NodePoint) { - begin = data->GeometricObject(at(CountNode()-1).getId())->toQPointF(); + begin = *data->GeometricObject(at(CountNode()-1).getId()); } } else { if (at(i-1).getTypeTool() == Tool::NodePoint) { - begin = data->GeometricObject(at(i-1).getId())->toQPointF(); + begin = *data->GeometricObject(at(i-1).getId()); } } } @@ -592,14 +592,14 @@ QPointF VDetail::EndSegment(const VContainer *data, const int &i, bool reverse) { if (at(0).getTypeTool() == Tool::NodePoint) { - end = data->GeometricObject(at(0).getId())->toQPointF(); + end = *data->GeometricObject(at(0).getId()); } } else { if (at(i+1).getTypeTool() == Tool::NodePoint) { - end = data->GeometricObject(at(i+1).getId())->toQPointF(); + end = *data->GeometricObject(at(i+1).getId()); } } } diff --git a/src/libs/vpatterndb/vformula.cpp b/src/libs/vpatterndb/vformula.cpp index 8e60633d2..703146d8b 100644 --- a/src/libs/vpatterndb/vformula.cpp +++ b/src/libs/vpatterndb/vformula.cpp @@ -32,7 +32,9 @@ #include "../vmisc/vabstractapplication.h" #include "../vmisc/vsettings.h" #include "vtranslatevars.h" + #include +#include //VFormula //--------------------------------------------------------------------------------------------------------------------- @@ -43,8 +45,14 @@ VFormula::VFormula() //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const QString &formula, const VContainer *container) - :formula(qApp->TrVars()->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container), - toolId(NULL_ID), postfix(QString()), _error(true), dValue(0) + : formula(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())), + value(QString(tr("Error"))), + checkZero(true), + data(container), + toolId(NULL_ID), + postfix(QString()), + _error(true), + dValue(0) { this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist Eval(); @@ -114,7 +122,7 @@ void VFormula::SetFormula(const QString &value, FormulaType type) { if (type == FormulaType::ToUser) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); } else { @@ -226,23 +234,31 @@ void VFormula::Eval() { try { - Calculator *cal = new Calculator(); + QScopedPointer cal(new Calculator()); QString expression = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); const qreal result = cal->EvalFormula(data->PlainVariables(), expression); - delete cal; - //if result equal 0 - if (checkZero && qFuzzyIsNull(result)) + if (qIsInf(result) || qIsNaN(result)) { - value = QString("0"); + value = QString(tr("Error")); _error = true; dValue = 0; } else { - dValue = result; - value = QString(qApp->LocaleToString(result) + " " + postfix); - _error = false; + //if result equal 0 + if (checkZero && qFuzzyIsNull(result)) + { + value = QString("0"); + _error = true; + dValue = 0; + } + else + { + dValue = result; + value = QString(qApp->LocaleToString(result) + " " + postfix); + _error = false; + } } } catch (qmu::QmuParserError &e) diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index 858a32d77..a2274b857 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -40,7 +40,7 @@ using namespace qmu; //--------------------------------------------------------------------------------------------------------------------- -VTranslateVars::VTranslateVars(bool osSeparator) +VTranslateVars::VTranslateVars() :VTranslateMeasurements(), PMSystemNames(QMap()), PMSystemAuthors(QMap()), @@ -48,8 +48,7 @@ VTranslateVars::VTranslateVars(bool osSeparator) variables(QMap()), functions(QMap()), postfixOperators(QMap()), - stDescriptions(QMap()), - osSeparator(osSeparator) + stDescriptions(QMap()) { InitPatternMakingSystems(); InitVariables(); @@ -804,7 +803,7 @@ QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSepara * @param formula expression that need translate * @return translated expression */ -QString VTranslateVars::FormulaToUser(const QString &formula) const +QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) const { if (formula.isEmpty()) { diff --git a/src/libs/vpatterndb/vtranslatevars.h b/src/libs/vpatterndb/vtranslatevars.h index 178377748..079d1ae50 100644 --- a/src/libs/vpatterndb/vtranslatevars.h +++ b/src/libs/vpatterndb/vtranslatevars.h @@ -34,7 +34,7 @@ class VTranslateVars : public VTranslateMeasurements { public: - explicit VTranslateVars(bool osSeparator); + explicit VTranslateVars(); virtual ~VTranslateVars() Q_DECL_OVERRIDE; bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const; @@ -55,7 +55,7 @@ public: QString FormulaFromUser(const QString &formula, bool osSeparator) const; QString TryFormulaFromUser(const QString &formula, bool osSeparator) const; - QString FormulaToUser(const QString &formula) const; + QString FormulaToUser(const QString &formula, bool osSeparator) const; virtual void Retranslate() Q_DECL_OVERRIDE; @@ -68,7 +68,6 @@ private: QMap functions; QMap postfixOperators; QMap stDescriptions; - bool osSeparator; void InitPatternMakingSystems(); void InitVariables(); diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 26bcfaad6..1a358d539 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -37,7 +37,8 @@ HEADERS += \ $$PWD/tools/dialogpointofintersectioncurves.h \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ - $$PWD/tools/dialoggroup.h + $$PWD/tools/dialoggroup.h \ + $$PWD/tools/dialogrotation.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -74,7 +75,8 @@ SOURCES += \ $$PWD/tools/dialogpointofintersectioncurves.cpp \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ - $$PWD/tools/dialoggroup.cpp + $$PWD/tools/dialoggroup.cpp \ + $$PWD/tools/dialogrotation.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -110,4 +112,5 @@ FORMS += \ $$PWD/tools/dialogpointofintersectioncurves.ui \ $$PWD/tools/dialogcubicbezier.ui \ $$PWD/tools/dialogcubicbezierpath.ui \ - $$PWD/tools/dialoggroup.ui + $$PWD/tools/dialoggroup.ui \ + $$PWD/tools/dialogrotation.ui diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index 7e128200d..22ea0bd69 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -298,7 +298,7 @@ void DialogEditWrongFormula::showEvent(QShowEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formula.length() > 80) diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index b9ac6d496..8383ebd91 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -61,6 +61,7 @@ #include "dialogs/tools/dialogpointfromarcandtangent.h" #include "dialogs/tools/dialogtruedarts.h" #include "dialogs/tools/dialoggroup.h" +#include "dialogs/tools/dialogrotation.h" #include "dialogs/support/dialogeditwrongformula.h" #include "dialogs/support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index df24ce40b..99dfef4be 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -250,7 +250,7 @@ void DialogAlongLine::SetFirstPointId(const quint32 &value) */ void DialogAlongLine::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index a70112f81..28b4e8e5a 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -135,7 +135,7 @@ void DialogArc::SetCenter(const quint32 &value) */ void DialogArc::SetF2(const QString &value) { - f2 = qApp->TrVars()->FormulaToUser(value); + f2 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (f2.length() > 80) { @@ -169,7 +169,7 @@ void DialogArc::SetColor(const QString &value) */ void DialogArc::SetF1(const QString &value) { - f1 = qApp->TrVars()->FormulaToUser(value); + f1 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (f1.length() > 80) { @@ -191,7 +191,7 @@ void DialogArc::SetF1(const QString &value) */ void DialogArc::SetRadius(const QString &value) { - radius = qApp->TrVars()->FormulaToUser(value); + radius = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (radius.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 198b168c0..294aef428 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -116,7 +116,7 @@ QString DialogArcWithLength::GetRadius() const //--------------------------------------------------------------------------------------------------------------------- void DialogArcWithLength::SetRadius(const QString &value) { - radius = qApp->TrVars()->FormulaToUser(value); + radius = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (radius.length() > 80) { @@ -139,7 +139,7 @@ QString DialogArcWithLength::GetF1() const void DialogArcWithLength::SetF1(const QString &value) { - f1 = qApp->TrVars()->FormulaToUser(value); + f1 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (f1.length() > 80) { @@ -163,7 +163,7 @@ QString DialogArcWithLength::GetLength() const //--------------------------------------------------------------------------------------------------------------------- void DialogArcWithLength::SetLength(const QString &value) { - length = qApp->TrVars()->FormulaToUser(value); + length = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (length.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogbisector.cpp b/src/libs/vtools/dialogs/tools/dialogbisector.cpp index 1ef8cba74..88b8313f0 100644 --- a/src/libs/vtools/dialogs/tools/dialogbisector.cpp +++ b/src/libs/vtools/dialogs/tools/dialogbisector.cpp @@ -237,7 +237,7 @@ void DialogBisector::SetTypeLine(const QString &value) */ void DialogBisector::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp index 202076550..52ab4aa38 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp @@ -110,7 +110,7 @@ QString DialogCurveIntersectAxis::GetAngle() const //--------------------------------------------------------------------------------------------------------------------- void DialogCurveIntersectAxis::SetAngle(const QString &value) { - formulaAngle = qApp->TrVars()->FormulaToUser(value); + formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formulaAngle.length() > 80) @@ -181,7 +181,7 @@ void DialogCurveIntersectAxis::ShowDialog(bool click) VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(GetBasePointId()); - QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); + QLineF line = QLineF(*point, scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index 03f0cc852..c247013aa 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -62,7 +62,6 @@ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidge CheckState(); FillComboBoxArcs(ui->comboBoxArc); - FillComboBoxLineColors(ui->comboBoxColor); connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutArc::FXLength); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged); @@ -170,18 +169,6 @@ void DialogCutArc::setArcId(const quint32 &value) path->setObject1Id(value); } -//--------------------------------------------------------------------------------------------------------------------- -QString DialogCutArc::GetColor() const -{ - return GetComboBoxCurrentData(ui->comboBoxColor); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogCutArc::SetColor(const QString &value) -{ - ChangeCurrentData(ui->comboBoxColor, value); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetFormula set string with formula length @@ -189,7 +176,7 @@ void DialogCutArc::SetColor(const QString &value) */ void DialogCutArc::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.h b/src/libs/vtools/dialogs/tools/dialogcutarc.h index fd219a3f3..28ecd4479 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.h +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.h @@ -54,9 +54,6 @@ public: quint32 getArcId() const; void setArcId(const quint32 &value); - - QString GetColor() const; - void SetColor(const QString &value); public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; /** diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.ui b/src/libs/vtools/dialogs/tools/dialogcutarc.ui index 76379aeab..823af7217 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.ui +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.ui @@ -7,7 +7,7 @@ 0 0 412 - 222 + 189 @@ -246,16 +246,6 @@ - - - - Color: - - - - - - diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index a52257a6c..fe6f2ffc7 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -61,7 +61,6 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, CheckState(); FillComboBoxSplines(ui->comboBoxSpline); - FillComboBoxLineColors(ui->comboBoxColor); connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSpline::FXLength); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged); @@ -96,7 +95,7 @@ void DialogCutSpline::SetPointName(const QString &value) */ void DialogCutSpline::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formula.length() > 80) @@ -126,18 +125,6 @@ void DialogCutSpline::setSplineId(const quint32 &value) path->setObject1Id(value); } -//--------------------------------------------------------------------------------------------------------------------- -QString DialogCutSpline::GetColor() const -{ - return GetComboBoxCurrentData(ui->comboBoxColor); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogCutSpline::SetColor(const QString &value) -{ - ChangeCurrentData(ui->comboBoxColor, value); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.h b/src/libs/vtools/dialogs/tools/dialogcutspline.h index ff472d927..e52d505f0 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.h +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.h @@ -53,9 +53,6 @@ public: quint32 getSplineId() const; void setSplineId(const quint32 &value); - - QString GetColor() const; - void SetColor(const QString &value); public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; /** diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.ui b/src/libs/vtools/dialogs/tools/dialogcutspline.ui index 805d4f727..4f792a299 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.ui +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.ui @@ -7,7 +7,7 @@ 0 0 412 - 222 + 189 @@ -246,16 +246,6 @@ - - - - Color: - - - - - - diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 0b94b5fad..181f958c2 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -61,7 +61,6 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & CheckState(); FillComboBoxSplinesPath(ui->comboBoxSplinePath); - FillComboBoxLineColors(ui->comboBoxColor); connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSplinePath::FXLength); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged); @@ -96,7 +95,7 @@ void DialogCutSplinePath::SetPointName(const QString &value) */ void DialogCutSplinePath::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formula.length() > 80) @@ -126,18 +125,6 @@ void DialogCutSplinePath::setSplinePathId(const quint32 &value) path->setObject1Id(value); } -//--------------------------------------------------------------------------------------------------------------------- -QString DialogCutSplinePath::GetColor() const -{ - return GetComboBoxCurrentData(ui->comboBoxColor); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogCutSplinePath::SetColor(const QString &value) -{ - ChangeCurrentData(ui->comboBoxColor, value); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h index 167d74eae..5a667e16c 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h @@ -53,9 +53,6 @@ public: quint32 getSplinePathId() const; void setSplinePathId(const quint32 &value); - - QString GetColor() const; - void SetColor(const QString &value); public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; /** diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui index 9fd940a71..e0dc93b76 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui @@ -7,7 +7,7 @@ 0 0 412 - 222 + 189 @@ -246,22 +246,6 @@ - - - - - 0 - 0 - - - - Color: - - - - - - diff --git a/src/libs/vtools/dialogs/tools/dialogendline.cpp b/src/libs/vtools/dialogs/tools/dialogendline.cpp index b8012f2d2..e1a921897 100644 --- a/src/libs/vtools/dialogs/tools/dialogendline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogendline.cpp @@ -203,7 +203,7 @@ void DialogEndLine::SetTypeLine(const QString &value) */ void DialogEndLine::SetFormula(const QString &value) { - formulaLength = qApp->TrVars()->FormulaToUser(value); + formulaLength = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formulaLength.length() > 80) @@ -226,7 +226,7 @@ void DialogEndLine::SetFormula(const QString &value) */ void DialogEndLine::SetAngle(const QString &value) { - formulaAngle = qApp->TrVars()->FormulaToUser(value); + formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formulaAngle.length() > 80) @@ -283,7 +283,7 @@ void DialogEndLine::ShowDialog(bool click) VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(GetBasePointId()); - QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); + QLineF line = QLineF(*point, scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. const qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; diff --git a/src/libs/vtools/dialogs/tools/dialogheight.cpp b/src/libs/vtools/dialogs/tools/dialogheight.cpp index da43253d1..81e0b40b8 100644 --- a/src/libs/vtools/dialogs/tools/dialogheight.cpp +++ b/src/libs/vtools/dialogs/tools/dialogheight.cpp @@ -248,8 +248,7 @@ void DialogHeight::PointNameChanged() const QSharedPointer p2Line = data->GeometricObject(p2LineId); QColor color = okColor; - if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()), - basePoint->toQPointF()) == QPointF()) + if (set.size() != 3 || VGObject::ClosestPoint(QLineF(*p1Line, *p2Line), *basePoint) == QPointF()) { flagError = false; color = errorColor; diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp index e4b284e51..0688571d1 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp @@ -215,8 +215,8 @@ void DialogLineIntersect::PointNameChanged() const QSharedPointer p1Line2 = data->GeometricObject(p1Line2Id); const QSharedPointer p2Line2 = data->GeometricObject(p2Line2Id); - QLineF line1(p1Line1->toQPointF(), p2Line1->toQPointF()); - QLineF line2(p1Line2->toQPointF(), p2Line2->toQPointF()); + QLineF line1(*p1Line1, *p2Line1); + QLineF line2(*p1Line2, *p2Line2); QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); @@ -266,8 +266,8 @@ bool DialogLineIntersect::CheckIntersecion() const QSharedPointer p1L2 = data->GeometricObject(GetP1Line2()); const QSharedPointer p2L2 = data->GeometricObject(GetP2Line2()); - QLineF line1(p1L1->toQPointF(), p2L1->toQPointF()); - QLineF line2(p1L2->toQPointF(), p2L2->toQPointF()); + QLineF line1(*p1L1, *p2L1); + QLineF line2(*p1L2, *p2L2); QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp index a11d378fb..a61a6e3d0 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp @@ -119,7 +119,7 @@ QString DialogLineIntersectAxis::GetAngle() const //--------------------------------------------------------------------------------------------------------------------- void DialogLineIntersectAxis::SetAngle(const QString &value) { - formulaAngle = qApp->TrVars()->FormulaToUser(value); + formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value if (formulaAngle.length() > 80) @@ -206,7 +206,7 @@ void DialogLineIntersectAxis::ShowDialog(bool click) VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(GetBasePointId()); - QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); + QLineF line = QLineF(*point, scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; diff --git a/src/libs/vtools/dialogs/tools/dialognormal.cpp b/src/libs/vtools/dialogs/tools/dialognormal.cpp index be1b08099..d219318fd 100644 --- a/src/libs/vtools/dialogs/tools/dialognormal.cpp +++ b/src/libs/vtools/dialogs/tools/dialognormal.cpp @@ -268,7 +268,7 @@ void DialogNormal::SetAngle(const qreal &value) */ void DialogNormal::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp index f7334a079..9b0d84830 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp @@ -125,7 +125,7 @@ QString DialogPointFromCircleAndTangent::GetCircleRadius() const //--------------------------------------------------------------------------------------------------------------------- void DialogPointFromCircleAndTangent::SetCircleRadius(const QString &value) { - const QString formula = qApp->TrVars()->FormulaToUser(value); + const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp index 29da1303f..e20065ab2 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp @@ -277,7 +277,7 @@ void DialogPointOfContact::setCenter(const quint32 &value) */ void DialogPointOfContact::setRadius(const QString &value) { - radius = qApp->TrVars()->FormulaToUser(value); + radius = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (radius.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp index e2822784f..90abbd364 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp @@ -157,7 +157,7 @@ QString DialogPointOfIntersectionCircles::GetFirstCircleRadius() const //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfIntersectionCircles::SetFirstCircleRadius(const QString &value) { - const QString formula = qApp->TrVars()->FormulaToUser(value); + const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { @@ -182,7 +182,7 @@ QString DialogPointOfIntersectionCircles::GetSecondCircleRadius() const //--------------------------------------------------------------------------------------------------------------------- void DialogPointOfIntersectionCircles::SetSecondCircleRadius(const QString &value) { - const QString formula = qApp->TrVars()->FormulaToUser(value); + const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp new file mode 100644 index 000000000..8af42964d --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -0,0 +1,381 @@ +/************************************************************************ + ** + ** @file dialogrotation.cpp + ** @author Roman Telezhynskyi + ** @date 10 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 "dialogrotation.h" +#include "ui_dialogrotation.h" + +#include + +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../ifc/xml/vdomdocument.h" +#include "../../visualization/line/vistoolrotation.h" +#include "../support/dialogeditwrongformula.h" +#include "../qmuparser/qmudef.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogRotation), + flagAngle(false), + timerAngle(nullptr), + formulaAngle(), + formulaBaseHeightAngle(0), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + this->formulaBaseHeightAngle = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + timerAngle = new QTimer(this); + connect(timerAngle, &QTimer::timeout, this, &DialogRotation::EvalAngle); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxOriginPoint); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogRotation::SuffixChanged); + connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogRotation::FXAngle); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogRotation::AngleChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogRotation::DeployAngleTextEdit); + connect(ui->comboBoxOriginPoint, static_cast(&QComboBox::currentIndexChanged), + this, &DialogRotation::PointChanged); + + vis = new VisToolRotation(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogRotation::~DialogRotation() +{ + DeleteVisualization(); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogRotation::GetOrigPointId() const +{ + return getCurrentObjectId(ui->comboBoxOriginPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetOrigPointId(const quint32 &value) +{ + ChangeCurrentData(ui->comboBoxOriginPoint, value); + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetOriginPointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogRotation::GetAngle() const +{ + return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetAngle(const QString &value) +{ + formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formulaAngle.length() > 80) + { + this->DeployAngleTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formulaAngle); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetAngle(formulaAngle); + + MoveCursorToEnd(ui->plainTextEditFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogRotation::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogRotation::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + + emit ToolTip("Select origin point"); + } + else if (not stage1 && prepare && click) + { + /*We will ignore click if pointer is in point circle*/ + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + const QSharedPointer point = data->GeometricObject(GetOrigPointId()); + const QLineF line = QLineF(*point, scene->getScenePos()); + + //Radius of point circle, but little bigger. Need handle with hover sizes. + const qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + if (line.length() <= radius) + { + return; + } + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + SetAngle(operation->Angle());//Show in dialog angle that a user choose + setModal(true); + emit ToolTip(""); + timerAngle->start(); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (objects.contains(id)) + { + return; + } + + if (SetObject(id, ui->comboBoxOriginPoint, "")) + { + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + connect(operation, &Visualization::ToolTip, this, &DialogTool::ShowVisToolTip); + + operation->SetOriginPointId(id); + operation->RefreshGeometry(); + + prepare = true; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(tool) + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::DeployAngleTextEdit() +{ + DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeightAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::AngleChanged() +{ + labelEditFormula = ui->labelEditAngle; + labelResultCalculation = ui->labelResultAngle; + ValFormulaChanged(flagAngle, ui->plainTextEditFormula, timerAngle, degreeSymbol); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::FXAngle() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit angle")); + dialog->SetFormula(GetAngle()); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetAngle(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString suffix = edit->text(); + if (suffix.isEmpty()) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + else + { + if (m_suffix != suffix) + { + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = data->AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + } + } + } + + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagAngle && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + formulaAngle = ui->plainTextEditFormula->toPlainText(); + formulaAngle.replace("\n", " "); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetOriginPointId(GetOrigPointId()); + operation->SetAngle(formulaAngle); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::closeEvent(QCloseEvent *event) +{ + ui->plainTextEditFormula->blockSignals(true); + DialogTool::closeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::PointChanged() +{ + QColor color = okColor; + if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint))) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelOriginPoint, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::EvalAngle() +{ + labelEditFormula = ui->labelEditAngle; + Eval(ui->plainTextEditFormula->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false); +} diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.h b/src/libs/vtools/dialogs/tools/dialogrotation.h new file mode 100644 index 000000000..f21ba28c8 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogrotation.h @@ -0,0 +1,106 @@ +/************************************************************************ + ** + ** @file dialogrotation.h + ** @author Roman Telezhynskyi + ** @date 10 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 DIALOGROTATION_H +#define DIALOGROTATION_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogRotation; +} + +class DialogRotation : public DialogTool +{ + Q_OBJECT +public: + explicit DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogRotation(); + + quint32 GetOrigPointId() const; + void SetOrigPointId(const quint32 &value); + + QString GetAngle() const; + void SetAngle(const QString &value); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + /** @brief DeployAngleTextEdit grow or shrink formula input */ + void DeployAngleTextEdit(); + void AngleChanged(); + void FXAngle(); + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; + +private slots: + void PointChanged(); + +private: + Q_DISABLE_COPY(DialogRotation) + Ui::DialogRotation *ui; + + /** @brief flagAngle true if value of angle is correct */ + bool flagAngle; + + /** @brief timerAngle timer of check formula of angle */ + QTimer *timerAngle; + + /** @brief angle formula of angle */ + QString formulaAngle; + + /** @brief formulaBaseHeightAngle base height defined by dialogui */ + int formulaBaseHeightAngle; + + QList objects; + + bool stage1; + + QString m_suffix; + + void EvalAngle(); +}; + +#endif // DIALOGROTATION_H diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.ui b/src/libs/vtools/dialogs/tools/dialogrotation.ui new file mode 100644 index 000000000..95a089b7d --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogrotation.ui @@ -0,0 +1,275 @@ + + + DialogRotation + + + + 0 + 0 + 285 + 189 + + + + Rotation + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + + + + + + + Origin Point: + + + + + + + + + + Suffix: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogRotation + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogRotation + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp index 3ff86611b..79f4ff42b 100644 --- a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp @@ -295,7 +295,7 @@ void DialogShoulderPoint::SetP1Line(const quint32 &value) */ void DialogShoulderPoint::SetFormula(const QString &value) { - formula = qApp->TrVars()->FormulaToUser(value); + formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 2a893b92e..ffd05e80d 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -273,7 +273,7 @@ void DialogSpline::FXAngle1() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (angle1F.length() > 80) { @@ -296,7 +296,7 @@ void DialogSpline::FXAngle2() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (angle2F.length() > 80) { @@ -319,7 +319,7 @@ void DialogSpline::FXLength1() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (length1F.length() > 80) { @@ -342,7 +342,7 @@ void DialogSpline::FXLength2() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (length2F.length() > 80) { @@ -505,13 +505,17 @@ void DialogSpline::ShowDialog(bool click) spl = VSpline(*GetP1(), path->GetP2(), path->GetP3(), *GetP4()); - const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula()); - const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula()); + const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula(), + qApp->Settings()->GetOsSeparator()); + const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula(), + qApp->Settings()->GetOsSeparator()); ui->plainTextEditAngle1F->setPlainText(angle1F); ui->plainTextEditAngle2F->setPlainText(angle2F); - ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula())); - ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula())); + ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula(), + qApp->Settings()->GetOsSeparator())); + ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula(), + qApp->Settings()->GetOsSeparator())); if (not data->IsUnique(spl.name())) { @@ -556,14 +560,18 @@ void DialogSpline::SetSpline(const VSpline &spline) setCurrentPointId(ui->comboBoxP1, spl.GetP1().id()); setCurrentPointId(ui->comboBoxP4, spl.GetP4().id()); - const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula()); - const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula()); + const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula(), + qApp->Settings()->GetOsSeparator()); + const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula(), + qApp->Settings()->GetOsSeparator()); ui->plainTextEditAngle1F->setPlainText(angle1F); ui->plainTextEditAngle2F->setPlainText(angle2F); - const QString length1F = qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula()); - const QString length2F = qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula()); + const QString length1F = qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula(), + qApp->Settings()->GetOsSeparator()); + const QString length2F = qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula(), + qApp->Settings()->GetOsSeparator()); ui->plainTextEditLength1F->setPlainText(length1F); ui->plainTextEditLength2F->setPlainText(length2F); diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 1a4771378..338f00ce6 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -301,7 +301,8 @@ void DialogSplinePath::Angle1Changed() if (row != ui->listWidget->count()-1) { ui->plainTextEditAngle2F->blockSignals(true); - ui->plainTextEditAngle2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle2Formula())); + ui->plainTextEditAngle2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle2Formula(), + qApp->Settings()->GetOsSeparator())); EvalAngle2(); ui->plainTextEditAngle2F->blockSignals(false); } @@ -343,7 +344,8 @@ void DialogSplinePath::Angle2Changed() if (row != 0) { ui->plainTextEditAngle1F->blockSignals(true); - ui->plainTextEditAngle1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle1Formula())); + ui->plainTextEditAngle1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle1Formula(), + qApp->Settings()->GetOsSeparator())); EvalAngle1(); ui->plainTextEditAngle1F->blockSignals(false); } @@ -431,7 +433,7 @@ void DialogSplinePath::FXAngle1() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (angle1F.length() > 80) { @@ -456,7 +458,7 @@ void DialogSplinePath::FXAngle2() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (angle2F.length() > 80) { @@ -481,7 +483,7 @@ void DialogSplinePath::FXLength1() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (length1F.length() > 80) { @@ -506,7 +508,7 @@ void DialogSplinePath::FXLength2() dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); if (dialog->exec() == QDialog::Accepted) { - length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator()); // increase height if needed. if (length2F.length() > 80) { @@ -790,9 +792,11 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p) ui->plainTextEditAngle2F->blockSignals(true); ui->plainTextEditLength2F->blockSignals(true); - ui->plainTextEditAngle2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle2Formula())); + ui->plainTextEditAngle2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle2Formula(), + qApp->Settings()->GetOsSeparator())); EvalAngle2(); - ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length2Formula())); + ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length2Formula(), + qApp->Settings()->GetOsSeparator())); EvalLength2(); ui->plainTextEditAngle2F->blockSignals(false); ui->plainTextEditLength2F->blockSignals(false); @@ -825,9 +829,11 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p) ui->plainTextEditAngle1F->blockSignals(true); ui->plainTextEditLength1F->blockSignals(true); - ui->plainTextEditAngle1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle1Formula())); + ui->plainTextEditAngle1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle1Formula(), + qApp->Settings()->GetOsSeparator())); EvalAngle1(); - ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length1Formula())); + ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length1Formula(), + qApp->Settings()->GetOsSeparator())); EvalLength1(); ui->plainTextEditAngle1F->blockSignals(false); ui->plainTextEditLength1F->blockSignals(false); @@ -849,10 +855,14 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p) ui->plainTextEditAngle2F->blockSignals(true); ui->plainTextEditLength2F->blockSignals(true); - ui->plainTextEditAngle1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle1Formula())); - ui->plainTextEditAngle2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle2Formula())); - ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length1Formula())); - ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length2Formula())); + ui->plainTextEditAngle1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle1Formula(), + qApp->Settings()->GetOsSeparator())); + ui->plainTextEditAngle2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Angle2Formula(), + qApp->Settings()->GetOsSeparator())); + ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length1Formula(), + qApp->Settings()->GetOsSeparator())); + ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(p.Length2Formula(), + qApp->Settings()->GetOsSeparator())); EvalAngle1(); EvalLength1(); diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index c288f9fb8..200a52287 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -49,6 +49,7 @@ #include #include #include +#include Q_LOGGING_CATEGORY(vDialog, "v.dialog") @@ -448,25 +449,34 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt formula.replace("\n", " "); // Translate to internal look. formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); - Calculator *cal = new Calculator(); + QScopedPointer cal(new Calculator()); result = cal->EvalFormula(data->PlainVariables(), formula); - delete cal; - //if result equal 0 - if (checkZero && qFuzzyIsNull(result)) + if (qIsInf(result) || qIsNaN(result)) { flag = false; ChangeColor(labelEditFormula, Qt::red); label->setText(tr("Error") + " (" + postfix + ")"); - label->setToolTip(tr("Value can't be 0")); + label->setToolTip(tr("Invalid value")); } else { - label->setText(qApp->LocaleToString(result) + " " +postfix); - flag = true; - ChangeColor(labelEditFormula, okColor); - label->setToolTip(tr("Value")); - emit ToolTip(""); + //if result equal 0 + if (checkZero && qFuzzyIsNull(result)) + { + flag = false; + ChangeColor(labelEditFormula, Qt::red); + label->setText(tr("Error") + " (" + postfix + ")"); + label->setToolTip(tr("Value can't be 0")); + } + else + { + label->setText(qApp->LocaleToString(result) + " " +postfix); + flag = true; + ChangeColor(labelEditFormula, okColor); + label->setToolTip(tr("Value")); + emit ToolTip(""); + } } } catch (qmu::QmuParserError &e) diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index 5b0bee7ff..f52094158 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -58,5 +58,6 @@ #include "toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h" #include "toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h" #include "toolpoint/tooldoublepoint/vtooltruedarts.h" +#include "operation/vtoolrotation.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp new file mode 100644 index 000000000..9e13392be --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -0,0 +1,1036 @@ +/************************************************************************ + ** + ** @file vtoolrotation.cpp + ** @author Roman Telezhynskyi + ** @date 12 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 "vtoolrotation.h" +#include "../../../dialogs/tools/dialogrotation.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../../../visualization/line/vistoolrotation.h" +#include "../vwidgets/vsimplepoint.h" +#include "../vwidgets/vsimplecurve.h" +#include "../../../undocommands/label/rotationmovelabel.h" +#include "../vpatterndb/vformula.h" + +const QString VToolRotation::ToolType = QStringLiteral("rotation"); +const QString VToolRotation::TagItem = QStringLiteral("item"); +const QString VToolRotation::TagSource = QStringLiteral("source"); +const QString VToolRotation::TagDestination = QStringLiteral("destination"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, + const QString &angle, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent) + : VDrawTool(doc, data, id), + QGraphicsLineItem(parent), + origPointId(origPointId), + formulaAngle(angle), + suffix(suffix), + source(source), + destination(destination), + rObjects() +{ + for (int i = 0; i < destination.size(); ++i) + { + const DestinationItem object = destination.at(i); + const QSharedPointer obj = data->GetGObject(object.id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), *data->GetPatternUnit(), &factor); + point->setParentItem(this); + point->SetType(GOType::Point); + connect(point, &VSimplePoint::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Point); + }); + connect(point, &VSimplePoint::Selected, this, &VToolRotation::ObjectSelected); + connect(point, &VSimplePoint::ShowContextMenu, this, &VToolRotation::contextMenuEvent); + connect(point, &VSimplePoint::Delete, this, &VToolRotation::DeleteFromLabel); + connect(point, &VSimplePoint::NameChangedPosition, this, &VToolRotation::LabelChangePosition); + point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); + rObjects.insert(object.id, point); + break; + } + case GOType::Arc: + case GOType::EllipticalArc: + { + VSimpleCurve *curve = InitCurve(object.id, data, GOType::Arc); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Arc); + }); + break; + } + case GOType::Spline: + case GOType::CubicBezier: + { + VSimpleCurve *curve = InitCurve(object.id, data, GOType::Spline); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Spline); + }); + break; + } + case GOType::SplinePath: + case GOType::CubicBezierPath: + { + VSimpleCurve *curve = InitCurve(object.id, data, GOType::SplinePath); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::SplinePath); + }); + break; + } + case GOType::Unknown: + break; + } +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + } + + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation::~VToolRotation() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogRotation *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetOrigPointId(origPointId); + dialogTool->SetAngle(formulaAngle); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation *VToolRotation::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogRotation *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 originPointId = dialogTool->GetOrigPointId(); + QString angle = dialogTool->GetAngle(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolRotation* operation = Create(0, originPointId, angle, suffix, source, QVector(), + scene, doc, data, Document::FullParse, Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation *VToolRotation::Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix, + const QVector &source, + const QVector &destination, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) +{ + qreal calcAngle = 0; + + calcAngle = CheckFormula(_id, angle, data); + + const auto originPoint = *data->GeometricObject(origin); + const QPointF oPoint = originPoint; + + QVector dest = destination; + + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + dest.clear();// Try to avoid mistake, value must be empty + + id = data->getNextId();//Just reserve id for tool + + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif + switch(static_cast(obj->getType())) + { + case GOType::Point: + dest.append(CreatePoint(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, oPoint, angle, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, + data)); + break; + case GOType::Unknown: + break; + } +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + } + } + else + { + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif + switch(static_cast(obj->getType())) + { + case GOType::Point: + UpdatePoint(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, oPoint, angle, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + + VDrawTool::AddRecord(id, Tool::Rotation, doc); + if (parse == Document::FullParse) + { + VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation); + scene->addItem(tool); + InitRotationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(originPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination) +{ + SCASSERT(doc != nullptr) + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dataElement = nodeList.at(i).toElement(); + if (not dataElement.isNull() && dataElement.tagName() == TagSource) + { + source.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); + } + } + } + + if (not dataElement.isNull() && dataElement.tagName() == TagDestination) + { + destination.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + DestinationItem d; + d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); + d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); + destination.append(d); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolRotation::getTagName() const +{ + return VAbstractPattern::TagOperation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetEnabled(bool enabled) +{ + this->setEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolRotation::GetFormulaAngle() const +{ + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(degreeSymbol); + return fAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetFormulaAngle(const VFormula &value) +{ + if (value.error() == false) + { + formulaAngle = value.GetFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolRotation::Suffix() const +{ + return suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetSuffix(const QString &suffix) +{ + // Don't know if need check name here. + this->suffix = suffix; + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::GroupVisibility(quint32 object, bool visible) +{ + if (rObjects.contains(object)) + { + VAbstractSimple *obj = rObjects.value(object); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + else + { + VSimpleCurve *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::FullUpdateFromFile() +{ + ReadAttributes(); + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowHover(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSelecting(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointHover(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointSelecting(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointLabelHover(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelHover(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointLabelSelecting(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelSelecting(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplineHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplineSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplinePathHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplinePathSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowArcHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowArcSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + } + else + { + qCDebug(vTool, "Can't find tool with id = %u", id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetVisualization() +{ + if (vis != nullptr) + { + VisToolRotation *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetOriginPointId(origPointId); + visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::Disable(bool disable, const QString &namePP) +{ + enabled = !CorrectDisable(disable, namePP); + SetEnabled(enabled); + + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + i.value()->SetEnabled(enabled); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ObjectSelected(bool selected, quint32 objId) +{ + emit ChangedToolSelection(selected, objId, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::DeleteFromLabel() +{ + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::LabelChangePosition(const QPointF &pos, quint32 labelId) +{ + if (rObjects.contains(labelId)) + { + VAbstractSimple *obj = rObjects.value(labelId); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + ChangePosition(item, labelId, pos); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogRotation *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetOrigPointId())); + doc->SetAttribute(domElement, AttrAngle, dialogTool->GetAngle()); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ReadToolAttributes(const QDomElement &domElement) +{ + origPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + formulaAngle = doc->GetParametrString(domElement, AttrAngle, "0"); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId)); + doc->SetAttribute(tag, AttrAngle, formulaAngle); + doc->SetAttribute(tag, AttrSuffix, suffix); + + doc->RemoveAllChildren(tag); + + QDomElement tagObjects = doc->createElement(TagSource); + for (int i = 0; i < source.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, source.at(i)); + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); + + tagObjects = doc->createElement(TagDestination); + for (int i = 0; i < destination.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, destination.at(i).id); + + if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && + not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) + { + doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); + doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); + } + + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my) +{ + if (rObjects.contains(id)) + { + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); + point->setMx(mx); + point->setMy(my); + VAbstractTool::data.UpdateGObject(id, point); + + VSimplePoint *item = qobject_cast(rObjects.value(id)); + SCASSERT(item != nullptr); + + item->RefreshGeometry(*point); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::UpdateNamePosition(quint32 id) +{ + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); + connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition); + qApp->getUndoStack()->push(moveLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = rotated.mx(); + item.my = rotated.my(); + item.id = data->AddGObject(new VPointF(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolRotation::CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolRotation::CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolRotation::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + data->AddCurve(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolRotation::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, + qreal angle, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + rotated.setMx(mx); + rotated.setMy(my); + data->UpdateGObject(id, new VPointF(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + data->UpdateGObject(id, new Item(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + data->AddCurve(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::ShowToolVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + AddVisualization(); + SetVisualization(); + } + else + { + if (T *visual = qobject_cast(vis)) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) +{ + const QPointF p = pos - item->pos(); + DoChangePosition(id, p.x(), p.y()); + UpdateNamePosition(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve *VToolRotation::InitCurve(quint32 id, VContainer *data, GOType curveType) +{ + VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); + curve->setParentItem(this); + curve->SetType(curveType); + connect(curve, &VSimpleCurve::Selected, this, &VToolRotation::ObjectSelected); + connect(curve, &VSimpleCurve::ShowContextMenu, this, &VToolRotation::contextMenuEvent); + connect(curve, &VSimpleCurve::Delete, this, &VToolRotation::DeleteFromLabel); + curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); + rObjects.insert(id, curve); + return curve; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowCurveHover(bool enabled, GOType type) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setAcceptHoverEvents(enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowCurveSelecting(bool enabled, GOType type) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId) +{ + QDomElement obj = doc->createElement(TagItem); + doc->SetAttribute(obj, AttrIdObject, objId); + domElement.appendChild(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::InitRotationToolConnections(VMainGraphicsScene *scene, T *tool) +{ + SCASSERT(scene != nullptr); + SCASSERT(tool != nullptr); + + InitDrawToolConnections(scene, tool); + + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); +} diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h new file mode 100644 index 000000000..3d811b691 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -0,0 +1,187 @@ +/************************************************************************ + ** + ** @file vtoolrotation.h + ** @author Roman Telezhynskyi + ** @date 12 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 VTOOLROTATION_H +#define VTOOLROTATION_H + +#include "../vdrawtool.h" + +struct DestinationItem +{ + quint32 id; + qreal mx; + qreal my; +}; + +class VAbstractSimple; +class VSimpleCurve; +class VFormula; + +// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. +// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. +// And i don't know how to fix it. +class VToolRotation : public VDrawTool, public QGraphicsLineItem +{ + Q_OBJECT + // Fix warning "Class implements the interface QGraphicsItem but does not list it + // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" + Q_INTERFACES(QGraphicsItem) +public: + virtual ~VToolRotation(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolRotation* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &formulaAngle, const QString &suffix, + const QVector &source, const QVector &destination, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); + static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination); + static const QString ToolType; + static const QString TagItem; + static const QString TagSource; + static const QString TagDestination; + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::Rotation)}; + virtual QString getTagName() const Q_DECL_OVERRIDE; + + void SetEnabled(bool enabled); + + VFormula GetFormulaAngle() const; + void SetFormulaAngle(const VFormula &value); + + QString Suffix() const; + void SetSuffix(const QString &suffix); + + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; + +public slots: + virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; + virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; + + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + + void AllowPointHover(bool enabled); + void AllowPointSelecting(bool enabled); + + void AllowPointLabelHover(bool enabled); + void AllowPointLabelSelecting(bool enabled); + + void AllowSplineHover(bool enabled); + void AllowSplineSelecting(bool enabled); + + void AllowSplinePathHover(bool enabled); + void AllowSplinePathSelecting(bool enabled); + + void AllowArcHover(bool enabled); + void AllowArcSelecting(bool enabled); + + virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; + void ObjectSelected(bool selected, quint32 objId); + void DeleteFromLabel(); + void LabelChangePosition(const QPointF &pos, quint32 labelId); + +protected: + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; + +private slots: + void DoChangePosition(quint32 id, qreal mx, qreal my); + +private: + Q_DISABLE_COPY(VToolRotation) + quint32 origPointId; + QString formulaAngle; + QString suffix; + + QVector source; + QVector destination; + + QMap rObjects; + + VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, + const QString &formulaAngle, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); + + void UpdateNamePosition(quint32 id); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, + const QString &suffix, VContainer *data, quint32 id); + + template + void ShowToolVisualization(bool show); + + void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); + + VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); + + template + static void InitRotationToolConnections(VMainGraphicsScene *scene, T *tool); + + void AllowCurveHover(bool enabled, GOType type); + void AllowCurveSelecting(bool enabled, GOType type); + + static void AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId); +}; + +#endif // VTOOLROTATION_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index b81d06eeb..57faed240 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -32,8 +32,6 @@ #include -const QString VAbstractSpline::TagName = QStringLiteral("spline"); - //--------------------------------------------------------------------------------------------------------------------- VAbstractSpline::VAbstractSpline(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent) :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()), @@ -49,7 +47,7 @@ VAbstractSpline::~VAbstractSpline() //--------------------------------------------------------------------------------------------------------------------- QString VAbstractSpline::getTagName() const { - return VAbstractSpline::TagName; + return VAbstractPattern::TagSpline; } //--------------------------------------------------------------------------------------------------------------------- @@ -67,7 +65,8 @@ void VAbstractSpline::Disable(bool disable, const QString &namePP) { enabled = !CorrectDisable(disable, namePP); this->setEnabled(enabled); - this->setPen(QPen(CorrectColor(lineColor), + const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(curve->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, Qt::SolidLine, Qt::RoundCap)); emit setEnabledPoint(enabled); @@ -124,7 +123,8 @@ void VAbstractSpline::SetFactor(qreal factor) void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(lineColor), + const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(curve->GetColor()), qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor, Qt::SolidLine, Qt::RoundCap)); this->setPath(ToolPath(PathDirection::Show)); @@ -141,7 +141,8 @@ void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(lineColor), + const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(curve->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); if (detailsMode) { @@ -203,6 +204,13 @@ void VAbstractSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsPathItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event } @@ -233,7 +241,7 @@ QPainterPath VAbstractSpline::ToolPath(PathDirection direction) const //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::ReadToolAttributes(const QDomElement &domElement) { - lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); + Q_UNUSED(domElement) } //--------------------------------------------------------------------------------------------------------------------- @@ -241,7 +249,8 @@ void VAbstractSpline::SaveOptions(QDomElement &tag, QSharedPointer &ob { VDrawTool::SaveOptions(tag, obj); - doc->SetAttribute(tag, AttrColor, lineColor); + const QSharedPointer curve = qSharedPointerCast(obj); + doc->SetAttribute(tag, AttrColor, curve->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -251,7 +260,7 @@ VSpline VAbstractSpline::CorrectedSpline(const VSpline &spline, const SplinePoin VSpline spl; if (position == SplinePointPosition::FirstPoint) { - QLineF line(spline.GetP1().toQPointF(), pos); + QLineF line(spline.GetP1(), pos); qreal newAngle1 = line.angle(); QString newAngle1F = QString().setNum(newAngle1); @@ -277,7 +286,7 @@ VSpline VAbstractSpline::CorrectedSpline(const VSpline &spline, const SplinePoin } else { - QLineF line(spline.GetP4().toQPointF(), pos); + QLineF line(spline.GetP4(), pos); qreal newAngle2 = line.angle(); QString newAngle2F = QString().setNum(newAngle2); @@ -319,7 +328,8 @@ void VAbstractSpline::setEnabled(bool enabled) QGraphicsPathItem::setEnabled(enabled); if (enabled) { - setPen(QPen(QColor(lineColor), + const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + setPen(QPen(QColor(curve->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } else @@ -329,6 +339,22 @@ void VAbstractSpline::setEnabled(bool enabled) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractSpline::GetLineColor() const +{ + const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + return curve->GetColor(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::SetLineColor(const QString &value) +{ + QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + curve->SetColor(value); + QSharedPointer obj = qSharedPointerCast(curve); + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractSpline::name() const { diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 89f2548f2..148d499b0 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -42,8 +42,7 @@ class VAbstractSpline:public VDrawTool, public QGraphicsPathItem public: VAbstractSpline(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); virtual ~VAbstractSpline() Q_DECL_OVERRIDE; - // cppcheck-suppress duplInheritedMember - static const QString TagName; + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::AbstractSpline)}; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -51,6 +50,9 @@ public: void setEnabled(bool enabled); + QString GetLineColor() const; + void SetLineColor(const QString &value); + QString name() const; virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index c35e0f0f4..bdf23acc2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -36,7 +36,6 @@ #include -const QString VToolArc::TagName = QStringLiteral("arc"); const QString VToolArc::ToolType = QStringLiteral("simple"); //--------------------------------------------------------------------------------------------------------------------- @@ -48,13 +47,11 @@ const QString VToolArc::ToolType = QStringLiteral("simple"); * @param typeCreation way we create this tool. * @param parent parent object */ -VToolArc::VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, +VToolArc::VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) { sceneType = SceneObject::Arc; - lineColor = color; this->setPath(ToolPath()); this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); @@ -77,7 +74,7 @@ void VToolArc::setDialog() dialogTool->SetF1(arc->GetFormulaF1()); dialogTool->SetF2(arc->GetFormulaF2()); dialogTool->SetRadius(arc->GetFormulaRadius()); - dialogTool->SetColor(lineColor); + dialogTool->SetColor(arc->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -134,6 +131,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra const VPointF c = *data->GeometricObject(center); VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 ); + arc->SetColor(color); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -152,7 +150,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra VDrawTool::AddRecord(id, Tool::Arc, doc); if (parse == Document::FullParse) { - VToolArc *toolArc = new VToolArc(doc, data, id, color, typeCreation); + VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); scene->addItem(toolArc); InitArcToolConnections(scene, toolArc); doc->AddTool(id, toolArc); @@ -165,7 +163,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra //--------------------------------------------------------------------------------------------------------------------- QString VToolArc::getTagName() const { - return VToolArc::TagName; + return VAbstractPattern::TagArc; } //--------------------------------------------------------------------------------------------------------------------- @@ -352,9 +350,9 @@ void VToolArc::SetVisualization() const VTranslateVars *trVars = qApp->TrVars(); visual->setObject1Id(arc->GetCenter().id()); - visual->setRadius(trVars->FormulaToUser(arc->GetFormulaRadius())); - visual->setF1(trVars->FormulaToUser(arc->GetFormulaF1())); - visual->setF2(trVars->FormulaToUser(arc->GetFormulaF2())); + visual->setRadius(trVars->FormulaToUser(arc->GetFormulaRadius(), qApp->Settings()->GetOsSeparator())); + visual->setF1(trVars->FormulaToUser(arc->GetFormulaF1(), qApp->Settings()->GetOsSeparator())); + visual->setF2(trVars->FormulaToUser(arc->GetFormulaF2(), qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); } } @@ -365,7 +363,8 @@ void VToolArc::SetVisualization() */ void VToolArc::RefreshGeometry() { - this->setPen(QPen(CorrectColor(lineColor), + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(arc->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setPath(ToolPath()); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h index cbcd0f33c..27e040b45 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h @@ -40,14 +40,12 @@ class VToolArc :public VAbstractSpline { Q_OBJECT public: - VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolArc* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolArc* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); - static const QString TagName; + static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Arc)}; @@ -73,6 +71,11 @@ protected: virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolArc) + + VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem * parent = nullptr); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index 7b5ff3e6f..757706536 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -36,16 +36,14 @@ #include -const QString VToolArcWithLength::TagName = QStringLiteral("arc"); const QString VToolArcWithLength::ToolType = QStringLiteral("arcWithLength"); //--------------------------------------------------------------------------------------------------------------------- -VToolArcWithLength::VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, QGraphicsItem *parent) +VToolArcWithLength::VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) { sceneType = SceneObject::Arc; - lineColor = color; this->setPath(ToolPath()); this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); @@ -65,7 +63,7 @@ void VToolArcWithLength::setDialog() dialogTool->SetF1(arc->GetFormulaF1()); dialogTool->SetLength(arc->GetFormulaLength()); dialogTool->SetRadius(arc->GetFormulaRadius()); - dialogTool->SetColor(lineColor); + dialogTool->SetColor(arc->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -103,6 +101,7 @@ VToolArcWithLength *VToolArcWithLength::Create(const quint32 _id, const quint32 const VPointF c = *data->GeometricObject(center); VArc *arc = new VArc(calcLength, length, c, calcRadius, radius, calcF1, f1); + arc->SetColor(color); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -121,7 +120,7 @@ VToolArcWithLength *VToolArcWithLength::Create(const quint32 _id, const quint32 VDrawTool::AddRecord(id, Tool::ArcWithLength, doc); if (parse == Document::FullParse) { - VToolArcWithLength *toolArc = new VToolArcWithLength(doc, data, id, color, typeCreation); + VToolArcWithLength *toolArc = new VToolArcWithLength(doc, data, id, typeCreation); scene->addItem(toolArc); InitArcToolConnections(scene, toolArc); doc->AddTool(id, toolArc); @@ -134,7 +133,7 @@ VToolArcWithLength *VToolArcWithLength::Create(const quint32 _id, const quint32 //--------------------------------------------------------------------------------------------------------------------- QString VToolArcWithLength::getTagName() const { - return VToolArcWithLength::TagName; + return VAbstractPattern::TagArc; } //--------------------------------------------------------------------------------------------------------------------- @@ -308,9 +307,9 @@ void VToolArcWithLength::SetVisualization() const VTranslateVars *trVars = qApp->TrVars(); visual->setObject1Id(arc->GetCenter().id()); - visual->setRadius(trVars->FormulaToUser(arc->GetFormulaRadius())); - visual->setF1(trVars->FormulaToUser(arc->GetFormulaF1())); - visual->setLength(trVars->FormulaToUser(arc->GetFormulaLength())); + visual->setRadius(trVars->FormulaToUser(arc->GetFormulaRadius(), qApp->Settings()->GetOsSeparator())); + visual->setF1(trVars->FormulaToUser(arc->GetFormulaF1(), qApp->Settings()->GetOsSeparator())); + visual->setLength(trVars->FormulaToUser(arc->GetFormulaLength(), qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); } } @@ -318,7 +317,8 @@ void VToolArcWithLength::SetVisualization() //--------------------------------------------------------------------------------------------------------------------- void VToolArcWithLength::RefreshGeometry() { - this->setPen(QPen(CorrectColor(lineColor), + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(arc->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setPath(ToolPath()); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h index e0446548a..ee0d718e5 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h @@ -37,18 +37,14 @@ class VToolArcWithLength : public VAbstractSpline { Q_OBJECT public: - VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, - QGraphicsItem * parent = nullptr); - virtual void setDialog() Q_DECL_OVERRIDE; static VToolArcWithLength* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolArcWithLength* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, - QString &length, const QString &color, VMainGraphicsScene *scene, - VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); - static const QString TagName; + QString &length, const QString &color, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::ArcWithLength)}; @@ -74,6 +70,11 @@ protected: virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolArcWithLength) + + VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem * parent = nullptr); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp index 35f000c6a..ab3e81eb6 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp @@ -35,12 +35,11 @@ const QString VToolCubicBezier::ToolType = QStringLiteral("cubicBezier"); //--------------------------------------------------------------------------------------------------------------------- -VToolCubicBezier::VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, +VToolCubicBezier::VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) { sceneType = SceneObject::Spline; - lineColor = color; this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setPath(ToolPath()); @@ -62,7 +61,7 @@ void VToolCubicBezier::setDialog() SCASSERT(dialogTool != nullptr); const auto spl = VAbstractTool::data.GeometricObject(id); dialogTool->SetSpline(*spl); - dialogTool->SetColor(lineColor); + dialogTool->SetColor(spl->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -89,6 +88,7 @@ VToolCubicBezier *VToolCubicBezier::Create(const quint32 _id, VCubicBezier *spli const Document &parse, const Source &typeCreation) { quint32 id = _id; + spline->SetColor(color); if (typeCreation == Source::FromGui) { id = data->AddGObject(spline); @@ -106,7 +106,7 @@ VToolCubicBezier *VToolCubicBezier::Create(const quint32 _id, VCubicBezier *spli VDrawTool::AddRecord(id, Tool::CubicBezier, doc); if (parse == Document::FullParse) { - auto _spl = new VToolCubicBezier(doc, data, id, color, typeCreation); + auto _spl = new VToolCubicBezier(doc, data, id, typeCreation); scene->addItem(_spl); InitSplineToolConnections(scene, _spl); doc->AddTool(id, _spl); @@ -209,7 +209,8 @@ void VToolCubicBezier::SetVisualization() //--------------------------------------------------------------------------------------------------------------------- void VToolCubicBezier::RefreshGeometry() { - this->setPen(QPen(CorrectColor(lineColor), + const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(spl->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); if (isHovered || detailsMode) { diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h index ca8d53ed8..53be60915 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h @@ -37,8 +37,6 @@ class VToolCubicBezier : public VAbstractSpline { Q_OBJECT public: - VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual ~VToolCubicBezier(); virtual void setDialog() Q_DECL_OVERRIDE; static VToolCubicBezier *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, @@ -63,6 +61,9 @@ protected: private: Q_DISABLE_COPY(VToolCubicBezier) + VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem * parent = nullptr); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp index a5febd61e..db00f4325 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp @@ -33,12 +33,11 @@ const QString VToolCubicBezierPath::ToolType = QStringLiteral("cubicBezierPath"); //--------------------------------------------------------------------------------------------------------------------- -VToolCubicBezierPath::VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, +VToolCubicBezierPath::VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent) : VAbstractSpline(doc, data, id, parent) { sceneType = SceneObject::SplinePath; - lineColor = color; this->setPath(ToolPath()); this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); @@ -60,7 +59,7 @@ void VToolCubicBezierPath::setDialog() SCASSERT(dialogTool != nullptr); const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); dialogTool->SetPath(*splPath); - dialogTool->SetColor(lineColor); + dialogTool->SetColor(splPath->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -90,6 +89,7 @@ VToolCubicBezierPath *VToolCubicBezierPath::Create(const quint32 _id, VCubicBezi const Document &parse, const Source &typeCreation) { quint32 id = _id; + path->SetColor(color); if (typeCreation == Source::FromGui) { id = data->AddGObject(path); @@ -107,7 +107,7 @@ VToolCubicBezierPath *VToolCubicBezierPath::Create(const quint32 _id, VCubicBezi VDrawTool::AddRecord(id, Tool::CubicBezierPath, doc); if (parse == Document::FullParse) { - VToolCubicBezierPath *spl = new VToolCubicBezierPath(doc, data, id, color, typeCreation); + VToolCubicBezierPath *spl = new VToolCubicBezierPath(doc, data, id, typeCreation); scene->addItem(spl); InitSplinePathToolConnections(scene, spl); doc->AddTool(id, spl); @@ -214,7 +214,8 @@ void VToolCubicBezierPath::RefreshGeometry() { isHovered || detailsMode ? setPath(ToolPath(PathDirection::Show)) : setPath(ToolPath()); - this->setPen(QPen(CorrectColor(lineColor), + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(splPath->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); SetVisualization(); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h index 29089fe2b..7761f8dee 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h @@ -37,8 +37,6 @@ class VToolCubicBezierPath:public VAbstractSpline { Q_OBJECT public: - VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual ~VToolCubicBezierPath(); virtual void setDialog() Q_DECL_OVERRIDE; static VToolCubicBezierPath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, @@ -65,6 +63,9 @@ protected: private: Q_DISABLE_COPY(VToolCubicBezierPath) + VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, + const Source &typeCreation, QGraphicsItem * parent = nullptr); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint); void SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 1857ef870..71404d2b5 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -52,13 +52,11 @@ const QString VToolSpline::OldToolType = QStringLiteral("simple"); * @param typeCreation way we create this tool. * @param parent parent object. */ -VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, +VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent), oldPosition() { sceneType = SceneObject::Spline; - lineColor = color; this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -71,7 +69,7 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula()); auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(), - spl->GetP1().toQPointF(), *data->GetPatternUnit(), freeAngle1, + spl->GetP1(), *data->GetPatternUnit(), freeAngle1, freeLength1, this); connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); @@ -83,7 +81,7 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula()); auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(), - spl->GetP4().toQPointF(), *data->GetPatternUnit(), freeAngle2, + spl->GetP4(), *data->GetPatternUnit(), freeAngle2, freeLength2, this); connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); @@ -114,7 +112,7 @@ void VToolSpline::setDialog() SCASSERT(dialogTool != nullptr); const auto spl = VAbstractTool::data.GeometricObject(id); dialogTool->SetSpline(*spl); - dialogTool->SetColor(lineColor); + dialogTool->SetColor(spl->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -132,8 +130,9 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, auto dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); - auto spl = Create(0, new VSpline(dialogTool->GetSpline()), dialogTool->GetColor(), scene, doc, data, - Document::FullParse, Source::FromGui); + VSpline *spline = new VSpline(dialogTool->GetSpline()); + + auto spl = Create(0, spline, dialogTool->GetColor(), scene, doc, data, Document::FullParse, Source::FromGui); if (spl != nullptr) { @@ -147,7 +146,6 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, * @brief Create help create tool. * @param _id tool id, 0 if tool doesn't exist yet. * @param spline spline. - * @param color spline color. * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. @@ -160,6 +158,7 @@ VToolSpline* VToolSpline::Create(const quint32 _id, VSpline *spline, const QStri const Source &typeCreation) { quint32 id = _id; + spline->SetColor(color); if (typeCreation == Source::FromGui) { id = data->AddGObject(spline); @@ -177,7 +176,7 @@ VToolSpline* VToolSpline::Create(const quint32 _id, VSpline *spline, const QStri VDrawTool::AddRecord(id, Tool::Spline, doc); if (parse == Document::FullParse) { - auto _spl = new VToolSpline(doc, data, id, color, typeCreation); + auto _spl = new VToolSpline(doc, data, id, typeCreation); scene->addItem(_spl); InitSplineToolConnections(scene, _spl); doc->AddTool(id, _spl); @@ -248,7 +247,7 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp const QSharedPointer spline = VAbstractTool::data.GeometricObject(id); const VSpline spl = CorrectedSpline(*spline, position, pos); - MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, id, this->scene()); + MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, id); connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(moveSpl); } @@ -408,7 +407,7 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) VSpline spl = VSpline(spline->GetP1(), p2, p3, spline->GetP4()); - MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, id, this->scene()); + MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, id); connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(moveSpl); @@ -508,7 +507,9 @@ void VToolSpline::RefreshGeometry() point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); } - this->setPen(QPen(CorrectColor(lineColor), + const auto spl = VAbstractTool::data.GeometricObject(id); + + this->setPen(QPen(CorrectColor(spl->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); if (isHovered || detailsMode) { @@ -522,13 +523,11 @@ void VToolSpline::RefreshGeometry() controlPoints[0]->blockSignals(true); controlPoints[1]->blockSignals(true); - const auto spl = VAbstractTool::data.GeometricObject(id); - { const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula()); const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula()); - const QPointF splinePoint = VAbstractTool::data.GeometricObject(spl->GetP1().id())->toQPointF(); + const QPointF splinePoint = *VAbstractTool::data.GeometricObject(spl->GetP1().id()); controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, spl->GetP2(), splinePoint, freeAngle1, freeLength1); } @@ -537,7 +536,7 @@ void VToolSpline::RefreshGeometry() const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl->GetEndAngleFormula()); const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula()); - const QPointF splinePoint = VAbstractTool::data.GeometricObject(spl->GetP4().id())->toQPointF(); + const QPointF splinePoint = *VAbstractTool::data.GeometricObject(spl->GetP4().id()); controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, spl->GetP3(), splinePoint, freeAngle2, freeLength2); } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index e404087a6..344e9542f 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -40,8 +40,6 @@ class VToolSpline:public VAbstractSpline { Q_OBJECT public: - VToolSpline (VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, const Source &typeCreation, - QGraphicsItem * parent = nullptr ); virtual ~VToolSpline() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; static VToolSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -80,6 +78,9 @@ private: Q_DISABLE_COPY(VToolSpline) QPointF oldPosition; + VToolSpline (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem * parent = nullptr ); + bool IsMovable() const; virtual void RefreshGeometry() Q_DECL_OVERRIDE; void SetSplineAttributes(QDomElement &domElement, const VSpline &spl); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index 9a09d2beb..1ebb410b0 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -51,14 +51,13 @@ const QString VToolSplinePath::OldToolType = QStringLiteral("path"); * @param typeCreation way we create this tool. * @param parent parent object. */ -VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, QGraphicsItem *parent) +VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem *parent) : VAbstractSpline(doc, data, id, parent), oldPosition(), splIndex(-1) { sceneType = SceneObject::SplinePath; - lineColor = color; this->setPath(ToolPath()); this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); @@ -74,7 +73,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl.GetC1LengthFormula()); auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(), - spl.GetP1().toQPointF(), *data->GetPatternUnit(), freeAngle1, + spl.GetP1(), *data->GetPatternUnit(), freeAngle1, freeLength1, this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); @@ -85,7 +84,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl.GetEndAngleFormula()); const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl.GetC2LengthFormula()); - controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, spl.GetP3(), spl.GetP4().toQPointF(), + controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, spl.GetP3(), spl.GetP4(), *data->GetPatternUnit(), freeAngle2, freeLength2, this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); @@ -117,7 +116,7 @@ void VToolSplinePath::setDialog() SCASSERT(dialogTool != nullptr); const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); dialogTool->SetPath(*splPath); - dialogTool->SetColor(lineColor); + dialogTool->SetColor(splPath->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -135,12 +134,12 @@ VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene DialogSplinePath *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); VSplinePath *path = new VSplinePath(dialogTool->GetPath()); - const QString color = dialogTool->GetColor(); for (qint32 i = 0; i < path->CountPoints(); ++i) { doc->IncrementReferens((*path)[i].P().getIdTool()); } - VToolSplinePath* spl = Create(0, path, color, scene, doc, data, Document::FullParse, Source::FromGui); + VToolSplinePath* spl = Create(0, path, dialogTool->GetColor(), scene, doc, data, Document::FullParse, + Source::FromGui); if (spl != nullptr) { spl->dialog=dialogTool; @@ -164,6 +163,7 @@ VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, c const Document &parse, const Source &typeCreation) { quint32 id = _id; + path->SetColor(color); if (typeCreation == Source::FromGui) { id = data->AddGObject(path); @@ -181,7 +181,7 @@ VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, c VDrawTool::AddRecord(id, Tool::SplinePath, doc); if (parse == Document::FullParse) { - VToolSplinePath *spl = new VToolSplinePath(doc, data, id, color, typeCreation); + VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); scene->addItem(spl); InitSplinePathToolConnections(scene, spl); doc->AddTool(id, spl); @@ -230,7 +230,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons const VSpline spl = CorrectedSpline(newSplPath.GetSpline(indexSpline), position, pos); UpdateControlPoints(spl, newSplPath, indexSpline); - MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id, this->scene()); + MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id); connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(moveSplPath); } @@ -521,7 +521,7 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event) UpdateControlPoints(spl, newSplPath, splIndex); - MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id, this->scene()); + MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id); connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(moveSplPath); @@ -631,10 +631,10 @@ void VToolSplinePath::RefreshGeometry() this->setPath(ToolPath()); } - this->setPen(QPen(CorrectColor(lineColor), + const auto splPath = VAbstractTool::data.GeometricObject(id); + this->setPen(QPen(CorrectColor(splPath->GetColor()), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); - const auto splPath = VAbstractTool::data.GeometricObject(id); for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { const qint32 j = i*2; @@ -648,7 +648,7 @@ void VToolSplinePath::RefreshGeometry() const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl.GetStartAngleFormula()); const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl.GetC1LengthFormula()); - const auto splinePoint = spl.GetP1().toQPointF(); + const auto splinePoint = spl.GetP1(); controlPoints[j-2]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), splinePoint, freeAngle1, freeLength1); } @@ -657,7 +657,7 @@ void VToolSplinePath::RefreshGeometry() const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl.GetEndAngleFormula()); const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl.GetC2LengthFormula()); - const auto splinePoint = spl.GetP4().toQPointF(); + const auto splinePoint = spl.GetP4(); controlPoints[j-1]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), splinePoint, freeAngle2, freeLength2); } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index a7035225e..b6e963332 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -42,18 +42,13 @@ class VToolSplinePath:public VAbstractSpline { Q_OBJECT public: - VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, - const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual ~VToolSplinePath() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, const QString &color, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation); - + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); static VToolSplinePath *Create(const quint32 _id, const QVector &points, QVector &a1, QVector &a2, QVector &l1, QVector &l2, const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, @@ -104,6 +99,9 @@ private: QPointF oldPosition; int splIndex; + VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + QGraphicsItem *parent = nullptr); + bool IsMovable(int index) const; virtual void RefreshGeometry() Q_DECL_OVERRIDE; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index bbb9fa9b3..830fa8982 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -29,7 +29,7 @@ #include "vtooldoublepoint.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" -#include "../../../../undocommands/movedoublelabel.h" +#include "../../../../undocommands/label/movedoublelabel.h" #include @@ -238,7 +238,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id) { const VPointF *p1 = VAbstractTool::data.GeometricObject(p1id).data(); - auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, p1id, scene()); + auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, p1id); connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); qApp->getUndoStack()->push(moveLabel); } @@ -246,8 +246,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id) { const VPointF *p2 = VAbstractTool::data.GeometricObject(p2id).data(); - auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id, - scene()); + auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id); connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); qApp->getUndoStack()->push(moveLabel); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp index 822a7bd8f..4fa80b2f2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp @@ -146,8 +146,7 @@ VToolTrueDarts *VToolTrueDarts::Create(quint32 _id, QPointF fPoint1; QPointF fPoint2; - VToolTrueDarts::FindPoint(baseLineP1->toQPointF(), baseLineP2->toQPointF(), - dartP1->toQPointF(), dartP2->toQPointF(), dartP3->toQPointF(), fPoint1, fPoint2); + VToolTrueDarts::FindPoint(*baseLineP1, *baseLineP2, *dartP1, *dartP2, *dartP3, fPoint1, fPoint2); quint32 id = _id; quint32 p1id = _p1id; quint32 p2id = _p2id; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h index 4aa074f6d..4832d1a19 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h @@ -35,19 +35,6 @@ class VToolTrueDarts : public VToolDoublePoint { Q_OBJECT public: - VToolTrueDarts(VAbstractPattern *doc, - VContainer *data, - const quint32 &id, - const quint32 &p1id, - const quint32 &p2id, - const quint32 &baseLineP1Id, - const quint32 &baseLineP2Id, - const quint32 &dartP1Id, - const quint32 &dartP2Id, - const quint32 &dartP3Id, - const Source &typeCreation, - QGraphicsItem * parent = nullptr); - static void FindPoint(const QPointF &baseLineP1, const QPointF &baseLineP2, const QPointF &dartP1, const QPointF &dartP2, const QPointF &dartP3, QPointF &p1, QPointF &p2); virtual void setDialog() Q_DECL_OVERRIDE; @@ -100,6 +87,19 @@ private: quint32 dartP1Id; quint32 dartP2Id; quint32 dartP3Id; + + VToolTrueDarts(VAbstractPattern *doc, + VContainer *data, + const quint32 &id, + const quint32 &p1id, + const quint32 &p2id, + const quint32 &baseLineP1Id, + const quint32 &baseLineP2Id, + const quint32 &dartP1Id, + const quint32 &dartP2Id, + const quint32 &dartP3Id, + const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLTRUEDARTS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index d78c488e3..4082a8e76 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -32,12 +32,10 @@ //--------------------------------------------------------------------------------------------------------------------- VToolCut::VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &curveCutId, const QString &color, QGraphicsItem *parent) + const quint32 &curveCutId, QGraphicsItem *parent) :VToolSinglePoint(doc, data, id, parent), formula(formula), curveCutId(curveCutId), detailsMode(false) { Q_ASSERT_X(curveCutId != 0, Q_FUNC_INFO, "curveCutId == 0"); //-V654 //-V712 - - lineColor = color; } //--------------------------------------------------------------------------------------------------------------------- @@ -137,11 +135,3 @@ void VToolCut::FullUpdateCurveFromFile(const QString &attrCurve) curveCutId = domElement.attribute(attrCurve, "").toUInt(); } } - -//--------------------------------------------------------------------------------------------------------------------- -void VToolCut::SaveOptions(QDomElement &tag, QSharedPointer &obj) -{ - VToolSinglePoint::SaveOptions(tag, obj); - - doc->SetAttribute(tag, AttrColor, lineColor); -} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h index 8e580a250..a44a7a72d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h @@ -39,7 +39,7 @@ class VToolCut : public VToolSinglePoint Q_OBJECT public: VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &curveCutId, const QString &color, QGraphicsItem * parent = nullptr); + const quint32 &curveCutId, QGraphicsItem * parent = nullptr); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Cut)}; @@ -63,7 +63,6 @@ protected: void RefreshGeometry(); virtual void RemoveReferens() Q_DECL_OVERRIDE; void FullUpdateCurveFromFile(const QString &attrCurve); - virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; template void ShowToolVisualization(bool show); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 181a464e5..ab4bda056 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -44,14 +44,12 @@ const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); * @param id object id in container. * @param formula string with formula length first arc. * @param arcId id arc in data container. - * @param color arc color. * @param typeCreation way we create this tool. * @param parent parent object. */ VToolCutArc::VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &arcId, const QString &color, const Source &typeCreation, - QGraphicsItem * parent) - :VToolCut(doc, data, id, formula, arcId, color, parent) + const quint32 &arcId, const Source &typeCreation, QGraphicsItem * parent) + :VToolCut(doc, data, id, formula, arcId, parent) { ToolCreation(typeCreation); } @@ -69,7 +67,6 @@ void VToolCutArc::setDialog() dialogTool->SetFormula(formula); dialogTool->setArcId(curveCutId); dialogTool->SetPointName(point->name()); - dialogTool->SetColor(lineColor); } //--------------------------------------------------------------------------------------------------------------------- @@ -88,8 +85,7 @@ VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->GetFormula(); const quint32 arcId = dialogTool->getArcId(); - const QString color = dialogTool->GetColor(); - VToolCutArc* point = Create(0, pointName, formula, arcId, 5, 10, color, scene, doc, data, Document::FullParse, + VToolCutArc* point = Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { @@ -114,9 +110,8 @@ VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, * @param typeCreation way we create this tool. */ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId, - const qreal &mx, const qreal &my, const QString &color, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation) { const QSharedPointer arc = data->GeometricObject(arcId); @@ -155,7 +150,7 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS VDrawTool::AddRecord(id, Tool::CutArc, doc); if (parse == Document::FullParse) { - VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, color, typeCreation); + VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, typeCreation); scene->addItem(point); InitToolConnections(scene, point); doc->AddTool(id, point); @@ -201,7 +196,6 @@ void VToolCutArc::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula()); doc->SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId())); - doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -219,7 +213,6 @@ void VToolCutArc::ReadToolAttributes(const QDomElement &domElement) { formula = doc->GetParametrString(domElement, AttrLength, ""); curveCutId = doc->GetParametrUInt(domElement, AttrArc, NULL_ID_STR); - lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); } //--------------------------------------------------------------------------------------------------------------------- @@ -231,7 +224,7 @@ void VToolCutArc::SetVisualization() SCASSERT(visual != nullptr); visual->setObject1Id(curveCutId); - visual->setLength(qApp->TrVars()->FormulaToUser(formula)); + visual->setLength(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h index 94d6944c5..de0140e92 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h @@ -38,13 +38,10 @@ class VToolCutArc : public VToolCut { Q_OBJECT public: - VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &arcId, const QString &color, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolCutArc* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolCutArc* Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId, - const qreal &mx, const qreal &my, const QString &color, VMainGraphicsScene *scene, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; @@ -59,6 +56,9 @@ protected: virtual void SetVisualization() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolCutArc) + + VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &arcId, const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLCUTARC_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 2f959f3bc..a3b755e22 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -45,14 +45,12 @@ const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); * @param id object id in container. * @param formula string with formula length first spline. * @param splineId id spline in data container. - * @param color spline color. * @param typeCreation way we create this tool. * @param parent parent object. */ VToolCutSpline::VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &splineId, const QString &color, const Source &typeCreation, - QGraphicsItem *parent) - :VToolCut(doc, data, id, formula, splineId, color, parent) + const quint32 &splineId, const Source &typeCreation, QGraphicsItem *parent) + :VToolCut(doc, data, id, formula, splineId, parent) { ToolCreation(typeCreation); } @@ -70,7 +68,6 @@ void VToolCutSpline::setDialog() dialogTool->SetFormula(formula); dialogTool->setSplineId(curveCutId); dialogTool->SetPointName(point->name()); - dialogTool->SetColor(lineColor); } //--------------------------------------------------------------------------------------------------------------------- @@ -90,8 +87,7 @@ VToolCutSpline* VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *s const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->GetFormula(); const quint32 splineId = dialogTool->getSplineId(); - const QString color = dialogTool->GetColor(); - VToolCutSpline* point = Create(0, pointName, formula, splineId, 5, 10, color, scene, doc, data, Document::FullParse, + VToolCutSpline* point = Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { @@ -116,7 +112,7 @@ VToolCutSpline* VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *s * @param typeCreation way we create this tool. */ VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula, - const quint32 &splineId, const qreal &mx, const qreal &my, const QString &color, + const quint32 &splineId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { @@ -152,7 +148,7 @@ VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointNa VDrawTool::AddRecord(id, Tool::CutSpline, doc); if (parse == Document::FullParse) { - VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, color, typeCreation); + VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, typeCreation); scene->addItem(point); InitToolConnections(scene, point); doc->AddTool(id, point); @@ -198,7 +194,6 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula()); doc->SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId())); - doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -216,7 +211,6 @@ void VToolCutSpline::ReadToolAttributes(const QDomElement &domElement) { formula = doc->GetParametrString(domElement, AttrLength, ""); curveCutId = doc->GetParametrUInt(domElement, AttrSpline, NULL_ID_STR); - lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); } //--------------------------------------------------------------------------------------------------------------------- @@ -228,7 +222,7 @@ void VToolCutSpline::SetVisualization() SCASSERT(visual != nullptr); visual->setObject1Id(curveCutId); - visual->setLength(qApp->TrVars()->FormulaToUser(formula)); + visual->setLength(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h index 84e0fc3bd..7f614aadf 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h @@ -38,15 +38,11 @@ class VToolCutSpline : public VToolCut { Q_OBJECT public: - - VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &splineId, const QString &color, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolCutSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolCutSpline *Create(const quint32 _id, const QString &pointName, QString &formula, - const quint32 &splineId, const qreal &mx, const qreal &my, const QString &color, + const quint32 &splineId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); @@ -63,6 +59,9 @@ protected: virtual void SetVisualization() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolCutSpline) + + VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &splineId, const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLCUTSPLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index dec424071..463debfb0 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -45,14 +45,13 @@ const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); * @param id object id in container. * @param formula string with formula length first splinePath. * @param splinePathId id splinePath (we cut this splinePath) in data container. - * @param color spline path color. * @param typeCreation way we create this tool. * @param parent parent object. */ VToolCutSplinePath::VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &splinePathId, - const QString &color, const Source &typeCreation, QGraphicsItem *parent) - :VToolCut(doc, data, id, formula, splinePathId, color, parent) + const Source &typeCreation, QGraphicsItem *parent) + :VToolCut(doc, data, id, formula, splinePathId, parent) { ToolCreation(typeCreation); } @@ -70,7 +69,6 @@ void VToolCutSplinePath::setDialog() dialogTool->SetFormula(formula); dialogTool->setSplinePathId(curveCutId); dialogTool->SetPointName(point->name()); - dialogTool->SetColor(lineColor); } //--------------------------------------------------------------------------------------------------------------------- @@ -90,8 +88,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphics const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->GetFormula(); const quint32 splinePathId = dialogTool->getSplinePathId(); - const QString color = dialogTool->GetColor(); - VToolCutSplinePath* point = Create(0, pointName, formula, splinePathId, 5, 10, color, scene, doc, data, + VToolCutSplinePath* point = Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { @@ -117,7 +114,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphics */ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splinePathId, const qreal &mx, const qreal &my, - const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { const auto splPath = data->GeometricObject(splinePathId); @@ -160,7 +157,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString VDrawTool::AddRecord(id, Tool::CutSplinePath, doc); if (parse == Document::FullParse) { - VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, color, typeCreation); + VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, typeCreation); scene->addItem(point); InitToolConnections(scene, point); doc->AddTool(id, point); @@ -282,7 +279,6 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula()); doc->SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId())); - doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); } //--------------------------------------------------------------------------------------------------------------------- @@ -300,7 +296,6 @@ void VToolCutSplinePath::ReadToolAttributes(const QDomElement &domElement) { formula = doc->GetParametrString(domElement, AttrLength, ""); curveCutId = doc->GetParametrUInt(domElement, AttrSplinePath, NULL_ID_STR); - lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); } //--------------------------------------------------------------------------------------------------------------------- @@ -312,7 +307,7 @@ void VToolCutSplinePath::SetVisualization() SCASSERT(visual != nullptr); visual->setObject1Id(curveCutId); - visual->setLength(qApp->TrVars()->FormulaToUser(formula)); + visual->setLength(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h index a0517d69c..8b5dbb593 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h @@ -42,17 +42,12 @@ class VToolCutSplinePath : public VToolCut { Q_OBJECT public: - - VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &splinePathId, const QString &color, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolCutSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolCutSplinePath *Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splinePathId, const qreal &mx, const qreal &my, - const QString &color, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSplinePath; @@ -71,6 +66,9 @@ protected: virtual void SetVisualization() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolCutSplinePath) + + VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, + const quint32 &splinePathId, const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLCUTSPLINEPATH_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 3ae03a962..2fbca8c73 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -146,7 +146,7 @@ void VToolAlongLine::SetVisualization() SCASSERT(visual != nullptr) visual->setObject1Id(basePointId); visual->setObject2Id(secondPointId); - visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength)); + visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator())); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); } @@ -248,7 +248,7 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa { const QSharedPointer firstPoint = data->GeometricObject(firstPointId); const QSharedPointer secondPoint = data->GeometricObject(secondPointId); - QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF()); + QLineF line = QLineF(*firstPoint, *secondPoint); line.setLength(qApp->toPixel(CheckFormula(_id, formula, data))); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h index 97562c96c..826634b70 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h @@ -38,11 +38,6 @@ class VToolAlongLine : public VToolLinePoint { Q_OBJECT public: - - VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formula, - const quint32 &firstPointId, - const quint32 &secondPointId, const QString &typeLine, const QString &lineColor, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolAlongLine* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -69,8 +64,15 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolAlongLine) + /** @brief secondPointId id second point of line. */ quint32 secondPointId; + + VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formula, + const quint32 &firstPointId, + const quint32 &secondPointId, const QString &typeLine, const QString &lineColor, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLALONGLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp index c58d3aba0..dd0c2d6c0 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp @@ -177,8 +177,7 @@ VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, const const qreal result = CheckFormula(_id, formula, data); - QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), - thirdPoint->toQPointF(), qApp->toPixel(result)); + QPointF fPoint = VToolBisector::FindPoint(*firstPoint, *secondPoint, *thirdPoint, qApp->toPixel(result)); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -305,7 +304,7 @@ void VToolBisector::SetVisualization() visual->setObject1Id(firstPointId); visual->setObject2Id(basePointId); visual->setObject3Id(thirdPointId); - visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength)); + visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator())); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h index f95e92156..deab4d68f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h @@ -38,11 +38,6 @@ class VToolBisector : public VToolLinePoint { Q_OBJECT public: - - VToolBisector(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, - const quint32 &thirdPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr); static qreal BisectorAngle(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint); static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint, const qreal& length); @@ -76,11 +71,18 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolBisector) + /** @brief firstPointId id first point of angle. */ quint32 firstPointId; /** @brief thirdPointId id third point of angle. */ quint32 thirdPointId; + + VToolBisector(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, + const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, + const quint32 &thirdPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLBISECTOR_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index 041ddd67f..fb6c5c6c0 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -113,7 +113,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(const quint32 _id, cons const qreal angle = CheckFormula(_id, formulaAngle, data); const QSharedPointer curve = data->GeometricObject(curveId); - const QPointF fPoint = FindPoint(basePoint->toQPointF(), angle, curve); + const QPointF fPoint = FindPoint(*basePoint, angle, curve); const qreal segLength = curve->GetLengthByPoint(fPoint); quint32 id = _id; VPointF *p = new VPointF(fPoint, pointName, mx, my); @@ -292,7 +292,7 @@ void VToolCurveIntersectAxis::SetVisualization() visual->setObject1Id(curveId); visual->setAxisPointId(basePointId); - visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle)); + visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h index 3821b9756..f83b41572 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h @@ -35,9 +35,6 @@ class VToolCurveIntersectAxis : public VToolLinePoint { Q_OBJECT public: - VToolCurveIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId, - const quint32 &curveId, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual ~VToolCurveIntersectAxis() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; @@ -73,6 +70,10 @@ private: QString formulaAngle; quint32 curveId; + VToolCurveIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId, + const quint32 &curveId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + static void InitSegments(const GOType &curveType, qreal segLength, const VPointF *p, quint32 curveId, VContainer *data); }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp index 5c37a3bfd..d993bdc20 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp @@ -140,7 +140,7 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, const Source &typeCreation) { const QSharedPointer basePoint = data->GeometricObject(basePointId); - QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); + QLineF line = QLineF(*basePoint, QPointF(basePoint->x()+100, basePoint->y())); line.setAngle(CheckFormula(_id, formulaAngle, data)); //First set angle. line.setLength(qApp->toPixel(CheckFormula(_id, formulaLength, data))); @@ -238,8 +238,8 @@ void VToolEndLine::SetVisualization() SCASSERT(visual != nullptr); visual->setObject1Id(basePointId); - visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength)); - visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle)); + visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator())); + visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h index 8242a86f9..052321933 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h @@ -38,11 +38,6 @@ class VToolEndLine : public VToolLinePoint { Q_OBJECT public: - - VToolEndLine(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const QString &formulaLength, const QString &formulaAngle, const quint32 &basePointId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual ~VToolEndLine() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; static VToolEndLine *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, @@ -67,7 +62,14 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolEndLine) + QString formulaAngle; + + VToolEndLine(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, + const QString &formulaLength, const QString &formulaAngle, const quint32 &basePointId, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLENDLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp index 2056dedfc..b259a920f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp @@ -131,7 +131,7 @@ VToolHeight* VToolHeight::Create(const quint32 _id, const QString &pointName, co const QSharedPointer p1Line = data->GeometricObject(p1LineId); const QSharedPointer p2Line = data->GeometricObject(p2LineId); - QPointF pHeight = FindPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()), basePoint->toQPointF()); + QPointF pHeight = FindPoint(QLineF(*p1Line, *p2Line), *basePoint); quint32 id = _id; if (typeCreation == Source::FromGui) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h index 19b426fc3..d04faa996 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h @@ -38,11 +38,6 @@ class VToolHeight: public VToolLinePoint { Q_OBJECT public: - - VToolHeight(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolHeight *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolHeight *Create(const quint32 _id, const QString &pointName, const QString &typeLine, @@ -69,11 +64,18 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolHeight) + /** @brief p1LineId id first point of line. */ quint32 p1LineId; /** @brief p2LineId id second point of line. */ quint32 p2LineId; + + VToolHeight(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, + const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLHEIGHT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index dd8409b0b..802e3bc92 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -106,12 +106,12 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(const quint32 _id, const const Source &typeCreation) { const QSharedPointer basePoint = data->GeometricObject(basePointId); - QLineF axis = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); + QLineF axis = QLineF(*basePoint, QPointF(basePoint->x()+100, basePoint->y())); axis.setAngle(CheckFormula(_id, formulaAngle, data)); const QSharedPointer firstPoint = data->GeometricObject(firstPointId); const QSharedPointer secondPoint = data->GeometricObject(secondPointId); - QLineF line(firstPoint->toQPointF(), secondPoint->toQPointF()); + QLineF line(*firstPoint, *secondPoint); QPointF fPoint = FindPoint(axis, line); quint32 id = _id; @@ -292,7 +292,7 @@ void VToolLineIntersectAxis::SetVisualization() visual->setObject1Id(firstPointId); visual->setPoint2Id(secondPointId); visual->setAxisPointId(basePointId); - visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle)); + visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h index 9a157d1b8..40e42d35a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h @@ -35,10 +35,6 @@ class VToolLineIntersectAxis : public VToolLinePoint { Q_OBJECT public: - VToolLineIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId, - const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual ~VToolLineIntersectAxis() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; @@ -75,9 +71,15 @@ protected: virtual void SetVisualization() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolLineIntersectAxis) + QString formulaAngle; quint32 firstPointId; quint32 secondPointId; + + VToolLineIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId, + const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLLINEINTERSECTAXIS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp index aa9ca24ab..85405cf8e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp @@ -46,13 +46,13 @@ VToolLinePoint::VToolLinePoint(VAbstractPattern *doc, VContainer *data, const qu const QString &lineColor, const QString &formula, const quint32 &basePointId, const qreal &angle, QGraphicsItem *parent) :VToolSinglePoint(doc, data, id, parent), formulaLength(formula), angle(angle), basePointId(basePointId), - mainLine(nullptr) + mainLine(nullptr), lineColor(ColorBlack) { this->typeLine = typeLine; this->lineColor = lineColor; Q_ASSERT_X(basePointId != 0, Q_FUNC_INFO, "basePointId == 0"); //-V654 //-V712 - QPointF point1 = data->GeometricObject(basePointId)->toQPointF(); - QPointF point2 = data->GeometricObject(id)->toQPointF(); + QPointF point1 = *data->GeometricObject(basePointId); + QPointF point2 = *data->GeometricObject(id); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); mainLine->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); @@ -75,8 +75,8 @@ void VToolLinePoint::RefreshGeometry() qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); VToolSinglePoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); - QPointF point = VDrawTool::data.GeometricObject(id)->toQPointF(); - QPointF basePoint = VDrawTool::data.GeometricObject(basePointId)->toQPointF(); + QPointF point = *VDrawTool::data.GeometricObject(id); + QPointF basePoint = *VDrawTool::data.GeometricObject(basePointId); mainLine->setLine(QLineF(basePoint - point, QPointF())); } @@ -145,6 +145,21 @@ void VToolLinePoint::SetAngle(const qreal &value) SaveOption(obj); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolLinePoint::GetLineColor() const +{ + return lineColor; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::SetLineColor(const QString &value) +{ + lineColor = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLinePoint::GetBasePointId() const { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h index 225691dd7..e9ca4a01b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h @@ -45,14 +45,18 @@ public: virtual ~VToolLinePoint() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::LinePoint)}; - VFormula GetFormulaLength() const; - void SetFormulaLength(const VFormula &value); - quint32 GetBasePointId() const; - void SetBasePointId(const quint32 &value); + VFormula GetFormulaLength() const; + void SetFormulaLength(const VFormula &value); - qreal GetAngle() const; - void SetAngle(const qreal &value); + quint32 GetBasePointId() const; + void SetBasePointId(const quint32 &value); + + qreal GetAngle() const; + void SetAngle(const qreal &value); + + QString GetLineColor() const; + void SetLineColor(const QString &value); public slots: virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; @@ -66,11 +70,14 @@ protected: qreal angle; /** @brief basePointId id base line point. */ - quint32 basePointId; + quint32 basePointId; /** @brief mainLine line item. */ QGraphicsLineItem *mainLine; + /** @brief lineColor color of a line. */ + QString lineColor; + virtual void RefreshGeometry(); virtual void RemoveReferens() Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp index f73de34fb..2250ca5ae 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp @@ -137,8 +137,7 @@ VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, const quin const qreal result = CheckFormula(_id, formula, data); - QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), - qApp->toPixel(result), angle); + QPointF fPoint = VToolNormal::FindPoint(*firstPoint, *secondPoint, qApp->toPixel(result), angle); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -279,7 +278,7 @@ void VToolNormal::SetVisualization() visual->setObject1Id(basePointId); visual->setObject2Id(secondPointId); - visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength)); + visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator())); visual->SetAngle(angle); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h index 9685b5c7d..cc188c977 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h @@ -38,10 +38,6 @@ class VToolNormal : public VToolLinePoint { Q_OBJECT public: - VToolNormal(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const QString &formula, const qreal &angle, const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolNormal* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolNormal* Create(const quint32 _id, QString &formula, const quint32 &firstPointId, @@ -70,8 +66,15 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolNormal) + /** @brief secondPointId id second line point. */ quint32 secondPointId; + + VToolNormal(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, + const QString &formula, const qreal &angle, const quint32 &firstPointId, const quint32 &secondPointId, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLNORMAL_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp index c0890dff4..edae92ae4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp @@ -178,8 +178,7 @@ VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formu const qreal result = CheckFormula(_id, formula, data); - QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), - shoulderPoint->toQPointF(), qApp->toPixel(result)); + QPointF fPoint = VToolShoulderPoint::FindPoint(*firstPoint, *secondPoint, *shoulderPoint, qApp->toPixel(result)); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -309,7 +308,7 @@ void VToolShoulderPoint::SetVisualization() visual->setObject1Id(pShoulder); visual->setLineP1Id(basePointId); visual->setLineP2Id(p2Line); - visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength)); + visual->setLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator())); visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h index 71bcf6d7a..ad2095cfc 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h @@ -39,9 +39,6 @@ class VToolShoulderPoint : public VToolLinePoint { Q_OBJECT public: - VToolShoulderPoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formula, const quint32 &p1Line, const quint32 &p2Line, - const quint32 &pShoulder, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, const qreal &length); @@ -74,11 +71,17 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolShoulderPoint) + /** @brief p2Line id second line point. */ quint32 p2Line; /** @brief pShoulder id shoulder line point. */ quint32 pShoulder; + + VToolShoulderPoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &lineColor, const QString &formula, const quint32 &p1Line, const quint32 &p2Line, + const quint32 &pShoulder, const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLSHOULDERPOINT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index 34ee3980c..238703690 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -76,7 +76,7 @@ void VToolBasePoint::setDialog() DialogSinglePoint *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); const QSharedPointer p = VAbstractTool::data.GeometricObject(id); - dialogTool->SetData(p->name(), p->toQPointF()); + dialogTool->SetData(p->name(), *p); } //--------------------------------------------------------------------------------------------------------------------- @@ -125,7 +125,7 @@ void VToolBasePoint::AddToFile() { Q_ASSERT_X(not namePP.isEmpty(), Q_FUNC_INFO, "name pattern piece is empty"); - QDomElement sPoint = doc->createElement(TagName); + QDomElement sPoint = doc->createElement(getTagName()); // Create SPoint tag QSharedPointer obj = VAbstractTool::data.GetGObject(id); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index 5c6b57f60..326778fcc 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -39,8 +39,6 @@ class VToolBasePoint : public VToolSinglePoint { Q_OBJECT public: - VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - const QString &namePP, QGraphicsItem * parent = nullptr ); virtual ~VToolBasePoint() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE; static VToolBasePoint *Create(quint32 _id, const QString &nameActivPP, VPointF *point, @@ -74,9 +72,14 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} private: - QString namePP; - void SetColorLabel(const Qt::GlobalColor & color); + Q_DISABLE_COPY(VToolBasePoint) + QString namePP; + + VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, + const QString &namePP, QGraphicsItem * parent = nullptr ); + + void SetColorLabel(const Qt::GlobalColor & color); }; #endif // VTOOLBASEPOINT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp index 4eab669b6..17b65031b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp @@ -131,8 +131,8 @@ VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, const quint32 const QSharedPointer p1Line2 = data->GeometricObject(p1Line2Id); const QSharedPointer p2Line2 = data->GeometricObject(p2Line2Id); - QLineF line1(p1Line1->toQPointF(), p2Line1->toQPointF()); - QLineF line2(p1Line2->toQPointF(), p2Line2->toQPointF()); + QLineF line1(*p1Line1, *p2Line1); + QLineF line2(*p1Line2, *p2Line2); QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h index f6e16c862..3e441a7c6 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h @@ -38,9 +38,6 @@ class VToolLineIntersect:public VToolSinglePoint { Q_OBJECT public: - VToolLineIntersect(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &p1Line1, - const quint32 &p2Line1, const quint32 &p1Line2, const quint32 &p2Line2, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolLineIntersect *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -76,6 +73,8 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolLineIntersect) + /** @brief p1Line1 id first point first line. */ quint32 p1Line1; @@ -87,6 +86,10 @@ private: /** @brief p2Line2 id second point second line.*/ quint32 p2Line2; + + VToolLineIntersect(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &p1Line1, + const quint32 &p2Line1, const quint32 &p1Line2, const quint32 &p2Line2, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLLINEINTERSECT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp index cb118ad07..b2383e20a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp @@ -88,7 +88,7 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(const quint32 _ const VArc arc = *data->GeometricObject(arcId); const VPointF tPoint = *data->GeometricObject(tangentPointId); - const QPointF point = VToolPointFromArcAndTangent::FindPoint(tPoint.toQPointF(), &arc, crossPoint); + const QPointF point = VToolPointFromArcAndTangent::FindPoint(tPoint, &arc, crossPoint); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -121,7 +121,7 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(const quint32 _ QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType) { QPointF p1, p2; - const QPointF center = arc->GetCenter().toQPointF(); + const QPointF center = arc->GetCenter(); const qreal radius = arc->GetRadius(); const int res = VGObject::ContactPoints (p, center, radius, p1, p2); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h index f128d7edc..43555895e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h @@ -35,9 +35,6 @@ class VToolPointFromArcAndTangent : public VToolSinglePoint { Q_OBJECT public: - VToolPointFromArcAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 arcId, - quint32 tangentPointId, CrossCirclesPoint crossPoint, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointFromArcAndTangent *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -73,6 +70,10 @@ private: quint32 arcId; quint32 tangentPointId; CrossCirclesPoint crossPoint; + + VToolPointFromArcAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 arcId, + quint32 tangentPointId, CrossCirclesPoint crossPoint, const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTFROMARCANDTANGENT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index bcb21eb6b..41f5fb58c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -96,7 +96,7 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(const qui const VPointF cPoint = *data->GeometricObject(circleCenterId); const VPointF tPoint = *data->GeometricObject(tangentPointId); - const QPointF point = VToolPointFromCircleAndTangent::FindPoint(tPoint.toQPointF(), cPoint.toQPointF(), radius, + const QPointF point = VToolPointFromCircleAndTangent::FindPoint(tPoint, cPoint, radius, crossPoint); quint32 id = _id; if (typeCreation == Source::FromGui) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h index 7b4bf670b..e5902f163 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h @@ -37,9 +37,6 @@ class VToolPointFromCircleAndTangent : public VToolSinglePoint { Q_OBJECT public: - VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 circleCenterId, - const QString &circleRadius, quint32 tangentPointId, CrossCirclesPoint crossPoint, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointFromCircleAndTangent *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -80,6 +77,10 @@ private: quint32 tangentPointId; QString circleRadius; CrossCirclesPoint crossPoint; + + VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 circleCenterId, + const QString &circleRadius, quint32 tangentPointId, CrossCirclesPoint crossPoint, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTFROMCIRCLEANDTANGENT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index 6d9fd88c8..7e92b8021 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -193,8 +193,7 @@ VToolPointOfContact* VToolPointOfContact::Create(const quint32 _id, QString &rad const qreal result = CheckFormula(_id, radius, data); - QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(), - firstP->toQPointF(), secondP->toQPointF()); + QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), *centerP, *firstP, *secondP); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -322,7 +321,7 @@ void VToolPointOfContact::SetVisualization() visual->setObject1Id(firstPointId); visual->setLineP2Id(secondPointId); visual->setRadiusId(center); - visual->setRadius(qApp->TrVars()->FormulaToUser(arcRadius)); + visual->setRadius(qApp->TrVars()->FormulaToUser(arcRadius, qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h index 81f879a32..85655c32d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h @@ -40,9 +40,6 @@ class VToolPointOfContact : public VToolSinglePoint { Q_OBJECT public: - VToolPointOfContact(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &arcRadius, - const quint32 ¢er, const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static QPointF FindPoint(const qreal &arcRadius, const QPointF ¢er, const QPointF &firstPoint, const QPointF &secondPoint); @@ -81,6 +78,8 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolPointOfContact) + /** @brief radius string with formula radius arc. */ QString arcRadius; @@ -92,6 +91,10 @@ private: /** @brief secondPointId id second line point. */ quint32 secondPointId; + + VToolPointOfContact(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &arcRadius, + const quint32 ¢er, const quint32 &firstPointId, const quint32 &secondPointId, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTOFCONTACT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h index 1e956da3b..29af360df 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h @@ -38,9 +38,6 @@ class VToolPointOfIntersection : public VToolSinglePoint { Q_OBJECT public: - VToolPointOfIntersection(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstPointId, - const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersection *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -68,11 +65,16 @@ protected: virtual void SetVisualization() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolPointOfIntersection) + /** @brief firstPointId id first line point. */ quint32 firstPointId; /** @brief secondPointId id second line point. */ quint32 secondPointId; + + VToolPointOfIntersection(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstPointId, + const quint32 &secondPointId, const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTOFINTERSECTION_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp index a67f9f450..a751d7122 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp @@ -122,8 +122,8 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(const quint32 QPointF VToolPointOfIntersectionArcs::FindPoint(const VArc *arc1, const VArc *arc2, const CrossCirclesPoint pType) { QPointF p1, p2; - const QPointF centerArc1 = arc1->GetCenter().toQPointF(); - const QPointF centerArc2 = arc2->GetCenter().toQPointF(); + const QPointF centerArc1 = arc1->GetCenter(); + const QPointF centerArc2 = arc2->GetCenter(); const int res = VGObject::IntersectionCircles(centerArc1, arc1->GetRadius(), centerArc2, arc2->GetRadius(), p1, p2); QLineF r1Arc1(centerArc1, p1); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h index 11e5b70b6..46cd4d39e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h @@ -38,9 +38,6 @@ class VToolPointOfIntersectionArcs : public VToolSinglePoint Q_OBJECT public: - VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstArcId, - const quint32 &secondArcId, CrossCirclesPoint crossPoint, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersectionArcs *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -81,6 +78,10 @@ private: quint32 secondArcId; CrossCirclesPoint crossPoint; + + VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstArcId, + const quint32 &secondArcId, CrossCirclesPoint crossPoint, const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTOFINTERSECTIONARCS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp index 6bcdde298..5e760c15d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp @@ -107,7 +107,7 @@ VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(const q const VPointF c1Point = *data->GeometricObject(firstCircleCenterId); const VPointF c2Point = *data->GeometricObject(secondCircleCenterId); - const QPointF point = FindPoint(c1Point.toQPointF(), c2Point.toQPointF(), calcC1Radius, calcC2Radius, crossPoint); + const QPointF point = FindPoint(c1Point, c2Point, calcC1Radius, calcC2Radius, crossPoint); quint32 id = _id; if (typeCreation == Source::FromGui) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h index 4bee4764f..cacccfd20 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h @@ -37,11 +37,6 @@ class VToolPointOfIntersectionCircles : public VToolSinglePoint { Q_OBJECT public: - VToolPointOfIntersectionCircles(VAbstractPattern *doc, VContainer *data, const quint32 &id, const - quint32 firstCircleCenterId, quint32 secondCircleCenterId, - const QString &firstCircleRadius, const QString &secondCircleRadius, - CrossCirclesPoint crossPoint, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersectionCircles *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, @@ -92,6 +87,12 @@ private: QString secondCircleRadius; CrossCirclesPoint crossPoint; + + VToolPointOfIntersectionCircles(VAbstractPattern *doc, VContainer *data, const quint32 &id, const + quint32 firstCircleCenterId, quint32 secondCircleCenterId, + const QString &firstCircleRadius, const QString &secondCircleRadius, + CrossCirclesPoint crossPoint, const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTOFINTERSECTIONCIRCLES_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h index 891ba17a6..acea09333 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h @@ -35,10 +35,6 @@ class VToolPointOfIntersectionCurves : public VToolSinglePoint { Q_OBJECT public: - explicit VToolPointOfIntersectionCurves(VAbstractPattern *doc, VContainer *data, const quint32 &id, const - quint32 firstCurveId, quint32 secondCurveId, - VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint, - const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersectionCurves *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -82,6 +78,11 @@ private: VCrossCurvesPoint vCrossPoint; HCrossCurvesPoint hCrossPoint; + + explicit VToolPointOfIntersectionCurves(VAbstractPattern *doc, VContainer *data, const quint32 &id, const + quint32 firstCurveId, quint32 secondCurveId, + VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint, + const Source &typeCreation, QGraphicsItem * parent = nullptr); }; #endif // VTOOLPOINTOFINTERSECTIONCURVES_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index be9c4edb9..6a880c460 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -30,7 +30,7 @@ #include "../vmisc/logging.h" #include "../vgeometry/vpointf.h" #include "../vwidgets/vgraphicssimpletextitem.h" -#include "../../../../undocommands/movelabel.h" +#include "../../../../undocommands/label/movelabel.h" #include @@ -122,7 +122,7 @@ void VToolSinglePoint::NameChangePosition(const QPointF &pos) void VToolSinglePoint::UpdateNamePosition(quint32 id) { const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id, scene()); + auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id); connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition); qApp->getUndoStack()->push(moveLabel); } @@ -132,6 +132,13 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsEllipseItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + if (selectionType == SelectionType::ByMouseRelease) { event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event @@ -249,7 +256,7 @@ void VToolSinglePoint::RefreshPointGeometry(const VPointF &point) QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); - this->setPos(point.toQPointF()); + this->setPos(point); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); namePoint->blockSignals(true); QFont font = namePoint->font(); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp index 22e745653..c3485d5c1 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp @@ -130,8 +130,7 @@ VToolTriangle* VToolTriangle::Create(const quint32 _id, const QString &pointName const QSharedPointer firstPoint = data->GeometricObject(firstPointId); const QSharedPointer secondPoint = data->GeometricObject(secondPointId); - QPointF point = FindPoint(axisP1->toQPointF(), axisP2->toQPointF(), firstPoint->toQPointF(), - secondPoint->toQPointF()); + QPointF point = FindPoint(*axisP1, *axisP2, *firstPoint, *secondPoint); quint32 id = _id; if (typeCreation == Source::FromGui) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h index c9950b81b..e26024d67 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h @@ -39,10 +39,6 @@ class VToolTriangle : public VToolSinglePoint { Q_OBJECT public: - VToolTriangle(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id, - const quint32 &axisP2Id, - const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolTriangle *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); @@ -89,6 +85,11 @@ private: /** @brief secondPointId id second triangle point, what lies on the hypotenuse. */ quint32 secondPointId; + + VToolTriangle(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id, + const quint32 &axisP2Id, + const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, + QGraphicsItem * parent = nullptr); }; #endif // VTOOLTRIANGLE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp index e7027800e..9d2e751fc 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp @@ -29,8 +29,6 @@ #include "vabstractpoint.h" #include "../vgeometry/vpointf.h" -const QString VAbstractPoint::TagName = QStringLiteral("point"); - //--------------------------------------------------------------------------------------------------------------------- VAbstractPoint::VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32 id) :VDrawTool(doc, data, id) @@ -43,7 +41,7 @@ VAbstractPoint::~VAbstractPoint() //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPoint::getTagName() const { - return VAbstractPoint::TagName; + return VAbstractPattern::TagPoint; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h index c6ae7623e..ecb7e5c64 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h @@ -40,7 +40,6 @@ public: virtual ~VAbstractPoint() Q_DECL_OVERRIDE; virtual QString getTagName() const Q_DECL_OVERRIDE; - static const QString TagName; template void ShowToolVisualization(bool show); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index 96dec91e1..81bbfb172 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -36,6 +36,8 @@ #include "../../undocommands/savetooloptions.h" #include "../../../ifc/exception/vexceptionundo.h" +#include + qreal VDrawTool::factor = 1; //--------------------------------------------------------------------------------------------------------------------- @@ -47,7 +49,7 @@ qreal VDrawTool::factor = 1; */ VDrawTool::VDrawTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent) :VAbstractTool(doc, data, id, parent), nameActivDraw(doc->GetNameActivPP()), - dialog(nullptr), typeLine(TypeLineLine), lineColor(ColorBlack), enabled(true) + dialog(nullptr), typeLine(TypeLineLine), enabled(true) { connect(this->doc, &VAbstractPattern::ChangedActivPP, this, &VDrawTool::ChangedActivDraw); connect(this->doc, &VAbstractPattern::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); @@ -289,26 +291,28 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine { SCASSERT(data != nullptr) qreal result = 0; - Calculator *cal = nullptr; try { - cal = new Calculator(); + QScopedPointer cal(new Calculator()); result = cal->EvalFormula(data->PlainVariables(), formula); - delete cal; + + if (qIsInf(result) || qIsNaN(result)) + { + qDebug() << "Invalid the formula value"; + return 0; + } } catch (qmu::QmuParserError &e) { - //Q_UNUSED(e) qDebug() << "\nMath parser error:\n" << "--------------------------------------\n" << "Message: " << e.GetMsg() << "\n" << "Expression: " << e.GetExpr() << "\n" << "--------------------------------------"; - delete cal; if (qApp->IsAppInGUIMode()) { - DialogUndo *dialogUndo = new DialogUndo(qApp->getMainWindow()); + QScopedPointer dialogUndo(new DialogUndo(qApp->getMainWindow())); forever { if (dialogUndo->exec() == QDialog::Accepted) @@ -316,8 +320,7 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine const UndoButton resultUndo = dialogUndo->Result(); if (resultUndo == UndoButton::Fix) { - DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, - qApp->getMainWindow()); + auto *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow()); dialog->setWindowTitle(tr("Edit wrong formula")); dialog->SetFormula(formula); if (dialog->exec() == QDialog::Accepted) @@ -326,10 +329,15 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine /* Need delete dialog here because parser in dialog don't allow use correct separator for * parsing here. */ delete dialog; - Calculator *cal1 = new Calculator(); + QScopedPointer cal1(new Calculator()); result = cal1->EvalFormula(data->PlainVariables(), formula); - delete cal1; /* Here can be memory leak, but dialog already check this formula and - probability very low. */ + + if (qIsInf(result) || qIsNaN(result)) + { + qDebug() << "Invalid the formula value"; + return 0; + } + break; } else @@ -344,11 +352,9 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine } else { - delete dialogUndo; throw; } } - delete dialogUndo; } else { @@ -384,19 +390,3 @@ void VDrawTool::SetTypeLine(const QString &value) QSharedPointer obj = VAbstractTool::data.GetGObject(id); SaveOption(obj); } - -//--------------------------------------------------------------------------------------------------------------------- -QString VDrawTool::GetLineColor() const -{ - return lineColor; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VDrawTool::SetLineColor(const QString &value) -{ - lineColor = value; - - QSharedPointer obj = VAbstractTool::data.GetGObject(id); - SaveOption(obj); -} diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 76e8adfa3..3d6588eb4 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -58,9 +58,6 @@ public: QString getLineType() const; virtual void SetTypeLine(const QString &value); - QString GetLineColor() const; - virtual void SetLineColor(const QString &value); - signals: void ChangedToolSelection(bool selected, quint32 object, quint32 tool); @@ -88,9 +85,6 @@ protected: /** @brief typeLine line type. */ QString typeLine; - /** @brief lineColor color line or curve, but not a point. */ - QString lineColor; - bool enabled; void AddToCalculation(const QDomElement &domElement); diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index acadc4f00..a408c4459 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -33,8 +33,6 @@ #include "../../dialogs/tools/dialogline.h" #include "../../visualization/line/vistoolline.h" -const QString VToolLine::TagName = QStringLiteral("line"); - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolLine constructor. @@ -50,15 +48,17 @@ const QString VToolLine::TagName = QStringLiteral("line"); VToolLine::VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, const QString &typeLine, const QString &lineColor, const Source &typeCreation, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint) + :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint), + lineColor(ColorBlack) { this->typeLine = typeLine; this->lineColor = lineColor; //Line const QSharedPointer first = data->GeometricObject(firstPoint); const QSharedPointer second = data->GeometricObject(secondPoint); - this->setLine(QLineF(first->toQPointF(), second->toQPointF())); + this->setLine(QLineF(*first, *second)); this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setAcceptHoverEvents(true); this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); @@ -167,7 +167,7 @@ VToolLine * VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, con //--------------------------------------------------------------------------------------------------------------------- QString VToolLine::getTagName() const { - return VToolLine::TagName; + return VAbstractPattern::TagLine; } //--------------------------------------------------------------------------------------------------------------------- @@ -249,7 +249,7 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) */ void VToolLine::AddToFile() { - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); QSharedPointer obj = QSharedPointer (); SaveOptions(domElement, obj); AddToCalculation(domElement); @@ -461,6 +461,12 @@ void VToolLine::SetTypeLine(const QString &value) SaveOption(obj); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolLine::GetLineColor() const +{ + return lineColor; +} + //--------------------------------------------------------------------------------------------------------------------- void VToolLine::SetLineColor(const QString &value) { @@ -503,6 +509,6 @@ void VToolLine::RefreshGeometry() { const QSharedPointer first = VAbstractTool::data.GeometricObject(firstPoint); const QSharedPointer second = VAbstractTool::data.GeometricObject(secondPoint); - this->setLine(QLineF(first->toQPointF(), second->toQPointF())); + this->setLine(QLineF(*first, *second)); this->setPen(QPen(CorrectColor(lineColor), pen().widthF(), LineStyleToPenStyle(typeLine))); } diff --git a/src/libs/vtools/tools/drawTools/vtoolline.h b/src/libs/vtools/tools/drawTools/vtoolline.h index a554c4248..ebbf96e74 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.h +++ b/src/libs/vtools/tools/drawTools/vtoolline.h @@ -39,16 +39,12 @@ class VToolLine: public VDrawTool, public QGraphicsLineItem { Q_OBJECT public: - VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, - const QString &typeLine, const QString &lineColor, const Source &typeCreation, - QGraphicsItem * parent = nullptr); virtual void setDialog() Q_DECL_OVERRIDE; static VToolLine *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolLine *Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint, const QString &typeLine, const QString &lineColor, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); - static const QString TagName; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Line)}; @@ -59,10 +55,12 @@ public: quint32 GetSecondPoint() const; void SetSecondPoint(const quint32 &value); + QString GetLineColor() const; + void SetLineColor(const QString &value); + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; 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; @@ -85,12 +83,21 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolLine) + /** @brief firstPoint id first line point. */ quint32 firstPoint; /** @brief secondPoint id second line point. */ quint32 secondPoint; + /** @brief lineColor color of a line. */ + QString lineColor; + + VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, + const QString &typeLine, const QString &lineColor, const Source &typeCreation, + QGraphicsItem * parent = nullptr); + void RefreshGeometry(); }; diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index fc7662e9b..8b883f58f 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -31,7 +31,6 @@ #include -const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool"); //--------------------------------------------------------------------------------------------------------------------- @@ -64,7 +63,15 @@ void VAbstractNode::incrementReferens() ++_referens; if (_referens == 1) { - idTool != NULL_ID ? doc->IncrementReferens(idTool) : doc->IncrementReferens(idNode); + if (idTool != NULL_ID) + { + doc->IncrementReferens(idTool); + } + else + { + const QSharedPointer node = VAbstractTool::data.GetGObject(idNode); + doc->IncrementReferens(node->getIdTool()); + } ShowNode(); QDomElement domElement = doc->elementById(id); if (domElement.isElement()) @@ -86,7 +93,15 @@ void VAbstractNode::decrementReferens() } if (_referens == 0) { - idTool != NULL_ID ? doc->DecrementReferens(idTool) : doc->DecrementReferens(idNode); + if (idTool != NULL_ID) + { + doc->DecrementReferens(idTool); + } + else + { + const QSharedPointer node = VAbstractTool::data.GetGObject(idNode); + doc->DecrementReferens(node->getIdTool()); + } HideNode(); QDomElement domElement = doc->elementById(id); if (domElement.isElement()) diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index ac9119b08..4272514da 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -45,7 +45,6 @@ public: VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode, const quint32 &idTool, QObject *parent = nullptr); virtual ~VAbstractNode() Q_DECL_OVERRIDE {} - static const QString AttrIdObject; static const QString AttrIdTool; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; virtual void incrementReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/nodeDetails/vnodearc.cpp b/src/libs/vtools/tools/nodeDetails/vnodearc.cpp index a0f53931a..06922cbdc 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodearc.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodearc.cpp @@ -31,7 +31,6 @@ #include #include -const QString VNodeArc::TagName = QStringLiteral("arc"); const QString VNodeArc::ToolType = QStringLiteral("modeling"); //--------------------------------------------------------------------------------------------------------------------- @@ -94,7 +93,7 @@ void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint //--------------------------------------------------------------------------------------------------------------------- QString VNodeArc::getTagName() const { - return VNodeArc::TagName; + return VAbstractPattern::TagArc; } //--------------------------------------------------------------------------------------------------------------------- @@ -117,7 +116,7 @@ void VNodeArc::AllowSelecting(bool enabled) */ void VNodeArc::AddToFile() { - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); diff --git a/src/libs/vtools/tools/nodeDetails/vnodearc.h b/src/libs/vtools/tools/nodeDetails/vnodearc.h index 55d064e3f..fc6597b68 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodearc.h +++ b/src/libs/vtools/tools/nodeDetails/vnodearc.h @@ -39,12 +39,9 @@ class VNodeArc :public VAbstractNode { Q_OBJECT public: - VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, - const quint32 &idTool = 0, QObject *qoParent = nullptr); - static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse, const Source &typeCreation, const quint32 &idTool = 0); - static const QString TagName; + static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; public slots: @@ -58,6 +55,9 @@ protected: virtual void HideNode() Q_DECL_OVERRIDE {} private: Q_DISABLE_COPY(VNodeArc) + + VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, + const quint32 &idTool = 0, QObject *qoParent = nullptr); }; #endif // VNODEARC_H4 diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index 9b22b2337..67cab4032 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -33,7 +33,6 @@ #include #include -const QString VNodePoint::TagName = QStringLiteral("point"); const QString VNodePoint::ToolType = QStringLiteral("modeling"); //--------------------------------------------------------------------------------------------------------------------- @@ -119,58 +118,7 @@ void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsSc //--------------------------------------------------------------------------------------------------------------------- QString VNodePoint::getTagName() const { - return VNodePoint::TagName; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VNodePoint::incrementReferens() -{ - ++_referens; - if (_referens == 1) - { - if (idTool != NULL_ID) - { - doc->IncrementReferens(idTool); - } - else - { - const QSharedPointer point = VAbstractTool::data.GeometricObject(idNode); - doc->IncrementReferens(point->getIdTool()); - } - ShowNode(); - QDomElement domElement = doc->elementById(id); - if (domElement.isElement()) - { - doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VNodePoint::decrementReferens() -{ - if (_referens > 0) - { - --_referens; - } - if (_referens == 0) - { - if (idTool != NULL_ID) - { - doc->DecrementReferens(idTool); - } - else - { - const QSharedPointer point = VAbstractTool::data.GeometricObject(idNode); - doc->DecrementReferens(point->getIdTool()); - } - HideNode(); - QDomElement domElement = doc->elementById(id); - if (domElement.isElement()) - { - doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse); - } - } + return VAbstractPattern::TagPoint; } //--------------------------------------------------------------------------------------------------------------------- @@ -195,7 +143,7 @@ void VNodePoint::FullUpdateFromFile() void VNodePoint::AddToFile() { const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); @@ -235,6 +183,13 @@ void VNodePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsEllipseItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event } @@ -317,7 +272,7 @@ void VNodePoint::RefreshPointGeometry(const VPointF &point) QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); - this->setPos(point.toQPointF()); + this->setPos(point); namePoint->blockSignals(true); namePoint->setText(point.name()); diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 246b249f2..727e8c8f0 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -44,21 +44,15 @@ class VNodePoint: public VAbstractNode, public QGraphicsEllipseItem { Q_OBJECT public: - - VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation, - const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr ); - static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, quint32 idPoint, const Document &parse, const Source &typeCreation, const quint32 &idTool = 0); - static const QString TagName; + static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::NodePoint)}; virtual QString getTagName() const Q_DECL_OVERRIDE; - virtual void incrementReferens() Q_DECL_OVERRIDE; - virtual void decrementReferens() Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; void NameChangePosition(const QPointF &pos); @@ -91,6 +85,9 @@ protected: virtual void HideNode() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VNodePoint) + + VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation, + const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr ); }; #endif // VNODEPOINT_H diff --git a/src/libs/vtools/tools/nodeDetails/vnodespline.cpp b/src/libs/vtools/tools/nodeDetails/vnodespline.cpp index 2690e01df..5555bf0ba 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodespline.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodespline.cpp @@ -31,7 +31,6 @@ #include #include -const QString VNodeSpline::TagName = QStringLiteral("spline"); const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline"); //--------------------------------------------------------------------------------------------------------------------- @@ -98,7 +97,7 @@ VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint3 //--------------------------------------------------------------------------------------------------------------------- QString VNodeSpline::getTagName() const { - return VNodeSpline::TagName; + return VAbstractPattern::TagSpline; } //--------------------------------------------------------------------------------------------------------------------- @@ -121,7 +120,7 @@ void VNodeSpline::AllowSelecting(bool enabled) */ void VNodeSpline::AddToFile() { - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); diff --git a/src/libs/vtools/tools/nodeDetails/vnodespline.h b/src/libs/vtools/tools/nodeDetails/vnodespline.h index 2339cffec..08823b0d9 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodespline.h +++ b/src/libs/vtools/tools/nodeDetails/vnodespline.h @@ -39,13 +39,10 @@ class VNodeSpline:public VAbstractNode { Q_OBJECT public: - VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, - const quint32 &idTool = 0, QObject *qoParent = nullptr); - static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Document &parse, const Source &typeCreation, const quint32 &idTool = 0); - static const QString TagName; + static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; public slots: @@ -59,6 +56,9 @@ protected: virtual void HideNode() Q_DECL_OVERRIDE {} private: Q_DISABLE_COPY(VNodeSpline) + + VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, + const quint32 &idTool = 0, QObject *qoParent = nullptr); }; #endif // VNODESPLINE_H diff --git a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp index 91a7f7e4d..4c16ce503 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp @@ -32,7 +32,6 @@ #include #include -const QString VNodeSplinePath::TagName = QStringLiteral("spline"); const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath"); //--------------------------------------------------------------------------------------------------------------------- @@ -95,7 +94,7 @@ void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id //--------------------------------------------------------------------------------------------------------------------- QString VNodeSplinePath::getTagName() const { - return VNodeSplinePath::TagName; + return VAbstractPattern::TagSpline; } //--------------------------------------------------------------------------------------------------------------------- @@ -118,7 +117,7 @@ void VNodeSplinePath::AllowSelecting(bool enabled) */ void VNodeSplinePath::AddToFile() { - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); diff --git a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h index 35e188f48..2976cc53b 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h +++ b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h @@ -39,12 +39,10 @@ class VNodeSplinePath : public VAbstractNode { Q_OBJECT public: - VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, - const quint32 &idTool = 0, QObject *qoParent = nullptr); static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Document &parse, const Source &typeCreation, const quint32 &idTool = 0); - static const QString TagName; + static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; public slots: @@ -58,6 +56,9 @@ protected: virtual void HideNode() Q_DECL_OVERRIDE {} private: Q_DISABLE_COPY(VNodeSplinePath) + + VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, + const quint32 &idTool = 0, QObject *qoParent = nullptr); }; #endif // VNODESPLINEPATH_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index a8ed05c2e..36b6f986c 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -49,7 +49,8 @@ HEADERS += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ - $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ + $$PWD/drawTools/operation/vtoolrotation.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -96,4 +97,5 @@ SOURCES += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ - $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ + $$PWD/drawTools/operation/vtoolrotation.cpp diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 25cdede3c..b6e311cf1 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -47,14 +47,11 @@ #include #include - -const QString VToolDetail::TagName = QStringLiteral("detail"); const QString VToolDetail::TagNode = QStringLiteral("node"); const QString VToolDetail::AttrSupplement = QStringLiteral("supplement"); const QString VToolDetail::AttrClosed = QStringLiteral("closed"); const QString VToolDetail::AttrWidth = QStringLiteral("width"); -const QString VToolDetail::AttrIdObject = QStringLiteral("idObject"); const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); const QString VToolDetail::AttrReverse = QStringLiteral("reverse"); @@ -316,7 +313,7 @@ void VToolDetail::FullUpdateFromGuiOk(int result) void VToolDetail::AddToFile() { VDetail detail = VAbstractTool::data.GetDetail(id); - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrName, detail.getName()); @@ -379,7 +376,7 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const // value - this is new position. const QPointF newPos = value.toPointF(); - MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id, scene()); + MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id); connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(moveDet); @@ -463,6 +460,13 @@ void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event VNoBrushScalePathItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + if (flags() & QGraphicsItem::ItemIsMovable) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) @@ -620,7 +624,7 @@ void VToolDetail::AddNode(VAbstractPattern *doc, QDomElement &domElement, const //--------------------------------------------------------------------------------------------------------------------- QString VToolDetail::getTagName() const { - return VToolDetail::TagName; + return VAbstractPattern::TagDetail; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index c93769c1e..0d989c0a5 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -42,8 +42,6 @@ class VToolDetail: public VAbstractTool, public VNoBrushScalePathItem { Q_OBJECT public: - VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, - VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); ~VToolDetail(); virtual void setDialog(); @@ -66,12 +64,10 @@ public: static void Create(const quint32 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation, const QString &drawName = QString()); - static const QString TagName; static const QString TagNode; static const QString AttrSupplement; static const QString AttrClosed; static const QString AttrWidth; - static const QString AttrIdObject; static const QString AttrNodeType; static const QString AttrReverse; static const QString NodeTypeContour; @@ -116,6 +112,9 @@ private: VNoBrushScalePathItem *seamAllowance; + VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, + VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); + void RefreshGeometry (); template /** diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 585dd541b..2b1840e90 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -36,7 +36,6 @@ #include -const QString VToolUnionDetails::TagName = QStringLiteral("tools"); const QString VToolUnionDetails::ToolType = QStringLiteral("unionDetails"); const QString VToolUnionDetails::TagDetail = QStringLiteral("det"); const QString VToolUnionDetails::TagNode = QStringLiteral("node"); @@ -119,8 +118,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte { VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); point->setMode(Draw::Modeling); - BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), - angle); + BiasRotatePoint(point, dx, dy, *data->GeometricObject(pRotate), angle); idObject = data->AddGObject(point); children.append(idObject); VPointF *point1 = new VPointF(*point); @@ -138,7 +136,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte } else { - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = *data->GeometricObject(pRotate); const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); VPointF p1 = VPointF(arc->GetP1(), "A", 0, 0); BiasRotatePoint(&p1, dx, dy, p, angle); @@ -147,8 +145,8 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte VPointF *center = new VPointF(arc->GetCenter()); BiasRotatePoint(center, dx, dy, p, angle); - QLineF l1(center->toQPointF(), p1.toQPointF()); - QLineF l2(center->toQPointF(), p2.toQPointF()); + QLineF l1(*center, p1); + QLineF l2(*center, p2); center->setMode(Draw::Modeling); quint32 idCenter = data->AddGObject(center); Q_UNUSED(idCenter); @@ -177,7 +175,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte { const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline->GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -190,7 +188,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte VPointF *p4 = new VPointF(spline->GetP4()); BiasRotatePoint(p4, dx, dy, p, angle); - VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, 0, Draw::Modeling); + VSpline *spl = new VSpline(*p1, p2, p3, *p4, 0, Draw::Modeling); idObject = data->AddGObject(spl); children.append(idObject); @@ -223,7 +221,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte point2.Angle1Formula(), point1.Length2(), point1.Length2Formula(), point2.Length1(), point2.Length1Formula()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline.GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -236,7 +234,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte VPointF *p4 = new VPointF(spline.GetP4()); BiasRotatePoint(p4, dx, dy, p, angle); - VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4); + VSpline spl = VSpline(*p1, p2, p3, *p4); if (i==1) { const qreal angle1 = spl.GetStartAngle()+180; @@ -299,7 +297,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); point->setMode(Draw::Modeling); - BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + BiasRotatePoint(point, dx, dy, *data->GeometricObject(pRotate), angle); data->UpdateGObject(TakeNextId(children), point); } } @@ -308,7 +306,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) { - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = *data->GeometricObject(pRotate); const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); VPointF p1 = VPointF(arc->GetP1()); BiasRotatePoint(&p1, dx, dy, p, angle); @@ -319,8 +317,8 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const VPointF *center = new VPointF(arc->GetCenter()); BiasRotatePoint(center, dx, dy, p, angle); - QLineF l1(center->toQPointF(), p1.toQPointF()); - QLineF l2(center->toQPointF(), p2.toQPointF()); + QLineF l1(*center, p1); + QLineF l2(*center, p2); VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(), QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())); @@ -336,7 +334,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline->GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -349,7 +347,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const VPointF *p4 = new VPointF(spline->GetP4()); BiasRotatePoint(p4, dx, dy, p, angle); - VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, 0, Draw::Modeling); + VSpline *spl = new VSpline(*p1, p2, p3, *p4, 0, Draw::Modeling); data->UpdateGObject(TakeNextId(children), spl); delete p1; delete p4; @@ -373,7 +371,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const point2.Angle1Formula(), point1.Length2(), point1.Length2Formula(), point2.Length1(), point2.Length1Formula()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline.GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -386,7 +384,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const VPointF *p4 = new VPointF(spline.GetP4()); BiasRotatePoint(p4, dx, dy, p, angle); - VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4); + VSpline spl = VSpline(*p1, p2, p3, *p4); if (i==1) { const qreal angle1 = spl.GetStartAngle()+180; @@ -431,7 +429,7 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q { point->setX(point->x()+dx); point->setY(point->y()+dy); - QLineF line(pRotate, point->toQPointF()); + QLineF line(pRotate, *point); line.setAngle(line.angle()+angle); point->setX(line.p2().x()); point->setY(line.p2().y()); @@ -440,7 +438,7 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q //--------------------------------------------------------------------------------------------------------------------- QString VToolUnionDetails::getTagName() const { - return VToolUnionDetails::TagName; + return VAbstractPattern::TagTools; } //--------------------------------------------------------------------------------------------------------------------- @@ -587,8 +585,8 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d point4.setX(point4.x()+dx); point4.setY(point4.y()+dy); - const QLineF p4p3 = QLineF(point4.toQPointF(), point3.toQPointF()); - const QLineF p1p2 = QLineF(point1.toQPointF(), point2.toQPointF()); + const QLineF p4p3 = QLineF(point4, point3); + const QLineF p1p2 = QLineF(point1, point2); const qreal angle = p4p3.angleTo(p1p2); qint32 pointsD2 = 0; //Keeps number points the second detail, what we have already added. @@ -739,7 +737,7 @@ QVector VToolUnionDetails::GetDetailFromFile(VAbstractPattern *doc, con { if (element.tagName() == VToolUnionDetails::TagNode) { - quint32 id = doc->GetParametrUInt(element, VToolDetail::AttrIdObject, NULL_ID_STR); + quint32 id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); qreal mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0")); qreal my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0")); const bool reversed = doc->GetParametrUInt(element, VToolDetail::AttrReverse, "0"); @@ -779,7 +777,7 @@ QVector VToolUnionDetails::GetDetailFromFile(VAbstractPattern *doc, con */ void VToolUnionDetails::AddToFile() { - QDomElement domElement = doc->createElement(TagName); + QDomElement domElement = doc->createElement(getTagName()); doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); diff --git a/src/libs/vtools/tools/vtooluniondetails.h b/src/libs/vtools/tools/vtooluniondetails.h index af18419ac..4ba45ab19 100644 --- a/src/libs/vtools/tools/vtooluniondetails.h +++ b/src/libs/vtools/tools/vtooluniondetails.h @@ -42,9 +42,6 @@ class VToolUnionDetails : public VAbstractTool { Q_OBJECT public: - VToolUnionDetails(VAbstractPattern *doc, VContainer *data, const quint32 &id, const VDetail &d1, const VDetail &d2, - const quint32 &indexD1, const quint32 &indexD2, const Source &typeCreation, - const QString &drawName, QObject *parent = nullptr); /** * @brief setDialog set dialog when user want change tool option. */ @@ -59,7 +56,7 @@ public: static void PointsOnEdge(const VDetail &d, const quint32 &index, VPointF &p1, VPointF &p2, VContainer *data); static void FindIndexJ(const qint32 &pointsD2, const VDetail &d2, const quint32 &indexD2, qint32 &j); static QVector GetDetailFromFile(VAbstractPattern *doc, const QDomElement &domElement); - static const QString TagName; + static const QString ToolType; static const QString TagDetail; static const QString TagNode; @@ -112,6 +109,10 @@ private: QString drawName; + VToolUnionDetails(VAbstractPattern *doc, VContainer *data, const quint32 &id, const VDetail &d1, const VDetail &d2, + const quint32 &indexD1, const quint32 &indexD2, const Source &typeCreation, + const QString &drawName, QObject *parent = nullptr); + void AddDetail(QDomElement &domElement, VDetail &d); void AddNode(QDomElement &domElement, const VNodeDetail &node); QDomNode UpdateDetail(const QDomNode &domNode, const VDetail &d); diff --git a/src/libs/vtools/undocommands/label/moveabstractlabel.cpp b/src/libs/vtools/undocommands/label/moveabstractlabel.cpp new file mode 100644 index 000000000..1ba5c0d39 --- /dev/null +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.cpp @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file moveabstractlabel.cpp + ** @author Roman Telezhynskyi + ** @date 13 5, 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 "moveabstractlabel.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../vmisc/vabstractapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +MoveAbstractLabel::MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y, + QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + m_oldMx(0.0), + m_oldMy(0.0), + m_newMx(x), + m_newMy(y), + m_isRedo(false), + m_scene(qApp->getCurrentScene()) +{ + nodeId = pointId; + qCDebug(vUndo, "Point id %u", nodeId); + + qCDebug(vUndo, "Label new Mx %f", m_newMx); + qCDebug(vUndo, "Label new My %f", m_newMy); +} + +//--------------------------------------------------------------------------------------------------------------------- +MoveAbstractLabel::~MoveAbstractLabel() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void MoveAbstractLabel::undo() +{ + qCDebug(vUndo, "Undo."); + + Do(m_oldMx, m_oldMy); + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); + m_isRedo = true; + emit ChangePosition(nodeId, m_oldMx, m_oldMy); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MoveAbstractLabel::redo() +{ + qCDebug(vUndo, "Redo."); + + Do(m_newMx, m_newMy); + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); + if (m_isRedo) + { + emit ChangePosition(nodeId, m_newMx, m_newMy); + } +} diff --git a/src/libs/vtools/undocommands/movelabel.h b/src/libs/vtools/undocommands/label/moveabstractlabel.h similarity index 62% rename from src/libs/vtools/undocommands/movelabel.h rename to src/libs/vtools/undocommands/label/moveabstractlabel.h index a3a04167d..5aa885955 100644 --- a/src/libs/vtools/undocommands/movelabel.h +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file movelabel.h + ** @file moveabstractlabel.h ** @author Roman Telezhynskyi - ** @date 25 12, 2014 + ** @date 13 5, 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) 2013-2015 Valentina project + ** Copyright (C) 2016 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,56 +26,60 @@ ** *************************************************************************/ -#ifndef MOVELABEL_H -#define MOVELABEL_H +#ifndef MOVEABSTRACTLABEL_H +#define MOVEABSTRACTLABEL_H -#include "vundocommand.h" +#include "../vundocommand.h" class QGraphicsScene; +class QGraphicsView; -class MoveLabel : public VUndoCommand +class MoveAbstractLabel : public VUndoCommand { Q_OBJECT public: - MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, - QUndoCommand *parent = 0); - virtual ~MoveLabel() Q_DECL_OVERRIDE; + MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y, QUndoCommand *parent = nullptr); + virtual ~MoveAbstractLabel(); + virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; - virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; - virtual int id() const Q_DECL_OVERRIDE; - quint32 getPointId() const; - double getNewMx() const; - double getNewMy() const; - void Do(double mx, double my); + + quint32 GetPointId() const; + double GetNewMx() const; + double GetNewMy() const; + signals: void ChangePosition(quint32 id, qreal mx, qreal my); +protected: + double m_oldMx; + double m_oldMy; + double m_newMx; + double m_newMy; + bool m_isRedo; + //Need for resizing scene rect + QGraphicsScene *m_scene; + + virtual void Do(double mx, double my)=0; private: - Q_DISABLE_COPY(MoveLabel) - double oldMx; - double oldMy; - double newMx; - double newMy; - bool isRedo; - QGraphicsScene *scene; + Q_DISABLE_COPY(MoveAbstractLabel) }; //--------------------------------------------------------------------------------------------------------------------- -inline quint32 MoveLabel::getPointId() const +inline quint32 MoveAbstractLabel::GetPointId() const { return nodeId; } //--------------------------------------------------------------------------------------------------------------------- -inline double MoveLabel::getNewMx() const +inline double MoveAbstractLabel::GetNewMx() const { - return newMx; + return m_newMx; } //--------------------------------------------------------------------------------------------------------------------- -inline double MoveLabel::getNewMy() const +inline double MoveAbstractLabel::GetNewMy() const { - return newMy; + return m_newMy; } -#endif // MOVELABEL_H +#endif // MOVEABSTRACTLABEL_H diff --git a/src/libs/vtools/undocommands/movedoublelabel.cpp b/src/libs/vtools/undocommands/label/movedoublelabel.cpp similarity index 55% rename from src/libs/vtools/undocommands/movedoublelabel.cpp rename to src/libs/vtools/undocommands/label/movedoublelabel.cpp index d2c8fe6bb..960a49409 100644 --- a/src/libs/vtools/undocommands/movedoublelabel.cpp +++ b/src/libs/vtools/undocommands/label/movedoublelabel.cpp @@ -27,21 +27,14 @@ *************************************************************************/ #include "movedoublelabel.h" -#include "../tools/vabstracttool.h" -#include "../../vwidgets/vmaingraphicsview.h" - -#include -#include +#include "../vmisc/vabstractapplication.h" //--------------------------------------------------------------------------------------------------------------------- MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, - quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), - oldMx(0.0), oldMy(0.0), - newMx(x), newMy(y), - scene(scene), type(type), - pointId(pointId), - isRedo(false) + quint32 toolId, quint32 pointId, QUndoCommand *parent) + : MoveAbstractLabel(doc, pointId, x, y, parent), + m_type(type), + m_idTool(toolId) { if (type == DoublePoint::FirstPoint) { @@ -51,44 +44,25 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d { setText(tr("move the second dart label")); } - nodeId = tooId; - qCDebug(vUndo, "Point id %u", nodeId); - if (type == DoublePoint::FirstPoint) - { - qCDebug(vUndo, "Label new Mx1 %f", newMx); - qCDebug(vUndo, "Label new My1 %f", newMy); - } - else - { - qCDebug(vUndo, "Label new Mx2 %f", newMx); - qCDebug(vUndo, "Label new My2 %f", newMy); - } - - SCASSERT(scene != nullptr); - QDomElement domElement = doc->elementById(tooId); + const QDomElement domElement = doc->elementById(m_idTool); if (domElement.isElement()) { if (type == DoublePoint::FirstPoint) { - oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); - oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0")); - } - else - { - oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0")); - oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy2, "0.0")); - } + m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); + m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0")); - if (type == DoublePoint::FirstPoint) - { - qCDebug(vUndo, "Label old Mx1 %f", oldMx); - qCDebug(vUndo, "Label old My1 %f", oldMy); + qCDebug(vUndo, "Label old Mx1 %f", m_oldMx); + qCDebug(vUndo, "Label old My1 %f", m_oldMy); } else { - qCDebug(vUndo, "Label old Mx2 %f", oldMx); - qCDebug(vUndo, "Label old My2 %f", oldMy); + m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0")); + m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy2, "0.0")); + + qCDebug(vUndo, "Label old Mx2 %f", m_oldMx); + qCDebug(vUndo, "Label old My2 %f", m_oldMy); } } else @@ -102,52 +76,31 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d MoveDoubleLabel::~MoveDoubleLabel() {} -//--------------------------------------------------------------------------------------------------------------------- -void MoveDoubleLabel::undo() -{ - qCDebug(vUndo, "Undo."); - - Do(oldMx, oldMy); - isRedo = true; - emit ChangePosition(pointId, oldMx, oldMy); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MoveDoubleLabel::redo() -{ - qCDebug(vUndo, "Redo."); - - Do(newMx, newMy); - if (isRedo) - { - emit ChangePosition(pointId, newMx, newMy); - } -} - //--------------------------------------------------------------------------------------------------------------------- bool MoveDoubleLabel::mergeWith(const QUndoCommand *command) { const MoveDoubleLabel *moveCommand = static_cast(command); SCASSERT(moveCommand != nullptr); - if (moveCommand->getPointId() != nodeId || moveCommand->getPointType() != type || - moveCommand->getLabelId() != pointId) + if (moveCommand->GetPointId() != nodeId || + moveCommand->GetPointType() != m_type || + moveCommand->GetToolId() != m_idTool) { return false; } - newMx = moveCommand->getNewMx(); - newMy = moveCommand->getNewMy(); + m_newMx = moveCommand->GetNewMx(); + m_newMy = moveCommand->GetNewMy(); - if (type == DoublePoint::FirstPoint) + if (m_type == DoublePoint::FirstPoint) { - qCDebug(vUndo, "Label new Mx1 %f", newMx); - qCDebug(vUndo, "Label new My1 %f", newMy); + qCDebug(vUndo, "Label new Mx1 %f", m_newMx); + qCDebug(vUndo, "Label new My1 %f", m_newMy); } else { - qCDebug(vUndo, "Label new Mx2 %f", newMx); - qCDebug(vUndo, "Label new My2 %f", newMy); + qCDebug(vUndo, "Label new Mx2 %f", m_newMx); + qCDebug(vUndo, "Label new My2 %f", m_newMy); } return true; } @@ -158,16 +111,10 @@ int MoveDoubleLabel::id() const return static_cast(UndoCommand::MoveDoubleLabel); } -//--------------------------------------------------------------------------------------------------------------------- -quint32 MoveDoubleLabel::getLabelId() const -{ - return pointId; -} - //--------------------------------------------------------------------------------------------------------------------- void MoveDoubleLabel::Do(double mx, double my) { - if (type == DoublePoint::FirstPoint) + if (m_type == DoublePoint::FirstPoint) { qCDebug(vUndo, "New mx1 %f", mx); qCDebug(vUndo, "New my1 %f", my); @@ -178,10 +125,10 @@ void MoveDoubleLabel::Do(double mx, double my) qCDebug(vUndo, "New my2 %f", my); } - QDomElement domElement = doc->elementById(nodeId); + QDomElement domElement = doc->elementById(m_idTool); if (domElement.isElement()) { - if (type == DoublePoint::FirstPoint) + if (m_type == DoublePoint::FirstPoint) { doc->SetAttribute(domElement, AttrMx1, QString().setNum(qApp->fromPixel(mx))); doc->SetAttribute(domElement, AttrMy1, QString().setNum(qApp->fromPixel(my))); diff --git a/src/libs/vtools/undocommands/movedoublelabel.h b/src/libs/vtools/undocommands/label/movedoublelabel.h similarity index 60% rename from src/libs/vtools/undocommands/movedoublelabel.h rename to src/libs/vtools/undocommands/label/movedoublelabel.h index b26728add..19bd4604a 100644 --- a/src/libs/vtools/undocommands/movedoublelabel.h +++ b/src/libs/vtools/undocommands/label/movedoublelabel.h @@ -29,65 +29,41 @@ #ifndef MOVEDOUBLELABEL_H #define MOVEDOUBLELABEL_H -#include "vundocommand.h" - -class QGraphicsScene; +#include "moveabstractlabel.h" enum class DoublePoint: char { FirstPoint, SecondPoint }; -class MoveDoubleLabel : public VUndoCommand +class MoveDoubleLabel : public MoveAbstractLabel { Q_OBJECT public: MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, - quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent = 0); + quint32 toolId, quint32 pointId, QUndoCommand *parent = 0); virtual ~MoveDoubleLabel() Q_DECL_OVERRIDE; - virtual void undo() Q_DECL_OVERRIDE; - virtual void redo() Q_DECL_OVERRIDE; + virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE; - quint32 getPointId() const; - quint32 getLabelId() const; - double getNewMx() const; - double getNewMy() const; - DoublePoint getPointType() const; - void Do(double mx, double my); -signals: - void ChangePosition(quint32 id, qreal mx, qreal my); + + quint32 GetToolId() const; + DoublePoint GetPointType() const; +protected: + virtual void Do(double mx, double my) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(MoveDoubleLabel) - double oldMx; - double oldMy; - double newMx; - double newMy; - QGraphicsScene *scene; - DoublePoint type; - quint32 pointId; - bool isRedo; + DoublePoint m_type; + quint32 m_idTool; }; //--------------------------------------------------------------------------------------------------------------------- -inline quint32 MoveDoubleLabel::getPointId() const +inline DoublePoint MoveDoubleLabel::GetPointType() const { - return nodeId; + return m_type; } //--------------------------------------------------------------------------------------------------------------------- -inline DoublePoint MoveDoubleLabel::getPointType() const +inline quint32 MoveDoubleLabel::GetToolId() const { - return type; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline double MoveDoubleLabel::getNewMx() const -{ - return newMx; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline double MoveDoubleLabel::getNewMy() const -{ - return newMy; + return m_idTool; } #endif // MOVEDOUBLELABEL_H diff --git a/src/libs/vtools/undocommands/movelabel.cpp b/src/libs/vtools/undocommands/label/movelabel.cpp similarity index 64% rename from src/libs/vtools/undocommands/movelabel.cpp rename to src/libs/vtools/undocommands/label/movelabel.cpp index c5c8dfea4..82b75289a 100644 --- a/src/libs/vtools/undocommands/movelabel.cpp +++ b/src/libs/vtools/undocommands/label/movelabel.cpp @@ -27,33 +27,22 @@ *************************************************************************/ #include "movelabel.h" -#include "../tools/vabstracttool.h" -#include "../../vwidgets/vmaingraphicsview.h" - -#include -#include +#include "../vmisc/vabstractapplication.h" //--------------------------------------------------------------------------------------------------------------------- -MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, - QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), oldMx(0.0), oldMy(0.0), newMx(x), newMy(y), isRedo(false), scene(scene) +MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent) + : MoveAbstractLabel(doc, id, x, y, parent) { setText(tr("move point label")); - nodeId = id; - qCDebug(vUndo, "Point id %u", nodeId); - qCDebug(vUndo, "Label new Mx %f", newMx); - qCDebug(vUndo, "Label new My %f", newMy); - - SCASSERT(scene != nullptr); - QDomElement domElement = doc->elementById(id); + QDomElement domElement = doc->elementById(nodeId); if (domElement.isElement()) { - oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); - oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); + m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); + m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); - qCDebug(vUndo, "Label old Mx %f", oldMx); - qCDebug(vUndo, "Label old My %f", oldMy); + qCDebug(vUndo, "Label old Mx %f", m_oldMx); + qCDebug(vUndo, "Label old My %f", m_oldMy); } else { @@ -66,45 +55,22 @@ MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, co MoveLabel::~MoveLabel() {} -//--------------------------------------------------------------------------------------------------------------------- -void MoveLabel::undo() -{ - qCDebug(vUndo, "Undo."); - - Do(oldMx, oldMy); - isRedo = true; - emit ChangePosition(nodeId, oldMx, oldMy); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MoveLabel::redo() -{ - qCDebug(vUndo, "Redo."); - - Do(newMx, newMy); - if (isRedo) - { - emit ChangePosition(nodeId, newMx, newMy); - } -} - //--------------------------------------------------------------------------------------------------------------------- bool MoveLabel::mergeWith(const QUndoCommand *command) { const MoveLabel *moveCommand = static_cast(command); SCASSERT(moveCommand != nullptr); - const quint32 id = moveCommand->getPointId(); - if (id != nodeId) + if (moveCommand->GetPointId() != nodeId) { return false; } qCDebug(vUndo, "Mergin undo."); - newMx = moveCommand->getNewMx(); - newMy = moveCommand->getNewMy(); - qCDebug(vUndo, "Label new Mx %f", newMx); - qCDebug(vUndo, "Label new My %f", newMy); + m_newMx = moveCommand->GetNewMx(); + m_newMy = moveCommand->GetNewMy(); + qCDebug(vUndo, "Label new Mx %f", m_newMx); + qCDebug(vUndo, "Label new My %f", m_newMy); return true; } diff --git a/src/libs/vtools/undocommands/label/movelabel.h b/src/libs/vtools/undocommands/label/movelabel.h new file mode 100644 index 000000000..3b5887919 --- /dev/null +++ b/src/libs/vtools/undocommands/label/movelabel.h @@ -0,0 +1,49 @@ +/************************************************************************ + ** + ** @file movelabel.h + ** @author Roman Telezhynskyi + ** @date 25 12, 2014 + ** + ** @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) 2013-2015 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 MOVELABEL_H +#define MOVELABEL_H + +#include "moveabstractlabel.h" + +class MoveLabel : public MoveAbstractLabel +{ + Q_OBJECT +public: + MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent = 0); + virtual ~MoveLabel(); + + virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; + virtual int id() const Q_DECL_OVERRIDE; +protected: + virtual void Do(double mx, double my) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(MoveLabel) +}; + +#endif // MOVELABEL_H diff --git a/src/libs/vtools/undocommands/label/rotationmovelabel.cpp b/src/libs/vtools/undocommands/label/rotationmovelabel.cpp new file mode 100644 index 000000000..0d73a9450 --- /dev/null +++ b/src/libs/vtools/undocommands/label/rotationmovelabel.cpp @@ -0,0 +1,144 @@ +/************************************************************************ + ** + ** @file moverotationlabel.cpp + ** @author Roman Telezhynskyi + ** @date 13 5, 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 "rotationmovelabel.h" +#include "../../tools/drawTools/operation/vtoolrotation.h" + +//--------------------------------------------------------------------------------------------------------------------- +RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + QUndoCommand *parent) + : MoveAbstractLabel(doc, idPoint, x, y, parent), + m_idTool(idTool) +{ + setText(tr("move point label")); + + qCDebug(vUndo, "Tool id %u", m_idTool); + + const QDomElement element = GetDestinationObject(m_idTool, nodeId); + if (element.isElement()) + { + m_oldMx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0")); + m_oldMy = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0")); + + qCDebug(vUndo, "Label old Mx %f", m_oldMx); + qCDebug(vUndo, "Label old My %f", m_oldMy); + } + else + { + qCDebug(vUndo, "Can't find point with id = %u.", nodeId); + return; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +RotationMoveLabel::~RotationMoveLabel() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +bool RotationMoveLabel::mergeWith(const QUndoCommand *command) +{ + const RotationMoveLabel *moveCommand = static_cast(command); + SCASSERT(moveCommand != nullptr); + + if (moveCommand->GetToolId() != m_idTool && moveCommand->GetPointId() != nodeId) + { + return false; + } + + qCDebug(vUndo, "Mergin undo."); + m_newMx = moveCommand->GetNewMx(); + m_newMy = moveCommand->GetNewMy(); + qCDebug(vUndo, "Label new Mx %f", m_newMx); + qCDebug(vUndo, "Label new My %f", m_newMy); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +int RotationMoveLabel::id() const +{ + return static_cast(UndoCommand::RotationMoveLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +void RotationMoveLabel::Do(double mx, double my) +{ + qCDebug(vUndo, "New mx %f", mx); + qCDebug(vUndo, "New my %f", my); + + QDomElement domElement = GetDestinationObject(m_idTool, nodeId); + if (not domElement.isNull() && domElement.isElement()) + { + doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx))); + doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my))); + } + else + { + qCDebug(vUndo, "Can't find point with id = %u.", nodeId); + return; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement RotationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const +{ + const QDomElement tool = doc->elementById(idTool); + if (tool.isElement()) + { + QDomElement correctDest; + const QDomNodeList nodeList = tool.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dest = nodeList.at(i).toElement(); + if (not dest.isNull() && dest.isElement() && dest.tagName() == VToolRotation::TagDestination) + { + correctDest = dest; + break; + } + } + + if (not correctDest.isNull()) + { + const QDomNodeList destObjects = correctDest.childNodes(); + for (qint32 i = 0; i < destObjects.size(); ++i) + { + const QDomElement obj = destObjects.at(i).toElement(); + if (not obj.isNull() && obj.isElement()) + { + const quint32 id = doc->GetParametrUInt(obj, AttrIdObject, NULL_ID_STR); + if (idPoint == id) + { + return obj; + } + } + } + } + } + + return QDomElement(); +} diff --git a/src/libs/vtools/undocommands/label/rotationmovelabel.h b/src/libs/vtools/undocommands/label/rotationmovelabel.h new file mode 100644 index 000000000..ba156eb01 --- /dev/null +++ b/src/libs/vtools/undocommands/label/rotationmovelabel.h @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file moverotationlabel.h + ** @author Roman Telezhynskyi + ** @date 13 5, 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 ROTATIONMOVELABEL_H +#define ROTATIONMOVELABEL_H + +#include "moveabstractlabel.h" + +class RotationMoveLabel : public MoveAbstractLabel +{ + Q_OBJECT +public: + RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + QUndoCommand *parent = nullptr); + virtual ~RotationMoveLabel(); + + virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; + virtual int id() const Q_DECL_OVERRIDE; + + quint32 GetToolId() const; +protected: + virtual void Do(double mx, double my) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(RotationMoveLabel) + quint32 m_idTool; + + QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 RotationMoveLabel::GetToolId() const +{ + return m_idTool; +} + +#endif // ROTATIONMOVELABEL_H diff --git a/src/libs/vtools/undocommands/movedetail.cpp b/src/libs/vtools/undocommands/movedetail.cpp index 2b809e8b3..a7390230a 100644 --- a/src/libs/vtools/undocommands/movedetail.cpp +++ b/src/libs/vtools/undocommands/movedetail.cpp @@ -28,15 +28,15 @@ #include "movedetail.h" #include "../tools/vabstracttool.h" -#include "../../vwidgets/vmaingraphicsview.h" +#include "../vwidgets/vmaingraphicsview.h" #include #include //--------------------------------------------------------------------------------------------------------------------- MoveDetail::MoveDetail(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, - QGraphicsScene *scene, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), oldX(0.0), oldY(0.0), newX(x), newY(y), scene(scene) + QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), oldX(0.0), oldY(0.0), newX(x), newY(y), scene(qApp->getCurrentScene()) { setText(QObject::tr("move detail")); nodeId = id; diff --git a/src/libs/vtools/undocommands/movedetail.h b/src/libs/vtools/undocommands/movedetail.h index a8e306c4d..d5d9ebdd1 100644 --- a/src/libs/vtools/undocommands/movedetail.h +++ b/src/libs/vtools/undocommands/movedetail.h @@ -37,7 +37,7 @@ class MoveDetail : public VUndoCommand { Q_OBJECT public: - MoveDetail(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, + MoveDetail(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent = 0); virtual ~MoveDetail() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/undocommands/movespline.cpp b/src/libs/vtools/undocommands/movespline.cpp index 6d36394aa..4c1a4702d 100644 --- a/src/libs/vtools/undocommands/movespline.cpp +++ b/src/libs/vtools/undocommands/movespline.cpp @@ -28,15 +28,18 @@ #include "movespline.h" #include "../tools/vabstracttool.h" -#include "../../vwidgets/vmaingraphicsview.h" +#include "../vwidgets/vmaingraphicsview.h" #include #include //--------------------------------------------------------------------------------------------------------------------- MoveSpline::MoveSpline(VAbstractPattern *doc, const VSpline *oldSpl, const VSpline &newSpl, const quint32 &id, - QGraphicsScene *scene, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), oldSpline(*oldSpl), newSpline(newSpl), scene(scene) + QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + oldSpline(*oldSpl), + newSpline(newSpl), + scene(qApp->getCurrentScene()) { setText(tr("move spline")); nodeId = id; @@ -54,6 +57,7 @@ void MoveSpline::undo() qCDebug(vUndo, "Undo."); Do(oldSpline); + VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- @@ -62,6 +66,7 @@ void MoveSpline::redo() qCDebug(vUndo, "Redo."); Do(newSpline); + VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/movespline.h b/src/libs/vtools/undocommands/movespline.h index cce2787b1..fa067771d 100644 --- a/src/libs/vtools/undocommands/movespline.h +++ b/src/libs/vtools/undocommands/movespline.h @@ -39,7 +39,7 @@ class MoveSpline : public VUndoCommand Q_OBJECT public: MoveSpline(VAbstractPattern *doc, const VSpline *oldSpl, const VSpline &spl, const quint32 &id, - QGraphicsScene *scene, QUndoCommand *parent = 0); + QUndoCommand *parent = nullptr); virtual ~MoveSpline() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/undocommands/movesplinepath.cpp b/src/libs/vtools/undocommands/movesplinepath.cpp index f744fa770..7109bbc93 100644 --- a/src/libs/vtools/undocommands/movesplinepath.cpp +++ b/src/libs/vtools/undocommands/movesplinepath.cpp @@ -32,8 +32,11 @@ //--------------------------------------------------------------------------------------------------------------------- MoveSplinePath::MoveSplinePath(VAbstractPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath, - const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), oldSplinePath(oldSplPath), newSplinePath(newSplPath), scene(scene) + const quint32 &id, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + oldSplinePath(oldSplPath), + newSplinePath(newSplPath), + scene(qApp->getCurrentScene()) { setText(tr("move spline path")); nodeId = id; @@ -51,6 +54,7 @@ void MoveSplinePath::undo() qCDebug(vUndo, "Undo."); Do(oldSplinePath); + VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- @@ -59,6 +63,7 @@ void MoveSplinePath::redo() qCDebug(vUndo, "Redo."); Do(newSplinePath); + VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/movesplinepath.h b/src/libs/vtools/undocommands/movesplinepath.h index 2dd7a82a5..445b03c9b 100644 --- a/src/libs/vtools/undocommands/movesplinepath.h +++ b/src/libs/vtools/undocommands/movesplinepath.h @@ -39,7 +39,7 @@ class MoveSplinePath : public VUndoCommand Q_OBJECT public: MoveSplinePath(VAbstractPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath, - const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent = 0); + const quint32 &id, QUndoCommand *parent = nullptr); virtual ~MoveSplinePath() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 0ce6cb9ec..a20f58d15 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -17,10 +17,12 @@ HEADERS += \ $$PWD/deletedetail.h \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ - $$PWD/movelabel.h \ - $$PWD/movedoublelabel.h \ + $$PWD/label/movelabel.h \ + $$PWD/label/movedoublelabel.h \ $$PWD/addgroup.h \ - $$PWD/delgroup.h + $$PWD/delgroup.h \ + $$PWD/label/rotationmovelabel.h \ + undocommands/label/moveabstractlabel.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -38,7 +40,9 @@ SOURCES += \ $$PWD/deletedetail.cpp \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ - $$PWD/movelabel.cpp \ - $$PWD/movedoublelabel.cpp \ + $$PWD/label/movelabel.cpp \ + $$PWD/label/movedoublelabel.cpp \ $$PWD/addgroup.cpp \ - $$PWD/delgroup.cpp + $$PWD/delgroup.cpp \ + $$PWD/label/rotationmovelabel.cpp \ + undocommands/label/moveabstractlabel.cpp diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index b97134e6b..e86cfce82 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -49,7 +49,8 @@ enum class UndoCommand: char { AddPatternPiece, DeletePatternPiece, RenamePP, MoveLabel, - MoveDoubleLabel + MoveDoubleLabel, + RotationMoveLabel }; class VPattern; diff --git a/src/libs/vtools/visualization/line/vistoolalongline.cpp b/src/libs/vtools/visualization/line/vistoolalongline.cpp index b08f6d393..96f30342e 100644 --- a/src/libs/vtools/visualization/line/vistoolalongline.cpp +++ b/src/libs/vtools/visualization/line/vistoolalongline.cpp @@ -66,22 +66,22 @@ void VisToolAlongLine::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(lineP1, first->toQPointF(), supportColor); + DrawPoint(lineP1, *first, supportColor); if (object2Id <= NULL_ID) { - DrawLine(line, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(line, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(object2Id); - DrawPoint(lineP2, second->toQPointF(), supportColor); + DrawPoint(lineP2, *second, supportColor); - DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + DrawLine(line, QLineF(*first, *second), supportColor); if (not qFuzzyIsNull(length)) { - QLineF mainLine = VGObject::BuildLine(first->toQPointF(), length, line->line().angle()); + QLineF mainLine = VGObject::BuildLine(*first, length, line->line().angle()); DrawLine(this, mainLine, mainColor, lineStyle); DrawPoint(point, mainLine.p2(), mainColor); diff --git a/src/libs/vtools/visualization/line/vistoolbisector.cpp b/src/libs/vtools/visualization/line/vistoolbisector.cpp index d78f931c3..c5c92eee1 100644 --- a/src/libs/vtools/visualization/line/vistoolbisector.cpp +++ b/src/libs/vtools/visualization/line/vistoolbisector.cpp @@ -74,46 +74,43 @@ void VisToolBisector::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(line1P1, first->toQPointF(), supportColor); + DrawPoint(line1P1, *first, supportColor); if (object2Id <= NULL_ID) { - DrawLine(line1, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(line1, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(object2Id); - DrawPoint(line1P2, second->toQPointF(), supportColor); + DrawPoint(line1P2, *second, supportColor); - DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + DrawLine(line1, QLineF(*first, *second), supportColor); if (object3Id <= NULL_ID) { - DrawLine(line2, QLineF(second->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(line2, QLineF(*second, Visualization::scenePos), supportColor); } else { const QSharedPointer third = Visualization::data->GeometricObject(object3Id); - DrawPoint(line2P2, third->toQPointF(), supportColor); + DrawPoint(line2P2, *third, supportColor); - DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); + DrawLine(line2, QLineF(*second, *third), supportColor); if (not qFuzzyIsNull(length)) { - qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(), - third->toQPointF()); - QLineF mainLine = VGObject::BuildLine(second->toQPointF(), length, angle); + qreal angle = VToolBisector::BisectorAngle(*first, *second, *third); + QLineF mainLine = VGObject::BuildLine(*second, length, angle); DrawLine(this, mainLine, mainColor, lineStyle); DrawPoint(point, mainLine.p2(), mainColor); } else { - qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(), - third->toQPointF()); - QPointF endRay = Ray(second->toQPointF(), angle); - QLineF mainLine = VGObject::BuildLine(second->toQPointF(), - QLineF(second->toQPointF(), endRay).length(), angle); + qreal angle = VToolBisector::BisectorAngle(*first, *second, *third); + QPointF endRay = Ray(*second, angle); + QLineF mainLine = VGObject::BuildLine(*second, QLineF(*second, endRay).length(), angle); DrawLine(this, mainLine, mainColor, lineStyle); } } diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp index 2de41114c..1f10d0ad6 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp @@ -63,17 +63,17 @@ void VisToolCurveIntersectAxis::RefreshGeometry() const QSharedPointer first = Visualization::data->GeometricObject(axisPointId); if (VFuzzyComparePossibleNulls(angle, -1)) { - axis = Axis(first->toQPointF(), Visualization::scenePos); + axis = Axis(*first, Visualization::scenePos); } else { - axis = Axis(first->toQPointF(), angle); + axis = Axis(*first, angle); } - DrawPoint(basePoint, first->toQPointF(), mainColor); + DrawPoint(basePoint, *first, mainColor); DrawLine(axisLine, axis, supportColor, Qt::DashLine); - QPointF p = VToolCurveIntersectAxis::FindPoint(first->toQPointF(), axis.angle(), curve); - QLineF axis_line(first->toQPointF(), p); + QPointF p = VToolCurveIntersectAxis::FindPoint(*first, axis.angle(), curve); + QLineF axis_line(*first, p); DrawLine(this, axis_line, mainColor, lineStyle); DrawPoint(point, p, mainColor); diff --git a/src/libs/vtools/visualization/line/vistoolendline.cpp b/src/libs/vtools/visualization/line/vistoolendline.cpp index b61cc006a..0365ab7cc 100644 --- a/src/libs/vtools/visualization/line/vistoolendline.cpp +++ b/src/libs/vtools/visualization/line/vistoolendline.cpp @@ -55,17 +55,17 @@ void VisToolEndLine::RefreshGeometry() { if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { - line = QLineF(first->toQPointF(), Visualization::scenePos); + line = QLineF(*first, Visualization::scenePos); line.setAngle(CorrectAngle(line.angle())); } else { - line = QLineF(first->toQPointF(), Visualization::scenePos); + line = QLineF(*first, Visualization::scenePos); } } else { - line = VGObject::BuildLine(first->toQPointF(), length, angle); + line = VGObject::BuildLine(*first, length, angle); DrawPoint(point, line.p2(), mainColor); } DrawLine(this, line, mainColor, lineStyle); @@ -73,7 +73,8 @@ void VisToolEndLine::RefreshGeometry() Visualization::toolTip = QString(tr("Point at distance and angle: angle = %1°, length = %2%3; " "Shift - sticking angle, Enter - finish creation")) .arg(this->line().angle()) - .arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(this->line().length())))) + .arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(this->line().length())), + qApp->Settings()->GetOsSeparator())) .arg(prefix); } diff --git a/src/libs/vtools/visualization/line/vistoolheight.cpp b/src/libs/vtools/visualization/line/vistoolheight.cpp index 641dbb218..20f1a2217 100644 --- a/src/libs/vtools/visualization/line/vistoolheight.cpp +++ b/src/libs/vtools/visualization/line/vistoolheight.cpp @@ -54,37 +54,37 @@ void VisToolHeight::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(base_point, first->toQPointF(), supportColor); + DrawPoint(base_point, *first, supportColor); if (lineP1Id <= NULL_ID) { - DrawLine(this, QLineF(first->toQPointF(), Visualization::scenePos), mainColor); + DrawLine(this, QLineF(*first, Visualization::scenePos), mainColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(lineP1Id); - DrawPoint(lineP1, second->toQPointF(), supportColor); + DrawPoint(lineP1, *second, supportColor); QLineF base_line; if (lineP2Id <= NULL_ID) { - base_line = QLineF(second->toQPointF(), Visualization::scenePos); + base_line = QLineF(*second, Visualization::scenePos); DrawLine(line, base_line, supportColor); } else { const QSharedPointer third = Visualization::data->GeometricObject(lineP2Id); - DrawPoint(lineP2, third->toQPointF(), supportColor); + DrawPoint(lineP2, *third, supportColor); - base_line = QLineF(second->toQPointF(), third->toQPointF()); + base_line = QLineF(*second, *third); } DrawLine(line, base_line, supportColor); - QPointF height = VToolHeight::FindPoint(base_line, first->toQPointF()); + QPointF height = VToolHeight::FindPoint(base_line, *first); DrawPoint(point, height, mainColor); - QLineF height_line(first->toQPointF(), height); + QLineF height_line(*first, height); DrawLine(this, height_line, mainColor, lineStyle); ShowIntersection(height_line, base_line); diff --git a/src/libs/vtools/visualization/line/vistoolline.cpp b/src/libs/vtools/visualization/line/vistoolline.cpp index 7de8599a7..49780bc6a 100644 --- a/src/libs/vtools/visualization/line/vistoolline.cpp +++ b/src/libs/vtools/visualization/line/vistoolline.cpp @@ -49,12 +49,12 @@ void VisToolLine::RefreshGeometry() const QSharedPointer first = Visualization::data->GeometricObject(object1Id); if (point2Id == NULL_ID) { - line = QLineF(first->toQPointF(), Visualization::scenePos); + line = QLineF(*first, Visualization::scenePos); } else { const QSharedPointer second = Visualization::data->GeometricObject(point2Id); - line = QLineF(first->toQPointF(), second->toQPointF()); + line = QLineF(*first, *second); } DrawLine(this, line, mainColor, lineStyle); } diff --git a/src/libs/vtools/visualization/line/vistoollineintersect.cpp b/src/libs/vtools/visualization/line/vistoollineintersect.cpp index 9a648de77..904113d9f 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersect.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersect.cpp @@ -55,18 +55,18 @@ void VisToolLineIntersect::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(line1P1, first->toQPointF(), supportColor); + DrawPoint(line1P1, *first, supportColor); if (line1P2Id <= NULL_ID) { - DrawLine(line1, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(line1, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(line1P2Id); - DrawPoint(line1P2, second->toQPointF(), supportColor); + DrawPoint(line1P2, *second, supportColor); - DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + DrawLine(line1, QLineF(*first, *second), supportColor); if (line2P1Id <= NULL_ID) { @@ -75,14 +75,14 @@ void VisToolLineIntersect::RefreshGeometry() else { const QSharedPointer third = Visualization::data->GeometricObject(line2P1Id); - DrawPoint(line2P1, third->toQPointF(), supportColor); + DrawPoint(line2P1, *third, supportColor); if (line2P2Id <= NULL_ID) { - DrawLine(this, QLineF(third->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(this, QLineF(*third, Visualization::scenePos), supportColor); - QLineF l1(first->toQPointF(), second->toQPointF()); - QLineF l2(third->toQPointF(), Visualization::scenePos); + QLineF l1(*first, *second); + QLineF l2(*third, Visualization::scenePos); QPointF fPoint; QLineF::IntersectType intersect = l1.intersect(l2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) @@ -93,12 +93,12 @@ void VisToolLineIntersect::RefreshGeometry() else { const QSharedPointer forth = Visualization::data->GeometricObject(line2P2Id); - DrawPoint(line2P2, forth->toQPointF(), supportColor); + DrawPoint(line2P2, *forth, supportColor); - DrawLine(this, QLineF(third->toQPointF(), forth->toQPointF()), supportColor); + DrawLine(this, QLineF(*third, *forth), supportColor); - QLineF l1(first->toQPointF(), second->toQPointF()); - QLineF l2(third->toQPointF(), forth->toQPointF()); + QLineF l1(*first, *second); + QLineF l2(*third, *forth); QPointF fPoint; QLineF::IntersectType intersect = l1.intersect(l2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) diff --git a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp index 94096a188..8481818c4 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp @@ -57,18 +57,18 @@ void VisToolLineIntersectAxis::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(lineP1, first->toQPointF(), supportColor); + DrawPoint(lineP1, *first, supportColor); if (point2Id <= NULL_ID) { - DrawLine(baseLine, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(baseLine, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(point2Id); - DrawPoint(lineP2, second->toQPointF(), supportColor); + DrawPoint(lineP2, *second, supportColor); - const QLineF base_line(first->toQPointF(), second->toQPointF()); + const QLineF base_line(*first, *second); DrawLine(baseLine, base_line, supportColor); if (axisPointId > NULL_ID) @@ -77,17 +77,17 @@ void VisToolLineIntersectAxis::RefreshGeometry() const QSharedPointer third = Visualization::data->GeometricObject(axisPointId); if (VFuzzyComparePossibleNulls(angle, -1)) { - axis = Axis(third->toQPointF(), Visualization::scenePos); + axis = Axis(*third, Visualization::scenePos); } else { - axis = Axis(third->toQPointF(), angle); + axis = Axis(*third, angle); } - DrawPoint(basePoint, third->toQPointF(), mainColor); + DrawPoint(basePoint, *third, mainColor); DrawLine(axisLine, axis, supportColor, Qt::DashLine); QPointF p = VToolLineIntersectAxis::FindPoint(axis, base_line); - QLineF axis_line(third->toQPointF(), p); + QLineF axis_line(*third, p); DrawLine(this, axis_line, mainColor, lineStyle); DrawPoint(point, p, mainColor); diff --git a/src/libs/vtools/visualization/line/vistoolnormal.cpp b/src/libs/vtools/visualization/line/vistoolnormal.cpp index 1b30f924e..fc326a169 100644 --- a/src/libs/vtools/visualization/line/vistoolnormal.cpp +++ b/src/libs/vtools/visualization/line/vistoolnormal.cpp @@ -54,11 +54,11 @@ void VisToolNormal::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(lineP1, first->toQPointF(), supportColor); + DrawPoint(lineP1, *first, supportColor); if (object2Id <= NULL_ID) { - QLineF line_mouse(first->toQPointF(), Visualization::scenePos); + QLineF line_mouse(*first, Visualization::scenePos); DrawLine(line, line_mouse, supportColor); QLineF normal = line_mouse.normalVector(); @@ -68,9 +68,9 @@ void VisToolNormal::RefreshGeometry() else { const QSharedPointer second = Visualization::data->GeometricObject(object2Id); - DrawPoint(lineP2, second->toQPointF(), supportColor); + DrawPoint(lineP2, *second, supportColor); - QLineF line_mouse(first->toQPointF(), second->toQPointF()); + QLineF line_mouse(*first, *second); DrawLine(line, line_mouse, supportColor); if (qFuzzyIsNull(length)) @@ -81,8 +81,8 @@ void VisToolNormal::RefreshGeometry() } else { - QPointF fPoint = VToolNormal::FindPoint(first->toQPointF(), second->toQPointF(), length, angle); - QLineF mainLine = QLineF(first->toQPointF(), fPoint); + QPointF fPoint = VToolNormal::FindPoint(*first, *second, length, angle); + QLineF mainLine = QLineF(*first, fPoint); DrawLine(this, mainLine, mainColor, lineStyle); DrawPoint(point, mainLine.p2(), mainColor); diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp index c71f832b3..e589380de 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp @@ -53,16 +53,16 @@ void VisToolPointFromArcAndTangent::RefreshGeometry() if (object1Id > NULL_ID)// tangent point { const QSharedPointer tan = Visualization::data->GeometricObject(object1Id); - DrawPoint(tangent, tan->toQPointF(), supportColor); + DrawPoint(tangent, *tan, supportColor); if (arcId > NULL_ID)// circle center { const QSharedPointer arc = Visualization::data->GeometricObject(arcId); DrawPath(arcPath, arc->GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); - FindRays(tan->toQPointF(), arc.data()); + FindRays(*tan, arc.data()); - const QPointF fPoint = VToolPointFromArcAndTangent::FindPoint(tan->toQPointF(), arc.data(), crossPoint); + const QPointF fPoint = VToolPointFromArcAndTangent::FindPoint(*tan, arc.data(), crossPoint); DrawPoint(point, fPoint, mainColor); } } @@ -84,7 +84,7 @@ void VisToolPointFromArcAndTangent::setCrossPoint(const CrossCirclesPoint &value void VisToolPointFromArcAndTangent::FindRays(const QPointF &p, const VArc *arc) { QPointF p1, p2; - const QPointF center = arc->GetCenter().toQPointF(); + const QPointF center = arc->GetCenter(); const qreal radius = arc->GetRadius(); const int res = VGObject::ContactPoints (p, center, radius, p1, p2); diff --git a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp index cca09507b..dd813e90b 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp @@ -53,22 +53,21 @@ void VisToolPointFromCircleAndTangent::RefreshGeometry() if (object1Id > NULL_ID)// tangent point { const QSharedPointer tan = Visualization::data->GeometricObject(object1Id); - DrawPoint(tangent, tan->toQPointF(), supportColor); + DrawPoint(tangent, *tan, supportColor); if (object2Id > NULL_ID)// circle center { const QSharedPointer center = Visualization::data->GeometricObject(object2Id); - DrawPoint(cCenter, center->toQPointF(), supportColor); + DrawPoint(cCenter, *center, supportColor); if (cRadius > 0) { cPath->setRect(PointRect(cRadius)); - DrawPoint(cPath, center->toQPointF(), Qt::darkGreen, Qt::DashLine); + DrawPoint(cPath, *center, Qt::darkGreen, Qt::DashLine); - FindRays(tan->toQPointF(), center->toQPointF(), cRadius); + FindRays(*tan, *center, cRadius); - const QPointF fPoint = VToolPointFromCircleAndTangent::FindPoint(tan->toQPointF(), center->toQPointF(), - cRadius, crossPoint); + const QPointF fPoint = VToolPointFromCircleAndTangent::FindPoint(*tan, *center, cRadius, crossPoint); DrawPoint(point, fPoint, mainColor); } } diff --git a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp index 926b4921c..866e932d2 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp @@ -53,17 +53,17 @@ void VisToolPointOfContact::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(lineP1, first->toQPointF(), supportColor); + DrawPoint(lineP1, *first, supportColor); if (lineP2Id <= NULL_ID) { - DrawLine(this, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(this, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(lineP2Id); - DrawPoint(lineP2, second->toQPointF(), supportColor); - DrawLine(this, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + DrawPoint(lineP2, *second, supportColor); + DrawLine(this, QLineF(*first, *second), supportColor); if (radiusId <= NULL_ID) { @@ -72,16 +72,15 @@ void VisToolPointOfContact::RefreshGeometry() else { const QSharedPointer third = Visualization::data->GeometricObject(radiusId); - DrawPoint(arc_point, third->toQPointF(), supportColor); + DrawPoint(arc_point, *third, supportColor); if (not qFuzzyIsNull(radius)) { - QPointF fPoint = VToolPointOfContact::FindPoint(radius, third->toQPointF(), first->toQPointF(), - second->toQPointF()); + QPointF fPoint = VToolPointOfContact::FindPoint(radius, *third, *first, *second); DrawPoint(point, fPoint, mainColor); circle->setRect(PointRect(radius)); - DrawPoint(circle, third->toQPointF(), supportColor, Qt::DashLine); + DrawPoint(circle, *third, supportColor, Qt::DashLine); } } } diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp index 7f3afe0a3..378da41c0 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp @@ -57,9 +57,9 @@ void VisToolPointOfIntersection::RefreshGeometry() else { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(axisP1, first->toQPointF(), supportColor); + DrawPoint(axisP1, *first, supportColor); - axisL1 = Axis(first->toQPointF(), 90); + axisL1 = Axis(*first, 90); DrawLine(this, axisL1, supportColor, Qt::DashLine); QLineF axisL2; @@ -71,8 +71,8 @@ void VisToolPointOfIntersection::RefreshGeometry() else { const QSharedPointer second = Visualization::data->GeometricObject(point2Id); - DrawPoint(axisP2, second->toQPointF(), supportColor); - axisL2 = Axis(second->toQPointF(), 180); + DrawPoint(axisP2, *second, supportColor); + axisL2 = Axis(*second, 180); ShowIntersection(axisL1, axisL2, mainColor); } DrawLine(axis2, axisL2, supportColor, Qt::DashLine); diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp index b211311bf..3de0104ab 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp @@ -56,23 +56,22 @@ void VisToolPointOfIntersectionCircles::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(c1Center, first->toQPointF(), supportColor); + DrawPoint(c1Center, *first, supportColor); if (object2Id > NULL_ID) { const QSharedPointer second = Visualization::data->GeometricObject(object2Id); - DrawPoint(c2Center, second->toQPointF(), supportColor); + DrawPoint(c2Center, *second, supportColor); if (c1Radius > 0 && c2Radius > 0) { c1Path->setRect(PointRect(c1Radius)); - DrawPoint(c1Path, first->toQPointF(), Qt::darkGreen, Qt::DashLine); + DrawPoint(c1Path, *first, Qt::darkGreen, Qt::DashLine); c2Path->setRect(PointRect(c2Radius)); - DrawPoint(c2Path, second->toQPointF(), Qt::darkRed, Qt::DashLine); + DrawPoint(c2Path, *second, Qt::darkRed, Qt::DashLine); - const QPointF fPoint = VToolPointOfIntersectionCircles::FindPoint(first->toQPointF(), - second->toQPointF(), c1Radius, + const QPointF fPoint = VToolPointOfIntersectionCircles::FindPoint(*first, *second, c1Radius, c2Radius, crossPoint); DrawPoint(point, fPoint, mainColor); } diff --git a/src/libs/vtools/visualization/line/vistoolrotation.cpp b/src/libs/vtools/visualization/line/vistoolrotation.cpp new file mode 100644 index 000000000..7be9fd8f1 --- /dev/null +++ b/src/libs/vtools/visualization/line/vistoolrotation.cpp @@ -0,0 +1,273 @@ +/************************************************************************ + ** + ** @file vistoolrotation.cpp + ** @author Roman Telezhynskyi + ** @date 11 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 "vistoolrotation.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vpatterndb/vcontainer.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), + angle(INT_MIN), + objects(), + point(nullptr), + angleArc(nullptr), + xAxis(nullptr), + supportColor2(Qt::darkGreen), + points(), + curves() +{ + point = InitPoint(supportColor2, this); + angleArc = InitItem(supportColor2, this); + xAxis = InitItem(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolRotation::~VisToolRotation() +{ + qDeleteAll(points); + qDeleteAll(curves); +} + +//--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif + +void VisToolRotation::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + QSharedPointer origin = QSharedPointer(new VPointF()); + + qreal tempAngle = 0; + + if (object1Id != NULL_ID) + { + origin = Visualization::data->GeometricObject(object1Id); + DrawPoint(point, *origin, supportColor2); + + QLineF rLine; + if (VFuzzyComparePossibleNulls(angle, INT_MIN)) + { + rLine = QLineF(*origin, Visualization::scenePos); + + if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) + { + rLine.setAngle(CorrectAngle(rLine.angle())); + } + + rLine.setP2(Ray(*origin, rLine.angle())); + tempAngle = rLine.angle(); + } + else + { + rLine = QLineF(*origin, Ray(*origin, angle)); + tempAngle = angle; + } + + DrawLine(this, rLine, supportColor2, Qt::DashLine); + DrawLine(xAxis, QLineF(*origin, Ray(*origin, 0)), supportColor2, Qt::DashLine); + + VArc arc(*origin, ToPixel(DefPointRadius/*mm*/*2, Unit::Mm), 0, tempAngle); + DrawPath(angleArc, arc.GetPath(PathDirection::Hide), supportColor2, Qt::SolidLine, Qt::RoundCap); + + Visualization::toolTip = tr("Rotating angle = %1°, Shift - sticking angle, " + "Mouse click - finish creation").arg(tempAngle); + } + + int iPoint = -1; + int iCurve = -1; + for (int i = 0; i < objects.size(); ++i) + { + const quint32 id = objects.at(i); + const QSharedPointer obj = Visualization::data->GetGObject(id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects was handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); + DrawPoint(point, *p, supportColor2); + + ++iPoint; + point = GetPoint(iPoint, supportColor); + + if (object1Id != NULL_ID) + { + DrawPoint(point, p->Rotate(*origin, tempAngle), supportColor); + } + break; + } + case GOType::Arc: + { + iCurve = AddCurve(tempAngle, *origin, id, iCurve); + break; + } + case GOType::EllipticalArc: + { + iCurve = AddCurve(tempAngle, *origin, id, iCurve); + break; + } + case GOType::Spline: + { + iCurve = AddCurve(tempAngle, *origin, id, iCurve); + break; + } + case GOType::SplinePath: + { + iCurve = AddCurve(tempAngle, *origin, id, iCurve); + break; + } + case GOType::CubicBezier: + { + iCurve = AddCurve(tempAngle, *origin, id, iCurve); + break; + } + case GOType::CubicBezierPath: + { + iCurve = AddCurve(tempAngle, *origin, id, iCurve); + break; + } + case GOType::Unknown: + break; + } + } +} + +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::SetObjects(QVector objects) +{ + this->objects = objects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::SetOriginPointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VisToolRotation::Angle() const +{ + return QString::number(line().angle()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::SetAngle(const QString &expression) +{ + angle = FindVal(expression, Visualization::data->PlainVariables()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::VisualMode(const quint32 &pointId) +{ + Q_UNUSED(pointId); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + + Visualization::scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolRotation::GetPoint(quint32 i, const QColor &color) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(color, this); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsPathItem *VisToolRotation::GetCurve(quint32 i, const QColor &color) +{ + if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) + { + return curves.at(static_cast(i)); + } + else + { + auto curve = InitItem(color, this); + curves.append(curve); + return curve; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +int VisToolRotation::AddCurve(qreal angle, const QPointF &origin, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i, supportColor2); + DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + + ++i; + path = GetCurve(i, supportColor); + if (object1Id != NULL_ID) + { + const Item rotated = curve->Rotate(origin, angle); + DrawPath(path, rotated.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + } + + return i; +} diff --git a/src/libs/vtools/visualization/line/vistoolrotation.h b/src/libs/vtools/visualization/line/vistoolrotation.h new file mode 100644 index 000000000..66030149c --- /dev/null +++ b/src/libs/vtools/visualization/line/vistoolrotation.h @@ -0,0 +1,72 @@ +/************************************************************************ + ** + ** @file vistoolrotation.h + ** @author Roman Telezhynskyi + ** @date 11 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 VISTOOLROTATION_H +#define VISTOOLROTATION_H + +#include "visline.h" + +class VisToolRotation : public VisLine +{ + Q_OBJECT +public: + explicit VisToolRotation(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolRotation(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetObjects(QVector objects); + void SetOriginPointId(quint32 value); + + QString Angle() const; + void SetAngle(const QString &expression); + + virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolRotation)}; +private: + Q_DISABLE_COPY(VisToolRotation) + qreal angle; + QVector objects; + QGraphicsEllipseItem *point; + QGraphicsPathItem *angleArc; + QGraphicsLineItem *xAxis; + QColor supportColor2; + + QVector points; + QVector curves; + + QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); + QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); + + template + int AddCurve(qreal angle, const QPointF &origin, quint32 id, int i); +}; + +#endif // VISTOOLROTATION_H diff --git a/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp b/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp index e9f1de60e..3b786dfe6 100644 --- a/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp +++ b/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp @@ -56,46 +56,44 @@ void VisToolShoulderPoint::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(line1P1, first->toQPointF(), supportColor); + DrawPoint(line1P1, *first, supportColor); if (lineP1Id <= NULL_ID) { - DrawLine(line1, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(line1, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(lineP1Id); - DrawPoint(line1P2, second->toQPointF(), supportColor); + DrawPoint(line1P2, *second, supportColor); - DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + DrawLine(line1, QLineF(*first, *second), supportColor); if (lineP2Id <= NULL_ID) { - DrawLine(line2, QLineF(second->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(line2, QLineF(*second, Visualization::scenePos), supportColor); } else { const QSharedPointer third = Visualization::data->GeometricObject(lineP2Id); - DrawPoint(line2P2, third->toQPointF(), supportColor); + DrawPoint(line2P2, *third, supportColor); - DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); + DrawLine(line2, QLineF(*second, *third), supportColor); if (not qFuzzyIsNull(length)) { - QPointF fPoint = VToolShoulderPoint::FindPoint(second->toQPointF(), third->toQPointF(), - first->toQPointF(), length); - QLineF mainLine = QLineF(second->toQPointF(), fPoint); + QPointF fPoint = VToolShoulderPoint::FindPoint(*second, *third, *first, length); + QLineF mainLine = QLineF(*second, fPoint); DrawLine(this, mainLine, mainColor, lineStyle); DrawPoint(point, mainLine.p2(), mainColor); - DrawLine(line3, QLineF(first->toQPointF(), mainLine.p2()), supportColor, Qt::DashLine); + DrawLine(line3, QLineF(*first, mainLine.p2()), supportColor, Qt::DashLine); } else { - qreal angle = QLineF(second->toQPointF(), third->toQPointF()).angle(); - QPointF endRay = Ray(second->toQPointF(), angle); - QLineF mainLine = VGObject::BuildLine(second->toQPointF(), - QLineF(second->toQPointF(), endRay).length(), angle); + qreal angle = QLineF(*second, *third).angle(); + QPointF endRay = Ray(*second, angle); + QLineF mainLine = VGObject::BuildLine(*second, QLineF(*second, endRay).length(), angle); DrawLine(this, mainLine, mainColor, lineStyle); } } diff --git a/src/libs/vtools/visualization/line/vistooltriangle.cpp b/src/libs/vtools/visualization/line/vistooltriangle.cpp index de7e96352..11eec05ca 100644 --- a/src/libs/vtools/visualization/line/vistooltriangle.cpp +++ b/src/libs/vtools/visualization/line/vistooltriangle.cpp @@ -59,18 +59,18 @@ void VisToolTriangle::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(axisP1, first->toQPointF(), supportColor); + DrawPoint(axisP1, *first, supportColor); if (object2Id <= NULL_ID) { - DrawAimedAxis(axis, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); + DrawAimedAxis(axis, QLineF(*first, Visualization::scenePos), supportColor); } else { const QSharedPointer second = Visualization::data->GeometricObject(object2Id); - DrawPoint(axisP2, second->toQPointF(), supportColor); + DrawPoint(axisP2, *second, supportColor); - DrawAimedAxis(axis, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + DrawAimedAxis(axis, QLineF(*first, *second), supportColor); if (hypotenuseP1Id <= NULL_ID) { @@ -79,32 +79,30 @@ void VisToolTriangle::RefreshGeometry() else { const QSharedPointer third = Visualization::data->GeometricObject(hypotenuseP1Id); - DrawPoint(hypotenuseP1, third->toQPointF(), supportColor); + DrawPoint(hypotenuseP1, *third, supportColor); if (hypotenuseP2Id <= NULL_ID) { - DrawLine(this, QLineF(third->toQPointF(), Visualization::scenePos), supportColor, Qt::DashLine); + DrawLine(this, QLineF(*third, Visualization::scenePos), supportColor, Qt::DashLine); - QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(), - third->toQPointF(), Visualization::scenePos); + QPointF trPoint = VToolTriangle::FindPoint(*first, *second, *third, Visualization::scenePos); DrawPoint(point, trPoint, mainColor); - DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine); + DrawLine(foot1, QLineF(*third, trPoint), supportColor, Qt::DashLine); DrawLine(foot2, QLineF(Visualization::scenePos, trPoint), supportColor, Qt::DashLine); } else { const QSharedPointer forth = Visualization::data->GeometricObject(hypotenuseP2Id); - DrawPoint(hypotenuseP2, forth->toQPointF(), supportColor); + DrawPoint(hypotenuseP2, *forth, supportColor); - DrawLine(this, QLineF(third->toQPointF(), forth->toQPointF()), supportColor, Qt::DashLine); + DrawLine(this, QLineF(*third, *forth), supportColor, Qt::DashLine); - QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(), - third->toQPointF(), forth->toQPointF()); + QPointF trPoint = VToolTriangle::FindPoint(*first, *second, *third, *forth); DrawPoint(point, trPoint, mainColor); - DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine); - DrawLine(foot2, QLineF(forth->toQPointF(), trPoint), supportColor, Qt::DashLine); + DrawLine(foot1, QLineF(*third, trPoint), supportColor, Qt::DashLine); + DrawLine(foot2, QLineF(*forth, trPoint), supportColor, Qt::DashLine); } } } diff --git a/src/libs/vtools/visualization/line/vistooltruedarts.cpp b/src/libs/vtools/visualization/line/vistooltruedarts.cpp index 4b4a53163..f6dbbdab9 100644 --- a/src/libs/vtools/visualization/line/vistooltruedarts.cpp +++ b/src/libs/vtools/visualization/line/vistooltruedarts.cpp @@ -75,55 +75,51 @@ void VisToolTrueDarts::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer blP1 = Visualization::data->GeometricObject(object1Id); - DrawPoint(baseLineP1, blP1->toQPointF(), supportColor); + DrawPoint(baseLineP1, *blP1, supportColor); if (baseLineP2Id <= NULL_ID) { - DrawLine(this, QLineF(blP1->toQPointF(), Visualization::scenePos), supportColor, Qt::DashLine); + DrawLine(this, QLineF(*blP1, Visualization::scenePos), supportColor, Qt::DashLine); } else { const QSharedPointer blP2 = Visualization::data->GeometricObject(baseLineP2Id); - DrawPoint(baseLineP2, blP2->toQPointF(), supportColor); - DrawLine(this, QLineF(blP1->toQPointF(), blP2->toQPointF()), supportColor, Qt::DashLine); + DrawPoint(baseLineP2, *blP2, supportColor); + DrawLine(this, QLineF(*blP1, *blP2), supportColor, Qt::DashLine); if (dartP1Id > NULL_ID) { const QSharedPointer d1 = Visualization::data->GeometricObject(dartP1Id); - DrawPoint(dartP1, d1->toQPointF(), supportColor); + DrawPoint(dartP1, *d1, supportColor); if (dartP2Id <= NULL_ID) { - DrawLine(p1d2, QLineF(d1->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(p1d2, QLineF(*d1, Visualization::scenePos), supportColor); } else { const QSharedPointer d2 = Visualization::data->GeometricObject(dartP2Id); - DrawPoint(dartP2, d2->toQPointF(), supportColor); - DrawLine(p1d2, QLineF(d1->toQPointF(), d2->toQPointF()), supportColor); + DrawPoint(dartP2, *d2, supportColor); + DrawLine(p1d2, QLineF(*d1, *d2), supportColor); if (dartP3Id <= NULL_ID) { - DrawLine(d2p2, QLineF(d2->toQPointF(), Visualization::scenePos), supportColor); + DrawLine(d2p2, QLineF(*d2, Visualization::scenePos), supportColor); } else { const QSharedPointer d3 = Visualization::data->GeometricObject(dartP3Id); - DrawPoint(dartP3, d3->toQPointF(), supportColor); - DrawLine(d2p2, QLineF(d2->toQPointF(), d3->toQPointF()), supportColor); + DrawPoint(dartP3, *d3, supportColor); + DrawLine(d2p2, QLineF(*d2, *d3), supportColor); QPointF p1; QPointF p2; - VToolTrueDarts::FindPoint(blP1->toQPointF(), - blP2->toQPointF(), - d1->toQPointF(), - d2->toQPointF(), - d3->toQPointF(), p1, p2); + VToolTrueDarts::FindPoint(*blP1, *blP2, *d1, *d2, *d3, p1, p2); - DrawLine(lineblP1P1, QLineF(blP1->toQPointF(), p1), supportColor); - DrawLine(lineblP2P2, QLineF(blP2->toQPointF(), p2), supportColor); - DrawLine(p1d2, QLineF(p1, d2->toQPointF()), supportColor); - DrawLine(d2p2, QLineF(d2->toQPointF(), p2), supportColor); + DrawLine(lineblP1P1, QLineF(*blP1, p1), supportColor); + DrawLine(lineblP2P2, QLineF(*blP2, p2), supportColor); + DrawLine(p1d2, QLineF(p1, *d2), supportColor); + DrawLine(d2p2, QLineF(*d2, p2), supportColor); DrawPoint(point1, p1, mainColor); DrawPoint(point2, p2, mainColor); diff --git a/src/libs/vtools/visualization/path/vistoolarc.cpp b/src/libs/vtools/visualization/path/vistoolarc.cpp index 9dac04450..1d2786473 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolarc.cpp @@ -48,7 +48,7 @@ void VisToolArc::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(arcCenter, first->toQPointF(), supportColor); + DrawPoint(arcCenter, *first, supportColor); if (not qFuzzyIsNull(radius) && f1 >= 0 && f2 >= 0 && not VFuzzyComparePossibleNulls(f1, f2)) { diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp index 4edb00767..c703f8ac2 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp @@ -48,7 +48,7 @@ void VisToolArcWithLength::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); - DrawPoint(arcCenter, first->toQPointF(), supportColor); + DrawPoint(arcCenter, *first, supportColor); if (not qFuzzyIsNull(radius) && f1 >= 0 && not qFuzzyIsNull(length)) { diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp index 7d534657a..951f33f3f 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp @@ -62,17 +62,17 @@ void VisToolCubicBezier::RefreshGeometry() if (object1Id > NULL_ID) { const auto first = Visualization::data->GeometricObject(object1Id); - DrawPoint(point1, first->toQPointF(), Qt::DashLine); + DrawPoint(point1, *first, Qt::DashLine); if (object2Id <= NULL_ID) { - DrawLine(helpLine1, QLineF(first->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); + DrawLine(helpLine1, QLineF(*first, Visualization::scenePos), mainColor, Qt::DashLine); } else { const auto second = Visualization::data->GeometricObject(object2Id); - DrawPoint(point2, second->toQPointF(), supportColor); - DrawLine(helpLine1, QLineF(first->toQPointF(), second->toQPointF()), mainColor, Qt::DashLine); + DrawPoint(point2, *second, supportColor); + DrawLine(helpLine1, QLineF(*first, *second), mainColor, Qt::DashLine); if (object3Id <= NULL_ID) { @@ -83,19 +83,19 @@ void VisToolCubicBezier::RefreshGeometry() else { const auto third = Visualization::data->GeometricObject(object3Id); - DrawPoint(point3, third->toQPointF(), supportColor); + DrawPoint(point3, *third, supportColor); if (object4Id <= NULL_ID) { VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos)); DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); - DrawLine(helpLine2, QLineF(third->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); + DrawLine(helpLine2, QLineF(*third, Visualization::scenePos), mainColor, Qt::DashLine); } else { const auto fourth = Visualization::data->GeometricObject(object4Id); - DrawPoint(point4, fourth->toQPointF(), supportColor); - DrawLine(helpLine2, QLineF(fourth->toQPointF(), third->toQPointF()), mainColor, Qt::DashLine); + DrawPoint(point4, *fourth, supportColor); + DrawLine(helpLine2, QLineF(*fourth, *third), mainColor, Qt::DashLine); VCubicBezier spline(*first, *second, *third, *fourth); DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp index 198f64938..d394ec40b 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp @@ -65,7 +65,7 @@ void VisToolCubicBezierPath::RefreshGeometry() for (int i = 0; i < size; ++i) { QGraphicsEllipseItem *point = this->getPoint(mainPoints, static_cast(i), 1/*zValue*/); - DrawPoint(point, pathPoints.at(i).toQPointF(), supportColor); + DrawPoint(point, pathPoints.at(i), supportColor); } if (mode == Mode::Creation) @@ -93,13 +93,13 @@ void VisToolCubicBezierPath::RefreshGeometry() const VSpline spl = path.GetSpline(i); QGraphicsLineItem *ctrlLine1 = this->getLine(static_cast(preLastPoint)); - DrawLine(ctrlLine1, QLineF(spl.GetP1().toQPointF(), spl.GetP2()), mainColor, Qt::DashLine); + DrawLine(ctrlLine1, QLineF(spl.GetP1(), spl.GetP2()), mainColor, Qt::DashLine); QGraphicsEllipseItem *p2 = this->getPoint(ctrlPoints, static_cast(preLastPoint)); DrawPoint(p2, spl.GetP2(), Qt::green); QGraphicsLineItem *ctrlLine2 = this->getLine(static_cast(lastPoint)); - DrawLine(ctrlLine2, QLineF(spl.GetP4().toQPointF(), spl.GetP3()), mainColor, Qt::DashLine); + DrawLine(ctrlLine2, QLineF(spl.GetP4(), spl.GetP3()), mainColor, Qt::DashLine); QGraphicsEllipseItem *p3 = this->getPoint(ctrlPoints, static_cast(lastPoint)); DrawPoint(p3, spl.GetP3(), Qt::green); @@ -180,8 +180,8 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po const VPointF p1 = pathPoints.last(); if (pathPoints.size() >= 4) { - QLineF p1p2(p1.toQPointF(), Visualization::scenePos); - QLineF prP3p1(pathPoints.at(size-2).toQPointF(), p1.toQPointF()); + QLineF p1p2(p1, Visualization::scenePos); + QLineF prP3p1(pathPoints.at(size-2), p1); p1p2.setAngle(prP3p1.angle()); const QPointF p2 = p1p2.p2(); @@ -197,24 +197,24 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po } else { - DrawLine(helpLine1, QLineF(p1.toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); + DrawLine(helpLine1, QLineF(p1, Visualization::scenePos), mainColor, Qt::DashLine); } break; } case 1: { const VPointF p1 = pathPoints.at(subSplPoints + pointsLeft-1); - QPointF p2 = pathPoints.at(subSplPoints + pointsLeft).toQPointF(); + QPointF p2 = pathPoints.at(subSplPoints + pointsLeft); if (subSplCount >= 1) { - QLineF p1p2(p1.toQPointF(), p2); - QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-2).toQPointF(), p1.toQPointF()); + QLineF p1p2(p1, p2); + QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-2), p1); p1p2.setAngle(prP3p1.angle()); p2 = p1p2.p2(); } - DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine); + DrawLine(helpLine1, QLineF(p1, p2), mainColor, Qt::DashLine); VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); @@ -227,18 +227,18 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po case 2: { const VPointF p1 = pathPoints.at(subSplPoints + pointsLeft-2); - QPointF p2 = pathPoints.at(subSplPoints + pointsLeft-1).toQPointF(); - const QPointF p3 = pathPoints.at(subSplPoints + pointsLeft).toQPointF(); + QPointF p2 = pathPoints.at(subSplPoints + pointsLeft-1); + const QPointF p3 = pathPoints.at(subSplPoints + pointsLeft); if (subSplCount >= 1) { - QLineF p1p2(p1.toQPointF(), p2); - QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-3).toQPointF(), p1.toQPointF()); + QLineF p1p2(p1, p2); + QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-3), p1); p1p2.setAngle(prP3p1.angle()); p2 = p1p2.p2(); } - DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine); + DrawLine(helpLine1, QLineF(p1, p2), mainColor, Qt::DashLine); DrawLine(helpLine2, QLineF(p3, Visualization::scenePos), mainColor, Qt::DashLine); VSpline spline(p1, p2, p3, VPointF(Visualization::scenePos)); diff --git a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp index 14bc0a3ca..b4881f0e4 100644 --- a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp @@ -66,7 +66,7 @@ void VisToolCutSplinePath::RefreshGeometry() SCASSERT(spPath1 != nullptr); SCASSERT(spPath2 != nullptr); - DrawPoint(point, p->toQPointF(), mainColor); + DrawPoint(point, *p, mainColor); delete p; DrawPath(splPath1, spPath1->GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/path/vistoolspline.cpp b/src/libs/vtools/visualization/path/vistoolspline.cpp index 58abcd50b..3c19651b7 100644 --- a/src/libs/vtools/visualization/path/vistoolspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolspline.cpp @@ -77,24 +77,24 @@ void VisToolSpline::RefreshGeometry() if (object1Id > NULL_ID) { const auto first = Visualization::data->GeometricObject(object1Id); - DrawPoint(point1, first->toQPointF(), supportColor); + DrawPoint(point1, *first, supportColor); if (mode == Mode::Creation) { if (isLeftMousePressed && not p2Selected) { p2 = Visualization::scenePos; - controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, first->toQPointF()); + controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, *first); if (not controlPoints[0]->isVisible()) { - if (QLineF(first->toQPointF(), p2).length() > radius) + if (QLineF(*first, p2).length() > radius) { controlPoints[0]->show(); } else { - p2 = first->toQPointF(); + p2 = *first; } } } @@ -112,26 +112,26 @@ void VisToolSpline::RefreshGeometry() else { const auto second = Visualization::data->GeometricObject(object4Id); - DrawPoint(point4, second->toQPointF(), supportColor); + DrawPoint(point4, *second, supportColor); if (mode == Mode::Creation) { if (isLeftMousePressed && not p3Selected) { - QLineF ctrlLine (second->toQPointF(), Visualization::scenePos); + QLineF ctrlLine (*second, Visualization::scenePos); ctrlLine.setAngle(ctrlLine.angle()+180); p3 = ctrlLine.p2(); - controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, second->toQPointF()); + controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, *second); if (not controlPoints[1]->isVisible()) { - if (QLineF(second->toQPointF(), p3).length() > radius) + if (QLineF(*second, p3).length() > radius) { controlPoints[1]->show(); } else { - p3 = second->toQPointF(); + p3 = *second; } } } diff --git a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp index 47e0d16fa..1842c8c1a 100644 --- a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp @@ -61,7 +61,7 @@ void VisToolSplinePath::RefreshGeometry() for (int i = 0; i < size; ++i) { QGraphicsEllipseItem *point = this->getPoint(static_cast(i)); - DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor); + DrawPoint(point, pathPoints.at(i).P(), supportColor); } if (mode == Mode::Creation) @@ -76,13 +76,13 @@ void VisToolSplinePath::RefreshGeometry() VSpline spl = path.GetSpline(i); ctrlPoints[preLastPoint]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), - spl.GetP1().toQPointF()); + spl.GetP1()); ctrlPoints[lastPoint]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), - spl.GetP4().toQPointF()); + spl.GetP4()); } } - Creating(pathPoints.at(size-1).P().toQPointF(), size); + Creating(pathPoints.at(size-1).P(), size); } if (size > 1) diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index cc7c7c3aa..fc0838621 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -32,6 +32,7 @@ #include "../../vpatterndb/vtranslatevars.h" #include +#include Q_LOGGING_CATEGORY(vVis, "v.visualization") @@ -157,9 +158,13 @@ qreal Visualization::FindVal(const QString &expression, const QHashTrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); - Calculator *cal = new Calculator(); + QScopedPointer cal(new Calculator()); val = cal->EvalFormula(vars, formula); - delete cal; + + if (qIsInf(val) || qIsNaN(val)) + { + val = 0; + } } catch (qmu::QmuParserError &e) { diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 1f47f42be..fce6c442e 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -32,7 +32,8 @@ HEADERS += \ $$PWD/path/vistoolarcwithlength.h \ $$PWD/path/vistoolpointofintersectioncurves.h \ $$PWD/path/vistoolcubicbezier.h \ - $$PWD/path/vistoolcubicbezierpath.h + $$PWD/path/vistoolcubicbezierpath.h \ + visualization/line/vistoolrotation.h SOURCES += \ $$PWD/visualization.cpp \ @@ -65,4 +66,5 @@ SOURCES += \ $$PWD/path/vistoolarcwithlength.cpp \ $$PWD/path/vistoolpointofintersectioncurves.cpp \ $$PWD/path/vistoolcubicbezier.cpp \ - $$PWD/path/vistoolcubicbezierpath.cpp + $$PWD/path/vistoolcubicbezierpath.cpp \ + visualization/line/vistoolrotation.cpp diff --git a/src/libs/vwidgets/vabstractsimple.cpp b/src/libs/vwidgets/vabstractsimple.cpp index 1649df7f6..44b890f79 100644 --- a/src/libs/vwidgets/vabstractsimple.cpp +++ b/src/libs/vwidgets/vabstractsimple.cpp @@ -28,16 +28,32 @@ #include "vabstractsimple.h" +#include +#include + //--------------------------------------------------------------------------------------------------------------------- VAbstractSimple::VAbstractSimple(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) - :QObject(parent), id (id), factor(factor), currentColor(currentColor), enabled(true), patternUnit(patternUnit) + : QObject(parent), + id (id), + factor(factor), + currentColor(currentColor), + enabled(true), + patternUnit(patternUnit), + selectionType(SelectionType::ByMouseRelease), + type(GOType::Unknown) {} //--------------------------------------------------------------------------------------------------------------------- VAbstractSimple::~VAbstractSimple() {} +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::ToolSelectionType(const SelectionType &type) +{ + selectionType = type; +} + //--------------------------------------------------------------------------------------------------------------------- QColor VAbstractSimple::CorrectColor(const QColor &color) const { @@ -50,3 +66,28 @@ QColor VAbstractSimple::CorrectColor(const QColor &color) const return Qt::gray; } } + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +QColor VAbstractSimple::GetCurrentColor() const +{ + return currentColor; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event) +{ + emit ShowContextMenu(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +GOType VAbstractSimple::GetType() const +{ + return type; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::SetType(const GOType &value) +{ + type = value; +} diff --git a/src/libs/vwidgets/vabstractsimple.h b/src/libs/vwidgets/vabstractsimple.h index bcebd73d1..b4c9600fd 100644 --- a/src/libs/vwidgets/vabstractsimple.h +++ b/src/libs/vwidgets/vabstractsimple.h @@ -33,6 +33,11 @@ #include #include #include "../vmisc/def.h" +#include "../vgeometry/vgeometrydef.h" +#include "../ifc/ifcdef.h" + +class QGraphicsSceneContextMenuEvent; +class QGraphicsItem; class VAbstractSimple : public QObject { @@ -40,9 +45,23 @@ class VAbstractSimple : public QObject public: VAbstractSimple(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor = nullptr, QObject *parent = 0); - virtual ~VAbstractSimple() Q_DECL_OVERRIDE; + virtual ~VAbstractSimple(); - virtual void ChangedActivDraw(const bool &flag)=0; + virtual void ToolSelectionType(const SelectionType &type); + + QColor GetCurrentColor() const; + + virtual void SetEnabled(bool enabled) { Q_UNUSED(enabled); } + + GOType GetType() const; + void SetType(const GOType &value); + +signals: + void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); + void Delete(); + +public slots: + void ContextMenu(QGraphicsSceneContextMenuEvent * event); protected: /** @brief id spline id. */ @@ -58,10 +77,20 @@ protected: Unit patternUnit; + SelectionType selectionType; + + GOType type; + QColor CorrectColor(const QColor &color) const; template - void SetPen(T *item, const QColor &color, qreal width); + void SetPen(T *item, const QColor &color, qreal width); + + template + void SimpleChangedActivDraw(T *item, const bool &flag); + + template + void SetSimpleCurrentColor(T *item, const QColor &value); private: Q_DISABLE_COPY(VAbstractSimple) @@ -73,12 +102,29 @@ void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width) { if (factor == nullptr) { - item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit))); + item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit), Qt::SolidLine, Qt::RoundCap)); } else { - item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor)); + item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor, Qt::SolidLine, Qt::RoundCap)); } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractSimple::SimpleChangedActivDraw(T *item, const bool &flag) +{ + enabled = flag; + item->setEnabled(enabled); + SetPen(item, currentColor, WidthHairLine(patternUnit)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractSimple::SetSimpleCurrentColor(T *item, const QColor &value) +{ + currentColor = value; + SetPen(item, CorrectColor(currentColor), item->pen().widthF()); +} + #endif // VABSTRACTSIMPLE_H diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 438133bf9..e9a8ca248 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -207,6 +207,13 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsSimpleTextItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + if (flags() & QGraphicsItem::ItemIsMovable) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index be0898116..c33877fe4 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -32,7 +32,7 @@ #include #include #include -#include "vsimplepoint.h" +#include "vsimplecurve.h" #include "vmaingraphicsscene.h" #include @@ -402,7 +402,7 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) { if (this->scene()->items().contains(list.at(i))) { - if (list.at(i)->type() <= VSimplePoint::Type && + if (list.at(i)->type() <= VSimpleCurve::Type && list.at(i)->type() > QGraphicsItem::UserType) { emit itemClicked(list.at(i)); diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp new file mode 100644 index 000000000..40ec7992b --- /dev/null +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -0,0 +1,188 @@ +/************************************************************************ + ** + ** @file vsimplecurve.cpp + ** @author Roman Telezhynskyi + ** @date 7 5, 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 "vsimplecurve.h" +#include "../ifc/ifcdef.h" +#include "../vgeometry/vabstractcurve.h" + +#include +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve::VSimpleCurve(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) + : VAbstractSimple(id, currentColor, patternUnit, factor, parent), + QGraphicsPathItem(), + m_curve(), + m_isHovered(false) +{ + this->setBrush(QBrush(Qt::NoBrush)); + SetPen(this, currentColor, WidthHairLine(patternUnit)); + this->setAcceptHoverEvents(true); + this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve::~VSimpleCurve() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::SetCurrentColor(const QColor &value) +{ + SetSimpleCurrentColor(this, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::ChangedActivDraw(bool flag) +{ + SimpleChangedActivDraw(this, flag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) +{ + m_curve = curve; + ShowPath(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::CurveChoosed() +{ + emit Choosed(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::CurveSelected(bool selected) +{ + emit Selected(selected, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + // Special for not selectable item first need to call standard mousePressEvent then accept event + QGraphicsPathItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + + if (selectionType == SelectionType::ByMouseRelease) + { + event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event + } + else + { + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (selectionType == SelectionType::ByMouseRelease) + { + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } + } + QGraphicsPathItem::mouseReleaseEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + m_isHovered = true; + SetPen(this, currentColor, WidthMainLine(patternUnit)); + ShowPath(); + QGraphicsPathItem::hoverEnterEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + m_isHovered = false; + SetPen(this, currentColor, WidthHairLine(patternUnit)); + ShowPath(); + QGraphicsPathItem::hoverLeaveEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVariant VSimpleCurve::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == QGraphicsItem::ItemSelectedChange) + { + emit Selected(value.toBool(), id); + } + + return QGraphicsPathItem::itemChange(change, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + emit ShowContextMenu(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::keyReleaseEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Delete: + emit Delete(); + return; //Leave this method immediately after call!!! + default: + break; + } + QGraphicsPathItem::keyReleaseEvent ( event ); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::ShowPath() +{ + if (not m_curve.isNull()) + { + QPainterPath path; + m_isHovered ? path = m_curve->GetPath(PathDirection::Show) : path = m_curve->GetPath(PathDirection::Hide); + path.setFillRule( Qt::WindingFill ); + setPath(path); + } + else + { + qWarning() << tr("VSimpleCurve::RefreshGeometry: pointer to curve is null."); + } +} diff --git a/src/libs/vwidgets/vsimplecurve.h b/src/libs/vwidgets/vsimplecurve.h new file mode 100644 index 000000000..98ad0c6b0 --- /dev/null +++ b/src/libs/vwidgets/vsimplecurve.h @@ -0,0 +1,83 @@ +/************************************************************************ + ** + ** @file vsimplecurve.h + ** @author Roman Telezhynskyi + ** @date 7 5, 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 VSIMPLECURVE_H +#define VSIMPLECURVE_H + +#include "vabstractsimple.h" + +#include + +class VAbstractCurve; + +class VSimpleCurve : public VAbstractSimple, public QGraphicsPathItem +{ + Q_OBJECT +public: + VSimpleCurve(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor = nullptr, + QObject *parent = nullptr); + virtual ~VSimpleCurve(); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::SimpleCurve)}; + + void SetCurrentColor(const QColor &value); + + void ChangedActivDraw(bool flag); + void RefreshGeometry(const QSharedPointer &curve); +signals: + /** + * @brief Choosed send id when clicked. + * @param id point id. + */ + void Choosed(quint32 id); + void Selected(bool selected, quint32 id); + +public slots: + void CurveChoosed(); + void CurveSelected(bool selected); + +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 QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; + virtual void keyReleaseEvent ( QKeyEvent * event ) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(VSimpleCurve) + + QSharedPointer m_curve; + bool m_isHovered; + + void ShowPath(); +}; + +#endif // VSIMPLECURVE_H diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 6819d52c0..820cfc4dd 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -36,12 +36,12 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) :VAbstractSimple(id, currentColor, patternUnit, factor, parent), QGraphicsEllipseItem(), - radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), namePoint(nullptr), lineName(nullptr), - selectionType(SelectionType::ByMouseRelease) + radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), namePoint(nullptr), lineName(nullptr) { namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); @@ -61,11 +61,15 @@ VSimplePoint::~VSimplePoint() {} //--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::ChangedActivDraw(const bool &flag) +void VSimplePoint::SetCurrentColor(const QColor &value) { - enabled = flag; - setEnabled(enabled); - SetPen(this, currentColor, WidthHairLine(patternUnit)); + SetSimpleCurrentColor(this, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimplePoint::ChangedActivDraw(bool flag) +{ + SimpleChangedActivDraw(this, flag); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,7 +109,7 @@ void VSimplePoint::RefreshGeometry(const VPointF &point) QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); - this->setPos(point.toQPointF()); + this->setPos(point); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); namePoint->blockSignals(true); QFont font = namePoint->font(); @@ -152,7 +156,7 @@ void VSimplePoint::AllowLabelSelecting(bool enabled) //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::ToolSelectionType(const SelectionType &type) { - selectionType = type; + VAbstractSimple::ToolSelectionType(type); namePoint->LabelSelectionType(type); } @@ -171,19 +175,13 @@ void VSimplePoint::PointChoosed() //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::PointSelected(bool selected) { - emit Selected(selected, id); + setSelected(selected); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::ChangedPosition(const QPointF &pos) { - emit NameChangedPosition(pos); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::ContextMenu(QGraphicsSceneContextMenuEvent *event) -{ - emit ShowContextMenu(event); + emit NameChangedPosition(pos, id); } //--------------------------------------------------------------------------------------------------------------------- @@ -191,6 +189,13 @@ void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsEllipseItem::mousePressEvent(event); + + // Somehow clicking on notselectable object do not clean previous selections. + if (not (flags() & ItemIsSelectable) && scene()) + { + scene()->clearSelection(); + } + if (selectionType == SelectionType::ByMouseRelease) { event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event @@ -260,15 +265,7 @@ QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, cons } //--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -QColor VSimplePoint::GetCurrentColor() const +void VSimplePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - return currentColor; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::SetCurrentColor(const QColor &value) -{ - currentColor = value; - SetPen(this, CorrectColor(currentColor), pen().widthF()); + emit ShowContextMenu(event); } diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index 26734429c..87e7e92e1 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -44,21 +44,19 @@ public: QObject *parent = nullptr); virtual ~VSimplePoint() Q_DECL_OVERRIDE; - virtual void ChangedActivDraw(const bool &flag) Q_DECL_OVERRIDE; - virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimplePoint)}; + void ChangedActivDraw(bool flag); void RefreshLine(); void RefreshGeometry(const VPointF &point); - void SetEnabled(bool enabled); + virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; void EnableToolMove(bool move); void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); - void ToolSelectionType(const SelectionType &type); + virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; - QColor GetCurrentColor() const; - void SetCurrentColor(const QColor &value); + void SetCurrentColor(const QColor &value); signals: /** * @brief Choosed send id when clicked. @@ -66,16 +64,13 @@ signals: */ void Choosed(quint32 id); void Selected(bool selected, quint32 id); - void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); - void Delete(); - void NameChangedPosition(const QPointF &pos); + void NameChangedPosition(const QPointF &pos, quint32 id); 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; @@ -84,6 +79,7 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent ( QKeyEvent * event ) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VSimplePoint) @@ -96,9 +92,6 @@ private: /** @brief lineName line what we see if label moved too away from point. */ QGraphicsLineItem *lineName; - - SelectionType selectionType; - }; #endif // VSIMPLEPOINT_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 619eb87e5..d80356e60 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -9,7 +9,8 @@ SOURCES += \ $$PWD/vgraphicssimpletextitem.cpp \ $$PWD/vsimplepoint.cpp \ $$PWD/vabstractsimple.cpp \ - $$PWD/vnobrushscalepathitem.cpp + $$PWD/vnobrushscalepathitem.cpp \ + $$PWD/vsimplecurve.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -22,4 +23,5 @@ HEADERS += \ $$PWD/vgraphicssimpletextitem.h \ $$PWD/vsimplepoint.h \ $$PWD/vabstractsimple.h \ - $$PWD/vnobrushscalepathitem.h + $$PWD/vnobrushscalepathitem.h \ + $$PWD/vsimplecurve.h diff --git a/src/test/ValentinaTest/tst_measurementregexp.cpp b/src/test/ValentinaTest/tst_measurementregexp.cpp index 9da3ed8df..44ba83479 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.cpp +++ b/src/test/ValentinaTest/tst_measurementregexp.cpp @@ -568,7 +568,7 @@ void TST_MeasurementRegExp::InitTrMs() } else { - trMs = new VTranslateVars(true); + trMs = new VTranslateVars(); } } diff --git a/src/test/ValentinaTest/tst_vabstractdetail.cpp b/src/test/ValentinaTest/tst_vabstractdetail.cpp index 4b41575ea..ac60b3a81 100644 --- a/src/test/ValentinaTest/tst_vabstractdetail.cpp +++ b/src/test/ValentinaTest/tst_vabstractdetail.cpp @@ -199,6 +199,44 @@ void TST_VAbstractDetail::PathRemoveLoop_data() const path.removeLast(); QTest::newRow("Corect unclosed a path, point on line (six unique points)") << path << path; + + path.clear(); + path << QPointF(100.96979100571033, 1797.6153764073072); + path << QPointF(168.3888427659865, 1807.2395034187866); + path << QPointF(206.78076137364403, 1812.2910842036706); + path << QPointF(239.1630793382262, 1815.951361623424); + path << QPointF(267.5320085054171, 1818.4827543754482); + path << QPointF(293.9502505847841, 1820.144031725603); + path << QPointF(320.48133946750147, 1821.175819320443); + path << QPointF(364.5960626489172, 1822.0507669842166); + path << QPointF(400.66867742260206, 1822.488188976378); + path << QPointF(623.3126833308274, 1822.488188976378); + path << QPointF(653.5489038032683, 2162.6456692913384); + path << QPointF(570.545584385708, 2162.6456692913384); + path << QPointF(600.7818048581489, 1822.488188976378); + path << QPointF(1001.3385826771654, 1822.488188976378); + path << QPointF(1001.3385826771654, 2680.44094488189); + path << QPointF(-22.11646613738226, 2680.44094488189); + path << QPointF(100.96979100571033, 1797.6153764073072); + + res.clear(); + res << QPointF(100.96979100571033, 1797.6153764073072); + res << QPointF(168.3888427659865, 1807.2395034187866); + res << QPointF(206.78076137364403, 1812.2910842036706); + res << QPointF(239.1630793382262, 1815.951361623424); + res << QPointF(267.5320085054171, 1818.4827543754482); + res << QPointF(293.9502505847841, 1820.144031725603); + res << QPointF(320.48133946750147, 1821.175819320443); + res << QPointF(364.5960626489172, 1822.0507669842166); + res << QPointF(400.66867742260206, 1822.488188976378); + res << QPointF(1001.3385826771654, 1822.488188976378); + res << QPointF(1001.3385826771654, 1822.488188976378); + res << QPointF(1001.3385826771654, 2680.44094488189); + res << QPointF(-22.11646613738226, 2680.44094488189); + res << QPointF(100.96979100571033, 1797.6153764073072); + + // See the file "collection/bugs/Issue_#493.val" + QTest::newRow("Test case issue #493") << path << res; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index 838e282d6..ba2fbfb4c 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -181,7 +181,7 @@ void TST_VArc::TestGetPoints() for (int i=0; i < points.size(); ++i) { - QLineF rLine(center.toQPointF(), points.at(i)); + QLineF rLine(center, points.at(i)); const qreal value = qAbs(rLine.length() - radius); const QString errorMsg = QString("Broken the first rule. All points should be on the same distance from " "the center. Error ='%1'.").arg(value); @@ -199,7 +199,7 @@ void TST_VArc::TestGetPoints() else {// sector square gSquere = (M_PI * radius * radius) / 360.0 * arc.AngleArc(); - points.append(center.toQPointF()); + points.append(center); } // calculated square @@ -211,3 +211,38 @@ void TST_VArc::TestGetPoints() QVERIFY2(value <= epsSquere, qUtf8Printable(errorMsg)); } } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VArc::TestRotation_data() +{ + QTest::addColumn("center"); + QTest::addColumn("radius"); + QTest::addColumn("startAngle"); + QTest::addColumn("endAngle"); + QTest::addColumn("rotatePoint"); + QTest::addColumn("degrees"); + QTest::addColumn("prefix"); + + QTest::newRow("Test arc 1") << QPointF(10, 10) << 10. << 0. << 90. << QPointF() << 90. << "_r"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VArc::TestRotation() +{ + QFETCH(QPointF, center); + QFETCH(qreal, radius); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(QPointF, rotatePoint); + QFETCH(qreal, degrees); + QFETCH(QString, prefix); + + const VArc arcOrigin(VPointF(center), radius, startAngle, endAngle); + const VArc rotatedArc = arcOrigin.Rotate(rotatePoint, degrees, prefix); + + QCOMPARE(arcOrigin.GetLength(), rotatedArc.GetLength()); + QCOMPARE(arcOrigin.AngleArc(), rotatedArc.AngleArc()); + QCOMPARE(arcOrigin.GetRadius(), rotatedArc.GetRadius()); + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); +} diff --git a/src/test/ValentinaTest/tst_varc.h b/src/test/ValentinaTest/tst_varc.h index 997533627..770c2a7a7 100644 --- a/src/test/ValentinaTest/tst_varc.h +++ b/src/test/ValentinaTest/tst_varc.h @@ -42,6 +42,8 @@ private slots: void NegativeArc(); void TestGetPoints_data(); void TestGetPoints(); + void TestRotation_data(); + void TestRotation(); }; #endif // TST_VARC_H diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 6bfd7fa80..023884d47 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -37,34 +37,66 @@ TST_VEllipticalArc::TST_VEllipticalArc(QObject *parent) : QObject(parent) {} +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::CompareTwoWays_data() +{ + QTest::addColumn("c"); + QTest::addColumn("radius1"); + QTest::addColumn("radius2"); + QTest::addColumn("f1"); + QTest::addColumn("f2"); + QTest::addColumn("rotationAngle"); + + //QTest::newRow("Test case 1") << QPointF() << 100. << 200. << 0. << 90.0 << 0.; + QTest::newRow("Test case 2") << QPointF() << 100. << 200. << 0. << 180.0 << 0.; + QTest::newRow("Test case 3") << QPointF() << 100. << 200. << 0. << 270.0 << 0.; + QTest::newRow("Test case 4") << QPointF() << 100. << 200. << 0. << 360.0 << 0.; + QTest::newRow("Test case 5") << QPointF(10, 10) << 100. << 200. << 0. << 90.0 << 80.; + QTest::newRow("Test case 6") << QPointF(10, 10) << 100. << 200. << 0. << 180.0 << 80.; + QTest::newRow("Test case 7") << QPointF(10, 10) << 100. << 200. << 0. << 270.0 << 80.; + QTest::newRow("Test case 8") << QPointF(10, 10) << 100. << 200. << 0. << 360.0 << 80.; + QTest::newRow("Test case 9") << QPointF() << 100. << 200. << 0. << 90.0 << 80.; + QTest::newRow("Test case 10") << QPointF() << 100. << 200. << 0. << 180.0 << 80.; + QTest::newRow("Test case 11") << QPointF() << 100. << 200. << 0. << 270.0 << 80.; + QTest::newRow("Test case 12") << QPointF() << 100. << 200. << 0. << 360.0 << 80.; + QTest::newRow("Test case 13") << QPointF(10, 10) << 100. << 200. << 0. << 90.0 << 80.; + QTest::newRow("Test case 14") << QPointF(10, 10) << 100. << 200. << 0. << 180.0 << 80.; + QTest::newRow("Test case 15") << QPointF(10, 10) << 100. << 200. << 0. << 270.0 << 80.; + QTest::newRow("Test case 16") << QPointF(10, 10) << 100. << 200. << 0. << 360.0 << 80.; +} + //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction void TST_VEllipticalArc::CompareTwoWays() { - const VPointF center; - const qreal radius1 = 100; - const qreal radius2 = 200; - const qreal f1 = 0; - const qreal f2 = 90; - const qreal rotationAngle = 0; + QFETCH(QPointF, c); + QFETCH(qreal, radius1); + QFETCH(qreal, radius2); + QFETCH(qreal, f1); + QFETCH(qreal, f2); + QFETCH(qreal, rotationAngle); - const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); - const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/4; + const VPointF center(c); VEllipticalArc arc1(center, radius1, radius2, f1, f2, rotationAngle); + const qreal length = arc1.GetLength(); + VEllipticalArc arc2(length, center, radius1, radius2, f1, rotationAngle); - const qreal eps = length*0.5/100; // computing error - const QString errorMsg = - QString("Difference between real and computing lengthes bigger than eps = %1.").number(eps); - QVERIFY2(qAbs(arc1.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); - QVERIFY2(qAbs(arc2.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); - QVERIFY2(qAbs(arc1.GetLength() - arc2.GetLength()) <= eps, qUtf8Printable(errorMsg)); + const qreal lengthEps = ToPixel(0.1, Unit::Mm); // computing error + const QString errorLengthMsg = + QString("Difference between real and computing lengthes bigger than eps = %1.").number(lengthEps); + QVERIFY2(qAbs(arc1.GetLength() - length) <= lengthEps, qUtf8Printable(errorLengthMsg)); + QVERIFY2(qAbs(arc2.GetLength() - length) <= lengthEps, qUtf8Printable(errorLengthMsg)); + QVERIFY2(qAbs(arc1.GetLength() - arc2.GetLength()) <= lengthEps, qUtf8Printable(errorLengthMsg)); + const qreal angleEps = 0.4; + const QString errorAngleMsg = + QString("Difference between real and computing angles bigger than eps = %1.").number(angleEps); // compare angles - QVERIFY2(qAbs(arc1.GetEndAngle() - arc2.GetEndAngle()) <= eps, qUtf8Printable(errorMsg)); - QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= eps, qUtf8Printable(errorMsg)); - QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc1.GetEndAngle() - arc2.GetEndAngle()) <= angleEps, qUtf8Printable(errorAngleMsg)); + QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= angleEps, qUtf8Printable(errorAngleMsg)); + QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= angleEps, qUtf8Printable(errorAngleMsg)); } //--------------------------------------------------------------------------------------------------------------------- @@ -78,10 +110,10 @@ void TST_VEllipticalArc::NegativeArc() const qreal f2 = 181; const qreal rotationAngle = 0; + // Full ellipse const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2; - qreal l = -length; - VEllipticalArc arc(l, center, radius1, radius2, f1, rotationAngle); + VEllipticalArc arc(-length, center, radius1, radius2, f1, rotationAngle); const qreal eps = 1; // computing error const QString errorMsg = @@ -267,13 +299,13 @@ void TST_VEllipticalArc::TestGetPoints2() const qreal c = qSqrt(qAbs(radius2*radius2 - radius1*radius1)); // distance from the center to the focus - QPointF focus1 = center.toQPointF(); - QPointF focus2 = center.toQPointF(); + QPointF focus1 = center; + QPointF focus2 = center; if (radius1 < radius2) { focus1.setY(focus1.ry() + c); - QLineF line(center.toQPointF(), focus1); + QLineF line(center, focus1); line.setAngle(line.angle() + rotationAngle); focus1 = line.p2(); @@ -285,7 +317,7 @@ void TST_VEllipticalArc::TestGetPoints2() else { focus1.setX(focus1.rx() + c); - QLineF line(center.toQPointF(), focus1); + QLineF line(center, focus1); line.setAngle(line.angle() + rotationAngle); focus1 = line.p2(); @@ -296,7 +328,7 @@ void TST_VEllipticalArc::TestGetPoints2() } QPointF ellipsePoint(center.x() + radius1, center.y()); - QLineF line(center.toQPointF(), ellipsePoint); + QLineF line(center, ellipsePoint); line.setAngle(line.angle() + rotationAngle); ellipsePoint = line.p2(); @@ -374,3 +406,52 @@ void TST_VEllipticalArc::TestGetPoints4() QVERIFY2(diffLength <= epsLength, qUtf8Printable(errorMsg2)); } } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestRotation_data() +{ + QTest::addColumn("center"); + QTest::addColumn("radius1"); + QTest::addColumn("radius2"); + QTest::addColumn("startAngle"); + QTest::addColumn("endAngle"); + QTest::addColumn("rotationAngle"); + QTest::addColumn("rotatePoint"); + QTest::addColumn("degrees"); + QTest::addColumn("prefix"); + + QTest::newRow("Test el arc 1") << QPointF() << 10. << 20.0 << 1. << 91. << 0.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 2") << QPointF() << 10. << 20.0 << 0. << 90. << 0.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 3") << QPointF(10, 10) << 10. << 20.0 << 1. << 91. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 4") << QPointF(10, 10) << 10. << 20.0 << 0. << 90. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 5") << QPointF(10, 10) << 10. << 20.0 << 0. << 180. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 6") << QPointF(10, 10) << 10. << 20.0 << 1. << 181. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 7") << QPointF(10, 10) << 10. << 20.0 << 0. << 270. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 8") << QPointF(10, 10) << 10. << 20.0 << 1. << 271. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 9") << QPointF(10, 10) << 10. << 20.0 << 0. << 360. << 90.<< QPointF() << 90. << "_r"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestRotation() +{ + QFETCH(QPointF, center); + QFETCH(qreal, radius1); + QFETCH(qreal, radius2); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(qreal, rotationAngle); + QFETCH(QPointF, rotatePoint); + QFETCH(qreal, degrees); + QFETCH(QString, prefix); + + const VEllipticalArc arcOrigin(VPointF(center), radius1, radius2, startAngle, endAngle, rotationAngle); + const VEllipticalArc rotatedArc = arcOrigin.Rotate(rotatePoint, degrees, prefix); + + QVERIFY(qAbs(arcOrigin.AngleArc() - rotatedArc.AngleArc()) <= 0.4); + QVERIFY(qAbs(arcOrigin.GetLength() - rotatedArc.GetLength()) <= ToPixel(1, Unit::Mm)); + QCOMPARE(arcOrigin.GetRadius1(), rotatedArc.GetRadius1()); + QCOMPARE(arcOrigin.GetRadius2(), rotatedArc.GetRadius2()); + QCOMPARE(arcOrigin.GetRotationAngle(), rotatedArc.GetRotationAngle()); + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); +} diff --git a/src/test/ValentinaTest/tst_vellipticalarc.h b/src/test/ValentinaTest/tst_vellipticalarc.h index 179227f91..17e8fc2b1 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.h +++ b/src/test/ValentinaTest/tst_vellipticalarc.h @@ -38,6 +38,7 @@ public: explicit TST_VEllipticalArc(QObject *parent = nullptr); private slots: + void CompareTwoWays_data(); void CompareTwoWays(); void NegativeArc(); void TestGetPoints1_data(); @@ -48,6 +49,8 @@ private slots: void TestGetPoints2(); void TestGetPoints3(); void TestGetPoints4(); + void TestRotation_data(); + void TestRotation(); private: Q_DISABLE_COPY(TST_VEllipticalArc) diff --git a/src/test/ValentinaTest/tst_vspline.cpp b/src/test/ValentinaTest/tst_vspline.cpp index 3b4098dd1..ae5b5c8ca 100644 --- a/src/test/ValentinaTest/tst_vspline.cpp +++ b/src/test/ValentinaTest/tst_vspline.cpp @@ -270,6 +270,52 @@ void TST_VSpline::GetSegmentPoints_NullSegment() Comparison(points, origPoints); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSpline::GetSegmentPoints_RotateTool() +{ + // Input data taken from real case + // See the file /src/app/share/collection/bugs/IsPointOnLineSegment_RotateTool_issue.val + // Test issue with method IsPointOnLineSegment. + + const VPointF p1(155.93961723681397, -42.472964170961042, "A", 5.0000125984251973, 9.9999874015748045); + const VPointF p4(237.32422843061005, 485.80074940371367, "A2", 5.0000125984251973, 9.9999874015748045); + + VSpline spl(p1, p4, 231.11199999999994, "231.112", 145.33899999999997, "145.339", 207.44768503937021, "5.48872", + 337.50916535433066, "8.92993"); + + const QPointF begin(237.32422843061005, 485.80074940371367); + const QPointF end (46.623829088412336, 167.78988631718659); + + QVector points; + points << spl.GetSegmentPoints(begin, end, true); + + QVector origPoints; + origPoints.append(QPointF(237.32422843061005, 485.80074940371367)); + origPoints.append(QPointF(224.47894722830574, 476.8115274500917)); + origPoints.append(QPointF(200.4405599713662, 458.9162132315404)); + origPoints.append(QPointF(178.3387458840754, 441.12004274890694)); + origPoints.append(QPointF(158.12235273581754, 423.422336123843)); + origPoints.append(QPointF(139.74022829597683, 405.8224134780004)); + origPoints.append(QPointF(123.1412203339375, 388.3195949330309)); + origPoints.append(QPointF(108.27417661908376, 370.91320061058616)); + origPoints.append(QPointF(95.08794492079983, 353.60255063231807)); + origPoints.append(QPointF(83.5313730084699, 336.38696511987837)); + origPoints.append(QPointF(73.55330865147822, 319.2657641949186)); + origPoints.append(QPointF(65.10259961920897, 302.2382679790908)); + origPoints.append(QPointF(58.12809368104641, 285.3037965940465)); + origPoints.append(QPointF(52.57863860637471, 268.4616701614375)); + origPoints.append(QPointF(48.40308216457812, 251.71120880291573)); + origPoints.append(QPointF(45.55027212504085, 235.05173264013274)); + origPoints.append(QPointF(43.9690562571471, 218.48256179474038)); + origPoints.append(QPointF(43.6082823302811, 202.00301638839034)); + origPoints.append(QPointF(44.416798113827056, 185.61241654273442)); + origPoints.append(QPointF(46.34345137716919, 169.31008237942433)); + origPoints.append(QPointF(46.623829088412336, 167.78988631718659)); + + // Begin comparison + Comparison(points, origPoints); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_VSpline::CompareThreeWays() { diff --git a/src/test/ValentinaTest/tst_vspline.h b/src/test/ValentinaTest/tst_vspline.h index 30937d5b5..d0b96b5fc 100644 --- a/src/test/ValentinaTest/tst_vspline.h +++ b/src/test/ValentinaTest/tst_vspline.h @@ -46,6 +46,7 @@ private slots: void GetSegmentPoints_issue412(); void GetSegmentPoints_TestPuzzle(); void GetSegmentPoints_NullSegment(); + void GetSegmentPoints_RotateTool(); void CompareThreeWays(); void TestParametrT(); void TestLengthByPoint_data();