Don't use combobox instead return list of pattern pieces.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-05 14:35:38 +03:00
parent 34f9451460
commit c03464144e
3 changed files with 46 additions and 25 deletions

View File

@ -90,7 +90,7 @@ MainWindow::MainWindow(QWidget *parent)
pattern = new VContainer(); pattern = new VContainer();
doc = new VPattern(pattern, comboBoxDraws, &mode); doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails);
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified);
connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear);
@ -1884,20 +1884,9 @@ void MainWindow::LoadPattern(const QString &fileName)
return; return;
} }
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
try try
{ {
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
doc->Parse(Document::FullParse, sceneDraw, sceneDetails); doc->Parse(Document::FullParse, sceneDraw, sceneDetails);
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
ui->actionPattern_properties->setEnabled(true);
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
@ -1948,8 +1937,15 @@ void MainWindow::LoadPattern(const QString &fileName)
Clear(); Clear();
return; return;
} }
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
comboBoxDraws->clear();
comboBoxDraws->addItems(doc->getPatternPieces());
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
ui->actionPattern_properties->setEnabled(true);
QString nameDraw = doc->GetNameActivDraw(); QString nameDraw = doc->GetNameActivDraw();
qint32 index = comboBoxDraws->findText(nameDraw); qint32 index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) if ( index != -1 )

View File

@ -70,10 +70,15 @@ const QString VPattern::IncrementKgrowth = QStringLiteral("kgrowth");
const QString VPattern::IncrementDescription = QStringLiteral("description"); const QString VPattern::IncrementDescription = QStringLiteral("description");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPattern::VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent) VPattern::VPattern(VContainer *data, Valentina::Draws *mode, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail, QObject *parent)
: QObject(parent), VDomDocument(data), nameActivDraw(QString()), tools(QHash<quint32, VDataTool*>()), : QObject(parent), VDomDocument(data), nameActivDraw(QString()), tools(QHash<quint32, VDataTool*>()),
history(QVector<VToolRecord>()), cursor(0), comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false) history(QVector<VToolRecord>()), cursor(0), patternPieces(QStringList()), mode(mode), patternModified(false),
{} sceneDraw(sceneDraw), sceneDetail(sceneDetail)
{
SCASSERT(sceneDraw != nullptr);
SCASSERT(sceneDetail != nullptr);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -237,6 +242,9 @@ bool VPattern::SetNameDraw(const QString &name)
*/ */
void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail) void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail)
{ {
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
Q_CHECK_PTR(sceneDraw); Q_CHECK_PTR(sceneDraw);
Q_CHECK_PTR(sceneDetail); Q_CHECK_PTR(sceneDetail);
PrepareForParse(parse, sceneDraw, sceneDetail); PrepareForParse(parse, sceneDraw, sceneDetail);
@ -263,7 +271,7 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene
{ {
ChangeActivDraw(GetParametrString(domElement, AttrName)); ChangeActivDraw(GetParametrString(domElement, AttrName));
} }
comboBoxDraws->addItem(GetParametrString(domElement, AttrName)); patternPieces << GetParametrString(domElement, AttrName);
} }
else else
{ {
@ -292,6 +300,9 @@ void VPattern::Parse(const Document::Documents &parse, VMainGraphicsScene *scene
} }
domNode = domNode.nextSibling(); domNode = domNode.nextSibling();
} }
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -331,15 +342,17 @@ void VPattern::setCursor(const quint32 &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setCurrentData set current data set. * @brief setCurrentData set current data set.
*
* Each time after parsing need set correct data set for current pattern piece. After parsing it is always last.
* Current data set for pattern pice it is data set for last object in pattern pice (point, arc, spline, spline path so
* on).
*/ */
void VPattern::setCurrentData() void VPattern::setCurrentData()
{ {
if (*mode == Valentina::Calculation) if (*mode == Valentina::Calculation)
{ {
const QString nameDraw = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); if (patternPieces.size() > 1)//don't need upadate data if we have only one pattern piece
if (nameActivDraw != nameDraw)
{ {
nameActivDraw = nameDraw;
quint32 id = 0; quint32 id = 0;
if (history.size() == 0) if (history.size() == 0)
{ {
@ -348,7 +361,7 @@ void VPattern::setCurrentData()
for (qint32 i = 0; i < history.size(); ++i) for (qint32 i = 0; i < history.size(); ++i)
{ {
const VToolRecord tool = history.at(i); const VToolRecord tool = history.at(i);
if (tool.getNameDraw() == nameDraw) if (tool.getNameDraw() == nameActivDraw)
{ {
id = tool.getId(); id = tool.getId();
} }
@ -737,6 +750,7 @@ void VPattern::ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable)
emit ShowTool(id, color, enable); emit ShowTool(id, color, enable);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ParseDrawElement parse draw tag. * @brief ParseDrawElement parse draw tag.
@ -1833,7 +1847,7 @@ void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsSc
nameActivDraw.clear(); nameActivDraw.clear();
sceneDraw->clear(); sceneDraw->clear();
sceneDetail->clear(); sceneDetail->clear();
comboBoxDraws->clear(); patternPieces.clear();
tools.clear(); tools.clear();
cursor = 0; cursor = 0;
} }

View File

@ -62,7 +62,8 @@ class VPattern : public QObject, public VDomDocument
{ {
Q_OBJECT Q_OBJECT
public: public:
VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent = nullptr); VPattern(VContainer *data, Valentina::Draws *mode, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
QObject *parent = nullptr);
void CreateEmptyFile(const QString &tablePath); void CreateEmptyFile(const QString &tablePath);
void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse); void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse);
QString GetNameActivDraw() const; QString GetNameActivDraw() const;
@ -115,6 +116,7 @@ public:
static const QString IncrementKgrowth; static const QString IncrementKgrowth;
static const QString IncrementDescription; static const QString IncrementDescription;
virtual bool SaveDocument(const QString &fileName); virtual bool SaveDocument(const QString &fileName);
QStringList getPatternPieces() const;
signals: signals:
/** /**
* @brief ChangedActivDraw change active pattern peace. * @brief ChangedActivDraw change active pattern peace.
@ -165,15 +167,18 @@ private:
QVector<VToolRecord> history; QVector<VToolRecord> history;
/** @brief cursor cursor keep id tool after which we will add new tool in file. */ /** @brief cursor cursor keep id tool after which we will add new tool in file. */
quint32 cursor; quint32 cursor;
QComboBox *comboBoxDraws; QStringList patternPieces;
/** @brief mode current draw mode. */ /** @brief mode current draw mode. */
Valentina::Draws *mode; Valentina::Draws *mode;
/** @brief fileModified true if exist change in file. */ /** @brief fileModified true if exist change in file. */
bool patternModified; bool patternModified;
VMainGraphicsScene *sceneDraw;
VMainGraphicsScene *sceneDetail;
bool CheckNameDraw(const QString& name) const; bool CheckNameDraw(const QString& name) const;
void SetActivDraw(const QString& name); void SetActivDraw(const QString& name);
@ -255,4 +260,10 @@ inline void VPattern::setPatternModified(bool value)
patternModified = value; patternModified = value;
} }
//---------------------------------------------------------------------------------------------------------------------
inline QStringList VPattern::getPatternPieces() const
{
return patternPieces;
}
#endif // VPATTERN_H #endif // VPATTERN_H