Permalink
Browse files

Line pattern manager

  • Loading branch information...
feragon committed Jul 27, 2016
1 parent 01a6d96 commit 0964d931e451101d9f7cce69f1709bff41240df5
View
@@ -41,10 +41,12 @@ widgets/layermodel.h
widgets/linepatternselect.h
widgets/linepatternpainter.h
widgets/linepatternpathpart.h
widgets/linepatternmodel.h
lua/qtbridge.h
lua/luaqobject.h
dialogs/addlayerdialog.h
dialogs/addlinepatterndialog.h)
dialogs/addlinepatterndialog.h
dialogs/linepatternmanager.h)
set(UI_srcs
cadmdichild.cpp
@@ -64,10 +66,12 @@ widgets/layermodel.cpp
widgets/linepatternselect.cpp
widgets/linepatternpainter.cpp
widgets/linepatternpathpart.cpp
widgets/linepatternmodel.cpp
lua/qtbridge.cpp
lua/luaqobject.cpp
dialogs/addlayerdialog.cpp
dialogs/addlinepatterndialog.cpp)
dialogs/addlinepatterndialog.cpp
dialogs/linepatternmanager.cpp)
QT5_WRAP_UI(UI_HEADERS
widgets/clicommand.ui
@@ -77,7 +81,8 @@ widgets/toolbartab.ui
widgets/layers.ui
widgets/linepatternpathpart.ui
dialogs/addlayerdialog.ui
dialogs/addlinepatterndialog.ui)
dialogs/addlinepatterndialog.ui
dialogs/linepatternmanager.ui)
qt5_add_resources(UI_RESOURCES
ui/resource.qrc)
@@ -0,0 +1,86 @@
#include "linepatternmanager.h"
#include "ui_linepatternmanager.h"
LinePatternManager::LinePatternManager(lc::Document_SPtr document, QWidget* parent) :
QDialog(parent),
ui(new Ui::LinePatternManager),
_model(new LinePatternModel(this)) {
ui->setupUi(this);
setDocument(document);
ui->lpView->setModel(_model);
ui->lpView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->lpView->horizontalHeader()->setSectionResizeMode(LinePatternModel::NAME, QHeaderView::Stretch);
show();
}
LinePatternManager::~LinePatternManager() {
delete ui;
delete _model;
}
void LinePatternManager::setDocument(lc::Document_SPtr document) {
if(_document != nullptr) {
_document->addLinePatternEvent().disconnect<LinePatternManager, &LinePatternManager::on_addLinePatternEvent>(this);
_document->removeLinePatternEvent().disconnect<LinePatternManager, &LinePatternManager::on_removeLinePatternEvent>(this);
_document->replaceLinePatternEvent().disconnect<LinePatternManager, &LinePatternManager::on_replaceLinePatternEvent>(this);
}
_document = document;
if(_document != nullptr) {
_document->addLinePatternEvent().connect<LinePatternManager, &LinePatternManager::on_addLinePatternEvent>(this);
_document->removeLinePatternEvent().connect<LinePatternManager, &LinePatternManager::on_removeLinePatternEvent>(this);
_document->replaceLinePatternEvent().connect<LinePatternManager, &LinePatternManager::on_replaceLinePatternEvent>(this);
}
updateModel();
}
void LinePatternManager::on_editButton_pressed() {
QItemSelectionModel* select = ui->lpView->selectionModel();
if(!select->hasSelection()) {
return;
}
auto row = select->selectedRows().first().row();
auto linePattern = _model->linePatternAt(row);
auto dialog = new AddLinePatternDialog(_document, linePattern, this);
dialog->show();
}
void LinePatternManager::on_newButton_pressed() {
auto dialog = new AddLinePatternDialog(_document, this);
dialog->show();
}
void LinePatternManager::on_lpView_doubleClicked(const QModelIndex &index) {
if(!index.isValid()) {
return;
}
auto linePattern = _model->linePatternAt(index.row());
auto dialog = new AddLinePatternDialog(_document, linePattern, this);
dialog->show();
}
void LinePatternManager::updateModel() {
_model->setLinePatterns(_document->linePatterns());
}
void LinePatternManager::on_addLinePatternEvent(const lc::AddLinePatternEvent &) {
updateModel();
}
void LinePatternManager::on_removeLinePatternEvent(const lc::RemoveLinePatternEvent &) {
updateModel();
}
void LinePatternManager::on_replaceLinePatternEvent(const lc::ReplaceLinePatternEvent &) {
updateModel();
}
@@ -0,0 +1,38 @@
#pragma once
#include <QDialog>
#include <QHeaderView>
#include <cad/document/document.h>
#include <dialogs/addlinepatterndialog.h>
#include <widgets/linepatternmodel.h>
namespace Ui {
class LinePatternManager;
}
class LinePatternManager : public QDialog {
Q_OBJECT
public:
LinePatternManager(lc::Document_SPtr document, QWidget* parent = 0);
~LinePatternManager();
void setDocument(lc::Document_SPtr document);
private slots:
void on_editButton_pressed();
void on_newButton_pressed();
void on_lpView_doubleClicked(const QModelIndex& index);
private:
void updateModel();
Ui::LinePatternManager* ui;
lc::Document_SPtr _document;
LinePatternModel* _model;
void on_addLinePatternEvent(const lc::AddLinePatternEvent&);
void on_removeLinePatternEvent(const lc::RemoveLinePatternEvent&);
void on_replaceLinePatternEvent(const lc::ReplaceLinePatternEvent&);
};
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LinePatternManager</class>
<widget class="QDialog" name="LinePatternManager">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>502</height>
</rect>
</property>
<property name="windowTitle">
<string>Line Patterns</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="newButton">
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="lpView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
View
@@ -258,6 +258,12 @@ void addLCBindings(lua_State *L) {
.addFunction("activeLayer", &Layers::activeLayer)
.endClass()
.beginExtendClass<LinePatternManager, QDialog>("LinePatternManager")
.addFactory([](lc::Document_SPtr document){
return new LinePatternManager(document);
})
.endClass()
.endModule();
}
View
@@ -30,6 +30,7 @@ extern "C"
#include "widgets/toolbar.h"
#include "widgets/toolbartab.h"
#include "widgets/layers.h"
#include "dialogs/linepatternmanager.h"
#include <drawables/tempentities.h>
@@ -0,0 +1,77 @@
#include "linepatternmodel.h"
LinePatternModel::LinePatternModel(QObject *parent) :
QAbstractTableModel(parent) {
}
void LinePatternModel::setLinePatterns(std::vector<lc::DxfLinePattern_CSPtr> linePatterns) {
beginResetModel();
_linePatterns = linePatterns;
endResetModel();
}
lc::DxfLinePattern_CSPtr LinePatternModel::linePatternAt(const int index) const {
return _linePatterns.at(index);
}
int LinePatternModel::rowCount(const QModelIndex&) const {
return _linePatterns.size();
}
int LinePatternModel::columnCount(const QModelIndex&) const {
return LAST;
}
QVariant LinePatternModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) {
return QVariant();
}
auto linePattern = _linePatterns.at(index.row());
if(role == Qt::DecorationRole && index.column() == PREVIEW) {
QPixmap pixmap(PREVIEW_WIDTH, PREVIEW_HEIGHT);
auto painter = LinePatternPainter(linePattern, &pixmap);
painter.drawLinePattern();
return pixmap;
}
if(role == Qt::SizeHintRole && index.column() == PREVIEW) {
return QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
}
if(role == Qt::DisplayRole) {
switch (index.column()) {
case NAME:
return linePattern->name().c_str();
case DESCRIPTION:
return linePattern->description().c_str();
}
}
return QVariant();
}
QVariant LinePatternModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal) {
if(role == Qt::DisplayRole) {
switch(section) {
case PREVIEW:
return "Preview";
case NAME:
return "Name";
case DESCRIPTION:
return "Description";
}
}
}
return QAbstractTableModel::headerData(section, orientation, role);
}
@@ -0,0 +1,38 @@
#pragma once
#include <QAbstractTableModel>
#include <QIcon>
#include <QPixmap>
#include <cad/meta/dxflinepattern.h>
#include <widgets/linepatternpainter.h>
#define PREVIEW_WIDTH 100
#define PREVIEW_HEIGHT 20
class LinePatternModel : public QAbstractTableModel {
Q_OBJECT
public:
enum columns {
PREVIEW,
NAME,
DESCRIPTION,
LAST
};
LinePatternModel(QObject* parent = 0);
void setLinePatterns(std::vector<lc::DxfLinePattern_CSPtr> linePatterns);
lc::DxfLinePattern_CSPtr linePatternAt(const int index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
private:
std::vector<lc::DxfLinePattern_CSPtr> _linePatterns;
};
View
@@ -120,4 +120,15 @@ function add_toolbar()
local removeButton = create_button("", ":/icons/modifytrim.png")
quickAccess:addButton(modifyGroup, removeButton, 2, 1, 1, 1)
luaInterface:luaConnect(removeButton, "pressed()", trim_entity)
--
-- Line Patterns
--
local linePatternsGroup = quickAccess:addGroup("Entity properties")
local linePatternsButton = create_button("Line Patterns")
quickAccess:addButton(linePatternsGroup, linePatternsButton, 0, 0, 1, 1)
luaInterface:luaConnect(linePatternsButton, "pressed()", function()
lc.LinePatternManager(active_widget():document())
end)
end

0 comments on commit 0964d93

Please sign in to comment.