Refactoring main windows.
--HG-- branch : feature
This commit is contained in:
parent
084061fbd5
commit
978858be50
|
@ -115,41 +115,14 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
void MainWindow::ActionNewDraw()
|
void MainWindow::ActionNewDraw()
|
||||||
{
|
{
|
||||||
QString nameDraw;
|
const QString nameDraw = PatternPieceName(QString(tr("Pattern piece %1")).arg(comboBoxDraws->count()+1));
|
||||||
bool bOk;
|
if (nameDraw.isEmpty())
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
bOk = dlg->exec();
|
|
||||||
nameDraw = dlg->textValue();
|
|
||||||
if (bOk == false || nameDraw.isEmpty())
|
|
||||||
{
|
|
||||||
delete dlg;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index = comboBoxDraws->findText(nameDraw);
|
if (doc->appendDraw(nameDraw) == false)
|
||||||
if (index != -1)
|
|
||||||
{//we already have this name
|
|
||||||
qCritical()<<tr("Error. Pattern piece of same label already exists.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
break;
|
qWarning()<<tr("Error creating pattern with the name ")<<nameDraw<<".";
|
||||||
}
|
|
||||||
}
|
|
||||||
delete dlg;
|
|
||||||
bOk = doc->appendDraw(nameDraw);
|
|
||||||
if (bOk == false)
|
|
||||||
{
|
|
||||||
qCritical()<<tr("Error creating pattern with the name ")<<nameDraw<<".";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
|
@ -158,18 +131,21 @@ void MainWindow::ActionNewDraw()
|
||||||
|
|
||||||
pattern->ClearGObjects();
|
pattern->ClearGObjects();
|
||||||
//Create single point
|
//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);
|
VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui);
|
||||||
|
Q_CHECK_PTR(spoint);
|
||||||
sceneDraw->addItem(spoint);
|
sceneDraw->addItem(spoint);
|
||||||
connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem);
|
connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem);
|
||||||
connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
|
connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
|
||||||
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
||||||
|
Q_CHECK_PTR(tools);
|
||||||
tools->insert(id, spoint);
|
tools->insert(id, spoint);
|
||||||
VDrawTool::AddRecord(id, Tool::SinglePointTool, doc);
|
VDrawTool::AddRecord(id, Tool::SinglePointTool, doc);
|
||||||
SetEnableTool(true);
|
SetEnableTool(true);
|
||||||
SetEnableWidgets(true);
|
SetEnableWidgets(true);
|
||||||
|
|
||||||
index = comboBoxDraws->findText(nameDraw);
|
const qint32 index = comboBoxDraws->findText(nameDraw);
|
||||||
if ( index != -1 )
|
if ( index != -1 )
|
||||||
{ // -1 for not found
|
{ // -1 for not found
|
||||||
comboBoxDraws->setCurrentIndex(index);
|
comboBoxDraws->setCurrentIndex(index);
|
||||||
|
@ -181,46 +157,20 @@ void MainWindow::ActionNewDraw()
|
||||||
|
|
||||||
void MainWindow::OptionDraw()
|
void MainWindow::OptionDraw()
|
||||||
{
|
{
|
||||||
QString nameDraw;
|
const QString activDraw = doc->GetNameActivDraw();
|
||||||
qint32 index;
|
const QString nameDraw = PatternPieceName(activDraw);
|
||||||
QString nDraw = doc->GetNameActivDraw();
|
if (nameDraw.isEmpty())
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
bool bOk = dlg->exec();
|
|
||||||
nameDraw = dlg->textValue();
|
|
||||||
if (bOk == false || nameDraw.isEmpty())
|
|
||||||
{
|
|
||||||
delete dlg;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index = comboBoxDraws->findText(nameDraw);
|
|
||||||
if (index != -1)
|
|
||||||
{//we already have this name
|
|
||||||
qCritical()<<tr("Error. Pattern piece of same name already exists.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete dlg;
|
|
||||||
index = comboBoxDraws->findText(doc->GetNameActivDraw());
|
|
||||||
if (doc->SetNameDraw(nameDraw))
|
if (doc->SetNameDraw(nameDraw))
|
||||||
{
|
{
|
||||||
comboBoxDraws->setItemText(index, nameDraw);
|
comboBoxDraws->setItemText(comboBoxDraws->findText(activDraw), nameDraw);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Error saving change!!!"), tr("Can't save new label of pattern piece"));
|
QMessageBox::warning(this, tr("Error saving change!!!"), tr("Can't save new label of pattern piece"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Dialog, typename Func>
|
template <typename Dialog, typename Func>
|
||||||
|
@ -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()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
CancelTool();
|
CancelTool();
|
||||||
|
|
|
@ -561,6 +561,7 @@ private:
|
||||||
void CreateMenus();
|
void CreateMenus();
|
||||||
void CreateActions();
|
void CreateActions();
|
||||||
void InitAutoSave();
|
void InitAutoSave();
|
||||||
|
QString PatternPieceName(const QString &text);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -188,7 +188,7 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene
|
||||||
if (domElement.isNull() == false)
|
if (domElement.isNull() == false)
|
||||||
{
|
{
|
||||||
QStringList tags;
|
QStringList tags;
|
||||||
tags << TagDraw << TagIncrements;
|
tags << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes;
|
||||||
switch (tags.indexOf(domElement.tagName()))
|
switch (tags.indexOf(domElement.tagName()))
|
||||||
{
|
{
|
||||||
case 0: // TagDraw
|
case 0: // TagDraw
|
||||||
|
@ -213,6 +213,12 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene
|
||||||
case 1: // TagIncrements
|
case 1: // TagIncrements
|
||||||
ParseIncrementsElement(domElement);
|
ParseIncrementsElement(domElement);
|
||||||
break;
|
break;
|
||||||
|
case 2: // TagAuthor
|
||||||
|
break;
|
||||||
|
case 3: // TagDescription
|
||||||
|
break;
|
||||||
|
case 4: // TagNotes
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qWarning()<<"Wrong tag name"<<Q_FUNC_INFO;
|
qWarning()<<"Wrong tag name"<<Q_FUNC_INFO;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user