Fixed problem with images included in branches. Added missing adaptormodel.* files
1 #include "branchpropwindow.h"
3 #include <QColorDialog>
5 #include "branchitem.h"
9 extern Settings settings;
10 extern QString vymName;
13 BranchPropertyWindow::BranchPropertyWindow (QWidget *parent): QDialog (parent)
17 setCaption(vymName +" - " +tr ("Property Editor","Window caption"));
23 ui.tabWidget->setEnabled(false);
25 penColor=QColor (Qt::black);
26 brushColor=QColor (Qt::black);
29 ui.framePenColorButton->setPixmap (pix);
30 ui.frameBrushColorButton->setPixmap (pix);
32 // Create Model and View to hold attributes // FIXME-3
34 attributeModel = new QStandardItemModel (1,3,this);
35 attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
36 attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
37 attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
38 ui.attributeTableView->setModel (attributeModel);
42 resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
43 move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
45 if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
50 // FIXME-2 for now remove attribute tab
51 ui.tabWidget->removeTab (3);
55 BranchPropertyWindow::~BranchPropertyWindow ()
57 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
58 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
59 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
62 void BranchPropertyWindow::setBranch (BranchItem *bi)
69 branch=(BranchObj*)(branchItem->getLMO());
70 if (branch) // FIXME-3 move to branchItem later, when Frame is ported...
72 ui.tabWidget->setEnabled (true);
75 FrameObj::FrameType t=branch->getFrameType();
76 if (t==FrameObj::NoFrame)
78 ui.frameTypeCombo->setCurrentIndex (0);
81 ui.colorGroupBox->setEnabled (false);
82 ui.framePaddingSpinBox->setEnabled (false);
83 ui.frameWidthSpinBox->setEnabled (false);
84 ui.framePaddingLabel->setEnabled (false);
85 ui.frameBorderLabel->setEnabled (false);
88 penColor=branch->getFramePenColor();
89 brushColor=branch->getFrameBrushColor();
92 ui.framePenColorButton->setPixmap (pix);
93 pix.fill (brushColor);
94 ui.frameBrushColorButton->setPixmap (pix);
95 ui.colorGroupBox->setEnabled (true);
96 ui.framePaddingSpinBox->setEnabled (true);
97 ui.framePaddingSpinBox->setValue (branch->getFramePadding());
98 ui.frameWidthSpinBox->setEnabled (true);
99 ui.frameWidthSpinBox->setValue (branch->getFrameBorderWidth());
100 ui.framePaddingLabel->setEnabled (true);
101 ui.frameBorderLabel->setEnabled (true);
105 case FrameObj::Rectangle:
106 ui.frameTypeCombo->setCurrentIndex (1);
108 case FrameObj::Ellipse:
109 ui.frameTypeCombo->setCurrentIndex (2);
117 if (branchItem->getHideLinkUnselected())
118 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
120 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
123 if (branchItem->getIncludeImagesVer())
124 ui.incImgVer->setCheckState (Qt::Checked);
126 ui.incImgVer->setCheckState (Qt::Unchecked);
127 if (branchItem->getIncludeImagesHor())
128 ui.incImgHor->setCheckState (Qt::Checked);
130 ui.incImgHor->setCheckState (Qt::Unchecked);
134 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
136 // FIXME-3 some samples for attribute testing
137 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
138 for (int i=0; i<attrTypes.count()-1;i++)
140 attributeModel->insertRow (i,QModelIndex ());
141 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
142 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
143 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
147 ui.attributeTableView->resizeColumnsToContents();
149 // Initialize Delegate
150 delegate.setAttributeTable (mapEditor->attributeTable());
151 ui.attributeTableView->setItemDelegate (&delegate);
154 // Finally activate signals
159 ui.tabWidget->setEnabled (false);
163 void BranchPropertyWindow::setModel (VymModel *m)
167 setBranch (model->getSelectedBranchItem() );
169 ui.tabWidget->setEnabled (false);
173 void BranchPropertyWindow::frameTypeChanged (int i)
179 case 0: model->setFrameType (FrameObj::NoFrame); break;
181 model->setFrameType (FrameObj::Rectangle);
184 model->setFrameType (FrameObj::Ellipse);
185 model->setFramePadding (5);
188 setBranch (branchItem);
192 void BranchPropertyWindow::framePenColorClicked()
196 QColor col = QColorDialog::getColor( penColor, this );
200 model->setFramePenColor (penColor);
205 void BranchPropertyWindow::frameBrushColorClicked()
209 QColor col = QColorDialog::getColor( brushColor, this );
213 model->setFrameBrushColor (brushColor);
218 void BranchPropertyWindow::framePaddingChanged(int i)
220 if (model) model->setFramePadding (i);
223 void BranchPropertyWindow::frameBorderWidthChanged(int i)
225 if (model) model->setFrameBorderWidth(i);
228 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
230 if (!branchItem) return;
231 model->setHideLinkUnselected(i);
234 void BranchPropertyWindow::incImgVerChanged (int i)
236 if (model) model->setIncludeImagesVer (i);
239 void BranchPropertyWindow::incImgHorChanged (int i)
241 if (model) model->setIncludeImagesHor (i);
244 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
246 ce->accept(); // can be reopened with show()
248 emit (windowClosed() );
253 void BranchPropertyWindow::addAttributeClicked()
255 // Add empty line for adding attributes
256 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
257 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
258 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
260 // Select attribute from list
261 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
262 ui.attributeTableView->resizeColumnsToContents();
264 // QString attname=attributeModel->in
265 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
269 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
273 void BranchPropertyWindow::deleteAttributeClicked()
275 //FIXME-3 cout << "BPW::delete\n";
279 void BranchPropertyWindow::connectSignals()
283 ui.framePenColorButton, SIGNAL (clicked()),
284 this, SLOT (framePenColorClicked()));
286 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
287 this, SLOT (framePaddingChanged (int)));
289 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
290 this, SLOT (frameBorderWidthChanged (int)));
292 ui.frameBrushColorButton, SIGNAL (clicked()),
293 this, SLOT (frameBrushColorClicked()));
295 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
296 this, SLOT (frameTypeChanged (int)));
301 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
302 this, SLOT (linkHideUnselectedChanged (int)));
306 ui.incImgVer, SIGNAL (stateChanged( int)),
307 this, SLOT (incImgVerChanged (int)));
309 ui.incImgHor, SIGNAL (stateChanged( int)),
310 this, SLOT (incImgHorChanged (int)));
315 ui.addAttributeButton, SIGNAL (clicked()),
316 this, SLOT (addAttributeClicked()));
318 ui.deleteAttributeButton, SIGNAL (clicked()),
319 this, SLOT (deleteAttributeClicked()));
324 void BranchPropertyWindow::disconnectSignals()
327 disconnect ( ui.frameTypeCombo, 0,0,0);
328 disconnect ( ui.framePenColorButton, 0,0,0);
329 disconnect ( ui.framePaddingSpinBox, 0,0,0);
330 disconnect ( ui.frameWidthSpinBox, 0,0,0);
331 disconnect ( ui.frameBrushColorButton, 0,0,0);
334 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
337 disconnect ( ui.incImgVer, 0,0,0);
338 disconnect ( ui.incImgHor, 0,0,0);
342 disconnect ( ui.addAttributeButton, 0,0,0);
343 disconnect ( ui.deleteAttributeButton, 0,0,0);