Merged develop into feature

--HG--
branch : feature
This commit is contained in:
Bojan Kverh 2016-10-15 11:50:17 +02:00
commit e1a4eeb4e4
10 changed files with 160 additions and 89 deletions

View File

@ -65,6 +65,22 @@ void VWidgetDetails::UpdateList()
FillTable(m_data->DataDetails());
}
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::SelectDetail(quint32 id)
{
const int rowCount = ui->tableWidget->rowCount();
for (int row = 0; row < rowCount; ++row)
{
QTableWidgetItem *item = ui->tableWidget->item(row, 0);
if (item->data(Qt::UserRole).toUInt() == id)
{
ui->tableWidget->setCurrentItem(item);
return;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::InLayoutStateChanged(int row, int column)
{
@ -81,7 +97,7 @@ void VWidgetDetails::InLayoutStateChanged(int row, int column)
const bool inLayout = not allDetails->value(id).IsInLayout();
ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, inLayout, m_data, m_doc);
connect(togglePrint, &ToggleDetailInLayout::NeedLiteParsing, m_doc, &VAbstractPattern::LiteParseTree);
connect(togglePrint, &ToggleDetailInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
qApp->getUndoStack()->push(togglePrint);
}
@ -139,16 +155,50 @@ void VWidgetDetails::FillTable(const QHash<quint32, VDetail> *details)
ui->tableWidget->setCurrentCell(selectedRow, 0);
}
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::ToggleSectionDetails(bool select)
{
const QHash<quint32, VDetail> *allDetails = m_data->DataDetails();
if (allDetails->count() == 0)
{
return;
}
for (int i = 0; i<ui->tableWidget->rowCount(); ++i)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 0);
const quint32 id = item->data(Qt::UserRole).toUInt();
if (allDetails->contains(id))
{
if (not select == allDetails->value(id).IsInLayout())
{
ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc);
connect(togglePrint, &ToggleDetailInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
qApp->getUndoStack()->push(togglePrint);
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VWidgetDetails::ShowContextMenu(const QPoint &pos)
{
QMenu *menu = new QMenu;
QMenu *menu = new QMenu(this);
QAction *actionSelectAll = menu->addAction(tr("Select all"));
QAction *actionSelectNone = menu->addAction(tr("Select none"));
QAction *actionSeparator = new QAction(this);
actionSeparator->setSeparator(true);
menu->addAction(actionSeparator);
QAction *actionInvertSelection = menu->addAction(tr("Invert selection"));
const QHash<quint32, VDetail> *allDetails = m_data->DataDetails();
if (not allDetails->count() == 0)
if (allDetails->count() == 0)
{
return;
}
int selectedDetails = 0;
QHash<quint32, VDetail>::const_iterator iter = allDetails->constBegin();
@ -160,6 +210,7 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
}
++iter;
}
if (selectedDetails == 0)
{
actionSelectNone->setDisabled(true);
@ -169,6 +220,7 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
actionSelectAll->setDisabled(true);
}
QAction *selectedAction = menu->exec(ui->tableWidget->viewport()->mapToGlobal(pos));
bool select;
@ -176,32 +228,32 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos)
{
select = true;
qApp->getUndoStack()->beginMacro(tr("select all details"));
ToggleSectionDetails(select);
}
else if (selectedAction == actionSelectNone)
{
select = false;
qApp->getUndoStack()->beginMacro(tr("select none details"));
ToggleSectionDetails(select);
}
else
else if (selectedAction == actionInvertSelection)
{
return;
}
qApp->getUndoStack()->beginMacro(tr("invert selection"));
for (int i = 0; i<ui->tableWidget->rowCount(); ++i)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 0);
const quint32 id = item->data(Qt::UserRole).toUInt();
if (not select == m_data->DataDetails()->value(id).IsInLayout())
if (allDetails->contains(id))
{
select = not allDetails->value(id).IsInLayout();
ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, select, m_data, m_doc);
connect(togglePrint, &ToggleDetailInLayout::NeedLiteParsing, m_doc, &VAbstractPattern::LiteParseTree);
connect(togglePrint, &ToggleDetailInLayout::UpdateList, this, &VWidgetDetails::UpdateList);
qApp->getUndoStack()->push(togglePrint);
}
}
}
qApp->getUndoStack()->endMacro();
}
else
{
return;
}
}

