diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cc00ee9ab..99be787f5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -115,41 +115,14 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::ActionNewDraw() { - QString nameDraw; - bool bOk; - qint32 index; - QString nDraw = QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1); - QInputDialog *dlg = new QInputDialog(this); - dlg->setInputMode( QInputDialog::TextInput ); - dlg->setLabelText(tr("Pattern piece:")); - dlg->setTextEchoMode(QLineEdit::Normal); - dlg->setWindowTitle(tr("Enter a label for the pattern piece.")); - dlg->resize(300, 100); - dlg->setTextValue(nDraw); - while (1) + const QString nameDraw = PatternPieceName(QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1)); + if (nameDraw.isEmpty()) { - bOk = dlg->exec(); - nameDraw = dlg->textValue(); - if (bOk == false || nameDraw.isEmpty()) - { - delete dlg; - return; - } - index = comboBoxDraws->findText(nameDraw); - if (index != -1) - {//we already have this name - qCritical()<appendDraw(nameDraw); - if (bOk == false) + if (doc->appendDraw(nameDraw) == false) { - qCritical()<(&QComboBox::currentIndexChanged), @@ -158,18 +131,21 @@ void MainWindow::ActionNewDraw() pattern->ClearGObjects(); //Create single point - quint32 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10)); + const quint32 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, + 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui); + Q_CHECK_PTR(spoint); sceneDraw->addItem(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); QHash* tools = doc->getTools(); + Q_CHECK_PTR(tools); tools->insert(id, spoint); VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); SetEnableTool(true); SetEnableWidgets(true); - index = comboBoxDraws->findText(nameDraw); + const qint32 index = comboBoxDraws->findText(nameDraw); if ( index != -1 ) { // -1 for not found comboBoxDraws->setCurrentIndex(index); @@ -181,46 +157,20 @@ void MainWindow::ActionNewDraw() void MainWindow::OptionDraw() { - QString nameDraw; - qint32 index; - QString nDraw = doc->GetNameActivDraw(); - QInputDialog *dlg = new QInputDialog(this); - dlg->setInputMode( QInputDialog::TextInput ); - dlg->setLabelText(tr("Pattern piece:")); - dlg->setTextEchoMode(QLineEdit::Normal); - dlg->setWindowTitle(tr("Enter a new label for the pattern piece.")); - dlg->resize(300, 100); - dlg->setTextValue(nDraw); - while (1) + const QString activDraw = doc->GetNameActivDraw(); + const QString nameDraw = PatternPieceName(activDraw); + if (nameDraw.isEmpty()) { - bool bOk = dlg->exec(); - nameDraw = dlg->textValue(); - if (bOk == false || nameDraw.isEmpty()) - { - delete dlg; - return; - } - index = comboBoxDraws->findText(nameDraw); - if (index != -1) - {//we already have this name - qCritical()<findText(doc->GetNameActivDraw()); if (doc->SetNameDraw(nameDraw)) { - comboBoxDraws->setItemText(index, nameDraw); + comboBoxDraws->setItemText(comboBoxDraws->findText(activDraw), nameDraw); } else { QMessageBox::warning(this, tr("Error saving change!!!"), tr("Can't save new label of pattern piece")); } - } template @@ -1362,6 +1312,35 @@ void MainWindow::InitAutoSave() } } +QString MainWindow::PatternPieceName(const QString &text) +{ + QInputDialog *dlg = new QInputDialog(this); + Q_CHECK_PTR(dlg); + dlg->setInputMode( QInputDialog::TextInput ); + dlg->setLabelText(tr("Pattern piece:")); + dlg->setTextEchoMode(QLineEdit::Normal); + dlg->setWindowTitle(tr("Enter a new label for the pattern piece.")); + dlg->resize(300, 100); + dlg->setTextValue(text); + QString nameDraw; + while (1) + { + const bool bOk = dlg->exec(); + nameDraw = dlg->textValue(); + if (bOk == false || nameDraw.isEmpty()) + { + delete dlg; + return QString(); + } + if (comboBoxDraws->findText(nameDraw) == -1) + { + break; + } + } + delete dlg; + return nameDraw; +} + MainWindow::~MainWindow() { CancelTool(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 9cc622812..8d83bbd99 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -561,6 +561,7 @@ private: void CreateMenus(); void CreateActions(); void InitAutoSave(); + QString PatternPieceName(const QString &text); }; #endif // MAINWINDOW_H diff --git a/src/xml/vpattern.cpp b/src/xml/vpattern.cpp index 82f53e3af..633734c8c 100644 --- a/src/xml/vpattern.cpp +++ b/src/xml/vpattern.cpp @@ -188,7 +188,7 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene if (domElement.isNull() == false) { QStringList tags; - tags << TagDraw << TagIncrements; + tags << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes; switch (tags.indexOf(domElement.tagName())) { case 0: // TagDraw @@ -213,6 +213,12 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene case 1: // TagIncrements ParseIncrementsElement(domElement); break; + case 2: // TagAuthor + break; + case 3: // TagDescription + break; + case 4: // TagNotes + break; default: qWarning()<<"Wrong tag name"<