/************************************************************************ ** ** @file dialoghistory.cpp ** @author Roman Telezhynskyi ** @date November 15, 2013 ** ** @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 . ** *************************************************************************/ #include "dialoghistory.h" #include "ui_dialoghistory.h" #include "../../libs/vgeometry/varc.h" #include "../../libs/vgeometry/vsplinepath.h" #include "../../libs/vgeometry/vpointf.h" #include "../../libs/vtools/tools/vabstracttool.h" #include "../../libs/vtools/tools/drawTools/vtoolcutspline.h" #include "../../libs/vtools/tools/drawTools/vtoolcutsplinepath.h" #include "../../libs/vtools/tools/drawTools/vtoolcutarc.h" #include "../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogHistory create dialog * @param data container with data * @param doc dom document container * @param parent parent widget */ DialogHistory::DialogHistory(VContainer *data, VPattern *doc, QWidget *parent) :DialogTool(data, 0, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), cursorToolRecordRow(0) { ui->setupUi(this); qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C)); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogHistory::DialogAccepted); FillTable(); InitialTable(); connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked); connect(this, &DialogHistory::ShowHistoryTool, doc, &VPattern::ShowHistoryTool); connect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor); connect(doc, &VPattern::patternChanged, this, &DialogHistory::UpdateHistory); ShowPoint(); } //--------------------------------------------------------------------------------------------------------------------- DialogHistory::~DialogHistory() { delete ui; } //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogAccepted save data and emit signal about closed dialog. */ void DialogHistory::DialogAccepted() { QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); quint32 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, false); emit DialogClosed(QDialog::Accepted); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief cellClicked changed history record * @param row number row in table * @param column number column in table */ void DialogHistory::cellClicked(int row, int column) { if (column == 0) { QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); item->setIcon(QIcon()); item = ui->tableWidget->item(row, 0); cursorRow = row; item->setIcon(QIcon("://icon/32x32/put_after.png")); quint32 id = qvariant_cast(item->data(Qt::UserRole)); doc->blockSignals(true); doc->setCursor(id); doc->blockSignals(false); } else { QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); quint32 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, false); cursorToolRecordRow = row; item = ui->tableWidget->item(cursorToolRecordRow, 0); id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, true); } } //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChangedCursor changed cursor of input. Cursor show after which record we will insert new object * @param id id of object */ void DialogHistory::ChangedCursor(quint32 id) { for (qint32 i = 0; i< ui->tableWidget->rowCount(); ++i) { QTableWidgetItem *item = ui->tableWidget->item(i, 0); quint32 rId = qvariant_cast(item->data(Qt::UserRole)); if (rId == id) { QTableWidgetItem *oldCursorItem = ui->tableWidget->item(cursorRow, 0); oldCursorItem->setIcon(QIcon()); cursorRow = i; item->setIcon(QIcon("://icon/32x32/put_after.png")); } } } //--------------------------------------------------------------------------------------------------------------------- /** * @brief UpdateHistory update history table */ void DialogHistory::UpdateHistory() { FillTable(); InitialTable(); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief FillTable fill table */ void DialogHistory::FillTable() { ui->tableWidget->clear(); QVector history = doc->getLocalHistory(); qint32 currentRow = -1; qint32 count = 0; ui->tableWidget->setRowCount(history.size());//Make row count max possible number for (qint32 i = 0; i< history.size(); ++i) { const VToolRecord tool = history.at(i); const QString historyRecord = Record(tool); if (historyRecord.isEmpty() ==false) { currentRow++; { QTableWidgetItem *item = new QTableWidgetItem(QString()); item->setTextAlignment(Qt::AlignHCenter); item->setData(Qt::UserRole, tool.getId()); ui->tableWidget->setItem(currentRow, 0, item); } QTableWidgetItem *item = new QTableWidgetItem(historyRecord); item->setFont(QFont("Times", 12, QFont::Bold)); item->setFlags(item->flags() ^ Qt::ItemIsEditable); ui->tableWidget->setItem(currentRow, 1, item); ++count; } } ui->tableWidget->setRowCount(count);//Real row count if (count>0) { cursorRow = currentRow; QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); SCASSERT(item != nullptr); item->setIcon(QIcon("://icon/32x32/put_after.png")); } ui->tableWidget->resizeColumnsToContents(); ui->tableWidget->resizeRowsToContents(); ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief Record return description for record * @param tool record data * @return description */ QString DialogHistory::Record(const VToolRecord &tool) { const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) { qDebug()<<"Can't find element by id"< spl = data->GeometricObject(tool.getId()); SCASSERT(spl != nullptr); return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id())); } case Tool::Arc: { const QSharedPointer arc = data->GeometricObject(tool.getId()); SCASSERT(arc != nullptr); return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); } case Tool::ArcWithLength: { const QSharedPointer arc = data->GeometricObject(tool.getId()); SCASSERT(arc != nullptr); return QString(tr("Arc with center in point %1 and length %2")).arg(PointName(arc->GetCenter().id())) .arg(arc->GetLength()); } case Tool::SplinePath: { const QSharedPointer splPath = data->GeometricObject(tool.getId()); SCASSERT(splPath != nullptr); const QVector points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) { // We use only first and last point name in curve record = QString(tr("Curve point %1")).arg(PointName(points.at(0).P().id())); if (points.size() > 1) { record.append(QString("_%1").arg(PointName(points.last().P().id()))); } } else { qDebug()<<"Not enough points in splinepath"< arc = data->GeometricObject(AttrUInt(domElem, VToolCutArc::AttrArc)); SCASSERT(arc != nullptr); return QString(tr("%1 - cut arc with center %2")) .arg(PointName(tool.getId())) .arg(PointName(arc->GetCenter().id())); } case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const QSharedPointer spl = data->GeometricObject(splineId); SCASSERT(spl != nullptr); return QString(tr("%1 - cut curve %2_%3")) .arg(PointName(tool.getId())) .arg(PointName(spl->GetP1().id())) .arg(PointName(spl->GetP4().id())); } case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const QSharedPointer splPath = data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); const QVector points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) { record = QString(tr("%1 - cut curve path %2")) .arg(PointName(tool.getId())) .arg(PointName(points.at(0).P().id())); if (points.size() > 1) { record.append(QString("_%1").arg(PointName(points.last().P().id()))); } } else { qDebug()<<"Not enough points in splinepath"<tableWidget->setSortingEnabled(false); ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(" ")); ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Tool"))); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief ShowPoint show selected point */ void DialogHistory::ShowPoint() { const QVector *history = doc->getHistory(); if (history->size()>0) { QTableWidgetItem *item = ui->tableWidget->item(0, 1); item->setSelected(true); cursorToolRecordRow = 0; item = ui->tableWidget->item(0, 0); quint32 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, true); } } //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogHistory::PointName return point name by id. * * Refacoring what hide ugly string getting point name by id. * @param pointId point if in data. * @return point name. */ QString DialogHistory::PointName(quint32 pointId) { return data->GeometricObject(pointId)->name(); } //--------------------------------------------------------------------------------------------------------------------- quint32 DialogHistory::AttrUInt(const QDomElement &domElement, const QString &name) { return doc->GetParametrUInt(domElement, name, "0"); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief closeEvent handle when windows is closing * @param event event */ void DialogHistory::closeEvent(QCloseEvent *event) { QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); quint32 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, false); DialogTool::closeEvent(event); }