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