View File

@ -53,6 +53,7 @@ signals:
public slots:
void UpdateList();
void SelectDetail(quint32 id);
private slots:
void InLayoutStateChanged(int row, int column);
@ -65,6 +66,7 @@ private:
VContainer *m_data;
void FillTable(const QHash<quint32, VDetail> *details);
void ToggleSectionDetails(bool select);
};
#endif // VWIDGETDETAILS_H

View File

@ -3510,6 +3510,8 @@ void MainWindow::InitDocksContain()
detailsWidget = new VWidgetDetails(pattern, doc, this);
connect(doc, &VPattern::FullUpdateFromFile, detailsWidget, &VWidgetDetails::UpdateList);
connect(doc, &VPattern::UpdateInLayoutList, detailsWidget, &VWidgetDetails::UpdateList);
connect(doc, &VPattern::ShowDetail, detailsWidget, &VWidgetDetails::SelectDetail);
connect(detailsWidget, &VWidgetDetails::Highlight, sceneDetails, &VMainGraphicsScene::HighlightItem);
detailsWidget->setVisible(false);
}

View File

@ -1203,6 +1203,18 @@ void VAbstractPattern::ClearScene()
emit ClearMainWindow();
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::CheckInLayoutList()
{
emit UpdateInLayoutList();
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SelectedDetail(quint32 id)
{
emit ShowDetail(id);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::ToolExists(const quint32 &id) const
{

View File

@ -292,6 +292,8 @@ signals:
void UndoCommand();
void SetEnabledGUI(bool enabled);
void CheckLayout();
void UpdateInLayoutList();
void ShowDetail(quint32 id);
void SetCurrentPP(const QString &patterPiece);
public slots:
@ -299,6 +301,8 @@ public slots:
void haveLiteChange();
void NeedFullParsing();
void ClearScene();
void CheckInLayoutList();
void SelectedDetail(quint32 id);
protected:
/** @brief nameActivDraw name current pattern peace. */

View File

@ -156,9 +156,9 @@ const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
*/
const VDetail VContainer::GetDetail(quint32 id) const
{
if (d->details.contains(id))
if (d->details->contains(id))
{
return d->details.value(id);
return d->details->value(id);
}
else
{
@ -188,8 +188,8 @@ quint32 VContainer::AddGObject(VGObject *obj)
*/
quint32 VContainer::AddDetail(const VDetail &detail)
{
quint32 id = getNextId();
d->details[id] = detail;
const quint32 id = getNextId();
d->details->insert(id, detail);
return id;
}
@ -260,7 +260,7 @@ void VContainer::Clear()
qCDebug(vCon, "Clearing container data.");
_id = NULL_ID;
d->details.clear();
d->details->clear();
ClearVariables();
ClearGObjects();
ClearUniqueNames();
@ -272,7 +272,7 @@ void VContainer::ClearForFullParse()
qCDebug(vCon, "Clearing container data for full parse.");
_id = NULL_ID;
d->details.clear();
d->details->clear();
ClearVariables(VarType::Increment);
ClearVariables(VarType::LineAngle);
ClearVariables(VarType::LineLength);
@ -496,7 +496,7 @@ void VContainer::UpdateGObject(quint32 id, VGObject* obj)
void VContainer::UpdateDetail(quint32 id, const VDetail &detail)
{
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
d->details[id] = detail;
d->details->insert(id, detail);
UpdateId(id);
}
@ -653,7 +653,7 @@ const QMap<QString, QSharedPointer<T> > VContainer::DataVar(const VarType &type)
// cppcheck-suppress unusedFunction
void VContainer::ClearDetails()
{
d->details.clear();
d->details->clear();
}
//---------------------------------------------------------------------------------------------------------------------
@ -731,7 +731,7 @@ const QHash<quint32, QSharedPointer<VGObject> > *VContainer::DataGObjects() cons
*/
const QHash<quint32, VDetail> *VContainer::DataDetails() const
{
return &d->details;
return d->details.data();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -78,14 +78,19 @@ class VContainerData : public QSharedData //-V690
public:
VContainerData(const VTranslateVars *trVars, const Unit *patternUnit)
:gObjects(QHash<quint32, QSharedPointer<VGObject> >()),
variables(QHash<QString, QSharedPointer<VInternalVariable> > ()), details(QHash<quint32, VDetail>()),
: gObjects(QHash<quint32, QSharedPointer<VGObject> >()),
variables(QHash<QString, QSharedPointer<VInternalVariable> > ()),
details(QSharedPointer<QHash<quint32, VDetail>>(new QHash<quint32, VDetail>())),
trVars(trVars), patternUnit(patternUnit)
{}
VContainerData(const VContainerData &data)
:QSharedData(data), gObjects(data.gObjects),
variables(data.variables), details(data.details), trVars(data.trVars), patternUnit(data.patternUnit)
: QSharedData(data),
gObjects(data.gObjects),
variables(data.variables),
details(data.details),
trVars(data.trVars),
patternUnit(data.patternUnit)
{}
virtual ~VContainerData();
@ -102,7 +107,7 @@ public:
/**
* @brief details container of details
*/
QHash<quint32, VDetail> details;
QSharedPointer<QHash<quint32, VDetail>> details;
const VTranslateVars *trVars;
const Unit *patternUnit;

View File

@ -76,6 +76,7 @@
#include "../undocommands/deletedetail.h"
#include "../undocommands/movedetail.h"
#include "../undocommands/savedetailoptions.h"
#include "../undocommands/toggledetailinlayout.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vcubicbezier.h"
#include "../vgeometry/vcubicbezierpath.h"
@ -710,6 +711,7 @@ void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
doc->SelectedDetail(id);
emit ChoosedTool(id, SceneObject::Detail);
}
@ -771,15 +773,15 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu menu;
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
QAction *inLayoutOption = menu.addAction(tr("In layout"));
inLayoutOption->setCheckable(true);
const VDetail detail = VAbstractTool::data.GetDetail(id);
inLayoutOption->setChecked(detail.IsInLayout());
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
if (_referens > 1)
{
actionRemove->setEnabled(false);
}
else
{
actionRemove->setEnabled(true);
}
_referens > 1 ? actionRemove->setEnabled(false) : actionRemove->setEnabled(true);
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
{
@ -791,6 +793,13 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
setDialog();
dialog->show();
}
else if (selectedAction == inLayoutOption)
{
ToggleDetailInLayout *togglePrint = new ToggleDetailInLayout(id, selectedAction->isChecked(),
&(VAbstractTool::data), doc);
connect(togglePrint, &ToggleDetailInLayout::UpdateList, doc, &VAbstractPattern::CheckInLayoutList);
qApp->getUndoStack()->push(togglePrint);
}
else if (selectedAction == actionRemove)
{
try

View File

@ -82,22 +82,6 @@ void ToggleDetailInLayout::redo()
}
}
//---------------------------------------------------------------------------------------------------------------------
bool ToggleDetailInLayout::mergeWith(const QUndoCommand *command)
{
const ToggleDetailInLayout *stateCommand = static_cast<const ToggleDetailInLayout *>(command);
SCASSERT(stateCommand != nullptr);
const quint32 id = stateCommand->getDetId();
if (id != m_id)
{
return false;
}
m_newState = stateCommand->getNewState();
return true;
}
//---------------------------------------------------------------------------------------------------------------------
int ToggleDetailInLayout::id() const
{
@ -134,8 +118,7 @@ void ToggleDetailInLayout::Do(bool state)
VDetail det = m_data->DataDetails()->value(m_id);
det.SetInLayout(state);
m_data->UpdateDetail(m_id, det);
emit NeedLiteParsing(Document::LiteParse);
emit UpdateList();
}
else
{

View File

@ -50,10 +50,12 @@ public:
virtual ~ToggleDetailInLayout();
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
quint32 getDetId() const;
bool getNewState() const;
signals:
void UpdateList();
private:
Q_DISABLE_COPY(ToggleDetailInLayout)
quint32 m_id;