PropertyEditor.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <QApplication>
00028 # include <QPainter>
00029 #endif
00030
00031 #include <Base/Console.h>
00032 #include <App/Application.h>
00033 #include <App/Document.h>
00034 #include "PropertyEditor.h"
00035 #include "PropertyItemDelegate.h"
00036 #include "PropertyModel.h"
00037
00038 using namespace Gui::PropertyEditor;
00039
00040 PropertyEditor::PropertyEditor(QWidget *parent)
00041 : QTreeView(parent), autoupdate(false), committing(false), delaybuild(false)
00042 {
00043 propertyModel = new PropertyModel(this);
00044 setModel(propertyModel);
00045
00046 PropertyItemDelegate* delegate = new PropertyItemDelegate(this);
00047 delegate->setItemEditorFactory(new PropertyItemEditorFactory);
00048 setItemDelegate(delegate);
00049
00050 setAlternatingRowColors(true);
00051 setRootIsDecorated(true);
00052 }
00053
00054 PropertyEditor::~PropertyEditor()
00055 {
00056 }
00057
00058 void PropertyEditor::setAutomaticDocumentUpdate(bool v)
00059 {
00060 autoupdate = v;
00061 }
00062
00063 bool PropertyEditor::isAutomaticDocumentUpdate(bool) const
00064 {
00065 return autoupdate;
00066 }
00067
00068 QStyleOptionViewItem PropertyEditor::viewOptions() const
00069 {
00070 QStyleOptionViewItem option = QTreeView::viewOptions();
00071 option.showDecorationSelected = true;
00072 return option;
00073 }
00074
00075 void PropertyEditor::closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
00076 {
00077 if (autoupdate) {
00078 App::Document* doc = App::GetApplication().getActiveDocument();
00079 if (doc && doc->isTouched())
00080 doc->recompute();
00081 }
00082 QTreeView::closeEditor(editor, hint);
00083 }
00084
00085 void PropertyEditor::commitData (QWidget * editor)
00086 {
00087 committing = true;
00088 QTreeView::commitData(editor);
00089 committing = false;
00090 if (delaybuild) {
00091 delaybuild = false;
00092 propertyModel->buildUp(std::map<std::string, std::vector<App::Property*> >());
00093 }
00094 }
00095
00096 void PropertyEditor::editorDestroyed (QObject * editor)
00097 {
00098 QTreeView::editorDestroyed(editor);
00099 }
00100
00101 void PropertyEditor::currentChanged ( const QModelIndex & current, const QModelIndex & previous )
00102 {
00103 QTreeView::currentChanged(current, previous);
00104 if (previous.isValid())
00105 closePersistentEditor(model()->buddy(previous));
00106 if (current.isValid())
00107 openPersistentEditor(model()->buddy(current));
00108 }
00109
00110 void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
00111 {
00112 QTreeView::drawBranches(painter, rect, index);
00113
00114 QStyleOptionViewItem opt = viewOptions();
00115 PropertyItem *property = static_cast<PropertyItem*>(index.internalPointer());
00116 if (property && property->isSeparator()) {
00117 painter->fillRect(rect, opt.palette.dark());
00118
00119
00120 }
00121
00122
00123
00124
00125
00126
00127 }
00128
00129 void PropertyEditor::buildUp(const std::map<std::string, std::vector<App::Property*> >& props)
00130 {
00131 if (committing) {
00132 Base::Console().Warning("While committing the data to the property the selection has changed.\n");
00133 delaybuild = true;
00134 return;
00135 }
00136
00137 QModelIndex index = this->currentIndex();
00138 QStringList propertyPath = propertyModel->propertyPathFromIndex(index);
00139 propertyModel->buildUp(props);
00140 if (!propertyPath.isEmpty()) {
00141 QModelIndex index = propertyModel->propertyIndexFromPath(propertyPath);
00142 this->setCurrentIndex(index);
00143 }
00144 }
00145
00146 #include "moc_PropertyEditor.cpp"