]> Shamusworld >> Repos - architektonas/blob - src/forms/blockdialog.cpp
a3666d23fd8425dbf0ea9750a7cc7a58a320de45
[architektonas] / src / forms / blockdialog.cpp
1 // blockdialog.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/10/2010  Created this file. :-)
15 //
16
17 #include "blockdialog.h"
18
19 #include "rs_blocklist.h"
20
21 BlockDialog::BlockDialog(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
22         QDialog(parent, flags), blockList(NULL)
23 {
24         ui.setupUi(this);
25 }
26
27 BlockDialog::~BlockDialog()
28 {
29 }
30
31 void BlockDialog::setBlockList(RS_BlockList * l)
32 {
33         RS_DEBUG->print("BlockDialog::setBlockList");
34         blockList = l;
35
36         if (blockList != NULL)
37         {
38                 RS_Block * block = blockList->getActive();
39
40                 if (block != NULL)
41                         ui.leName->setText(block->getName());
42                 else
43                         RS_DEBUG->print(RS_Debug::D_ERROR, "BlockDialog::setBlockList: No block active.");
44         }
45 }
46
47 RS_BlockData BlockDialog::getBlockData()
48 {
49     /*if (blockList!=NULL) {
50       RS_Block* block = blockList->getActive();
51         if (block!=NULL) {
52            return blockList->rename(block, leName->text().latin1());
53         }
54 }
55
56     return false;*/
57
58         return RS_BlockData(ui.leName->text(), Vector(0.0, 0.0), false);
59 }
60
61 void BlockDialog::validate()
62 {
63         QString name = ui.leName->text();
64
65         if (!name.isEmpty())
66         {
67                 if (blockList != NULL && blockList->find(name) == NULL)
68                         accept();
69                 else
70                         QMessageBox::warning(this, tr("Renaming Block"),
71                                 tr("Could not name block. A block named \"%1\" already exists.").arg(ui.leName->text()),
72                                 QMessageBox::Ok, Qt::NoButton);
73         }
74 }
75
76 void BlockDialog::cancel()
77 {
78         ui.leName->setText("");
79         reject();
80 }