]> Shamusworld >> Repos - architektonas/blob - src/forms/blockdialog.cpp
Bugfixes related to removing Snapper class.
[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 "blocklist.h"
20 #include "debug.h"
21
22 BlockDialog::BlockDialog(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QDialog(parent, flags), blockList(NULL)
24 {
25         ui.setupUi(this);
26 }
27
28 BlockDialog::~BlockDialog()
29 {
30 }
31
32 void BlockDialog::setBlockList(BlockList * l)
33 {
34         DEBUG->print("BlockDialog::setBlockList");
35         blockList = l;
36
37         if (blockList != NULL)
38         {
39                 Block * block = blockList->getActive();
40
41                 if (block != NULL)
42                         ui.leName->setText(block->getName());
43                 else
44                         DEBUG->print(Debug::D_ERROR, "BlockDialog::setBlockList: No block active.");
45         }
46 }
47
48 BlockData BlockDialog::getBlockData()
49 {
50     /*if (blockList!=NULL) {
51       Block* block = blockList->getActive();
52         if (block!=NULL) {
53            return blockList->rename(block, leName->text().latin1());
54         }
55 }
56
57     return false;*/
58
59         return BlockData(ui.leName->text(), Vector(0.0, 0.0), false);
60 }
61
62 void BlockDialog::validate()
63 {
64         QString name = ui.leName->text();
65
66         if (!name.isEmpty())
67         {
68                 if (blockList != NULL && blockList->find(name) == NULL)
69                         accept();
70                 else
71                         QMessageBox::warning(this, tr("Renaming Block"),
72                                 tr("Could not name block. A block named \"%1\" already exists.").arg(ui.leName->text()),
73                                 QMessageBox::Ok, Qt::NoButton);
74         }
75 }
76
77 void BlockDialog::cancel()
78 {
79         ui.leName->setText("");
80         reject();
81 }