Skip to content

Commit

Permalink
Add manage button in line pattern selector
Browse files Browse the repository at this point in the history
  • Loading branch information
feragon committed Aug 9, 2016
1 parent 943242e commit f60aea1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lcUI/widgets/linepatternpainter.cpp
Expand Up @@ -6,7 +6,7 @@ LinePatternPainter::LinePatternPainter(QPaintDevice *device, lc::DxfLinePattern_
_width(width) {
}

LinePatternPainter::LinePatternPainter(QPaintDevice *device, int width, lc::DxfLinePattern_CSPtr linePattern) :
LinePatternPainter::LinePatternPainter(QPaintDevice *device, double width, lc::DxfLinePattern_CSPtr linePattern) :
_device(device),
_linePattern(linePattern),
_width(width) {
Expand Down
2 changes: 1 addition & 1 deletion lcUI/widgets/linepatternpainter.h
Expand Up @@ -7,7 +7,7 @@
class LinePatternPainter {
public:
LinePatternPainter(QPaintDevice* device, lc::DxfLinePattern_CSPtr linePattern, int width = 1);
LinePatternPainter(QPaintDevice* device, int width, lc::DxfLinePattern_CSPtr linePattern = nullptr);
LinePatternPainter(QPaintDevice* device, double width, lc::DxfLinePattern_CSPtr linePattern = nullptr);
void drawLinePattern();

private:
Expand Down
17 changes: 11 additions & 6 deletions lcUI/widgets/linepatternselect.cpp
Expand Up @@ -63,21 +63,26 @@ void LinePatternSelect::onActivated(const QString& text) {
auto dialog = new AddLinePatternDialog(_document, this);
dialog->show();
}
else if(text == MANAGE_LP) {
auto dialog = new LinePatternManager(_document, this);
dialog->show();
}
}

void LinePatternSelect::createEntries() {
clear();

if(_document != nullptr) {
if(_showByBlock) {
insertItem(0, BY_BLOCK);
}
addItem(NEW_LP);
addItem(MANAGE_LP);
insertSeparator(2);

if(_showByLayer) {
insertItem(0, BY_LAYER);
addItem(BY_LAYER);
}
if(_showByBlock) {
addItem(BY_BLOCK);
}

insertItem(0, NEW_LP);

auto linePatterns = _document->linePatterns();
for (auto linePattern : linePatterns) {
Expand Down
2 changes: 2 additions & 0 deletions lcUI/widgets/linepatternselect.h
Expand Up @@ -5,11 +5,13 @@
#include <cad/meta/dxflinepattern.h>
#include <widgets/linepatternpainter.h>
#include <dialogs/addlinepatterndialog.h>
#include <dialogs/linepatternmanager.h>
#include <cad/document/document.h>

#define BY_BLOCK "ByBlock"
#define BY_LAYER "ByLayer"
#define NEW_LP "New line pattern"
#define MANAGE_LP "Manage line patterns"

class LinePatternSelect : public QComboBox {
Q_OBJECT
Expand Down
6 changes: 3 additions & 3 deletions unittest/ui/testlinepatterns.cpp
Expand Up @@ -68,11 +68,11 @@ TEST(LinePatternTest, Selection) {
auto document = createDocument();

auto linePatternSelect = new LinePatternSelect(document);
EXPECT_EQ(1, linePatternSelect->count()) << "Select should contains New";
EXPECT_EQ(3, linePatternSelect->count()) << "Select should contains New/Manage/Separator";
delete linePatternSelect;

linePatternSelect = new LinePatternSelect(document, 0, true, true);
EXPECT_EQ(3, linePatternSelect->count()) << "Select should contains New/ByBlock/ByLayer";
EXPECT_EQ(5, linePatternSelect->count()) << "Select should contains New/Manage/Separator/ByBlock/ByLayer";

auto linePattern1 = std::make_shared<const lc::DxfLinePattern>("LP", "Line Pattern", std::vector<double>{1, -1, 0, -1}, 3);
auto linePattern2 = std::make_shared<const lc::DxfLinePattern>("NLP", "New Line Pattern", std::vector<double>{0, -1, 1, -1}, 3);
Expand All @@ -82,7 +82,7 @@ TEST(LinePatternTest, Selection) {
operation = std::make_shared<lc::operation::AddLinePattern>(document, linePattern2);
operation->execute();

EXPECT_EQ(5, linePatternSelect->count()) << "Layers were not added to line pattern select";
EXPECT_EQ(7, linePatternSelect->count()) << "Line patterns were not added to select";

linePatternSelect->setCurrentText(linePattern1->name().c_str());
EXPECT_EQ(linePattern1, linePatternSelect->linePattern()) << "Selected line pattern wasn't returned";
Expand Down

0 comments on commit f60aea1

Please sign in to comment.