Refactoring main windows.

--HG--
branch : feature
This commit is contained in:
dismine 2014-03-03 17:30:04 +02:00
parent 084061fbd5
commit 978858be50
3 changed files with 52 additions and 66 deletions

View File

@ -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()<<tr("Error. Pattern piece of same label already exists.");
}
else
{
break;
}
return;
}
delete dlg;
bOk = doc->appendDraw(nameDraw);
if (bOk == false)
if (doc->appendDraw(nameDraw) == false)
{
qCritical()<<tr("Error creating pattern with the name ")<<nameDraw<<".";
qWarning()<<tr("Error creating pattern with the name ")<<nameDraw<<".";
return;
}
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&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<quint32, VDataTool*>* 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()<<tr("Error. Pattern piece of same name already exists.");
}
else
{
break;
}
return;
}
delete dlg;
index = comboBoxDraws->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 <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()
{
CancelTool();

View File

@ -561,6 +561,7 @@ private:
void CreateMenus();
void CreateActions();
void InitAutoSave();
QString PatternPieceName(const QString &text);
};
#endif // MAINWINDOW_H

View File

@ -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"<<Q_FUNC_INFO;
break;