Commands and object making

This commit is contained in:
jriegel
2012-02-12 19:18:29 +01:00
committed by Stefan Tröger
parent 6700512efe
commit 80217bf10f
12 changed files with 182 additions and 31 deletions

View File

@@ -638,6 +638,23 @@ void TreeWidget::slotActiveDocument(const Gui::Document& Doc)
}
}
void TreeWidget::markItem(const App::DocumentObject* Obj,bool mark)
{
// never call without Object!
assert(Obj);
Gui::Document* Doc = Gui::Application::Instance->getDocument(Obj->getDocument());
std::map<const Gui::Document*, DocumentItem*>::iterator jt = DocumentMap.find(Doc);
for (std::map<const Gui::Document*, DocumentItem*>::iterator it = DocumentMap.begin();
it != DocumentMap.end(); ++it)
{
it->second->markItem(Obj,mark);
QFont f = it->second->font(0);
f.setBold(it == jt);
it->second->setFont(0,f);
}
}
void TreeWidget::onTestStatus(void)
{
@@ -874,7 +891,7 @@ void DocumentItem::slotResetEdit(const Gui::ViewProviderDocumentObject& v)
std::string name (v.getObject()->getNameInDocument());
std::map<std::string, DocumentObjectItem*>::iterator it = ObjectMap.find(name);
if (it != ObjectMap.end()) {
it->second->setData(0, Qt::BackgroundColorRole,QVariant());
it->second->setData(0, Qt::BackgroundColorRole,QVariant());
}
}
@@ -1071,6 +1088,21 @@ const Gui::Document* DocumentItem::document() const
return this->pDocument;
}
void DocumentItem::markItem(const App::DocumentObject* Obj,bool mark)
{
// never call without Object!
assert(Obj);
std::map<std::string,DocumentObjectItem*>::iterator pos;
pos = ObjectMap.find(Obj->getNameInDocument());
if (pos != ObjectMap.end()) {
QFont f = pos->second->font(0);
f.setUnderline(mark);
pos->second->setFont(0,f);
}
}
//void DocumentItem::markItem(const App::DocumentObject* Obj,bool mark)
//{
// // never call without Object!
@@ -1185,7 +1217,7 @@ void DocumentItem::selectItems(void)
// The document objects in 'objs' is a subset of the document objects stored
// in 'items'. Since both arrays are sorted we get the wanted tree items in
// linear time.
std::vector<DocumentObjectItem*> common;
std::vector<DocumentObjectItem*> common;
std::vector<DocumentObjectItem*>::iterator item_it = items.begin();
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
item_it = std::find_if(item_it, items.end(), std::bind2nd(ObjectItem_Equal(), *it));
@@ -1197,7 +1229,7 @@ void DocumentItem::selectItems(void)
// get all unselected items of the given document
std::sort(common.begin(), common.end());
std::sort(items.begin(), items.end());
std::vector<DocumentObjectItem*> diff;
std::vector<DocumentObjectItem*> diff;
std::back_insert_iterator<std::vector<DocumentObjectItem*> > biit(diff);
std::set_difference(items.begin(), items.end(), common.begin(), common.end(), biit);
@@ -1315,28 +1347,28 @@ void DocumentObjectItem::testStatus()
QIcon::Mode mode = QIcon::Normal;
if (currentStatus & 1) { // visible
// Note: By default the foreground, i.e. text color is invalid
// to make use of the default color of the tree widget's palette.
// If we temporarily set this color to dark and reset to an invalid
// color again we cannot do it with setTextColor() or setForeground(),
// respectively, because for any reason the color would always switch
// to black which will lead to unreadable text if the system background
// hss already a dark color.
// Note: By default the foreground, i.e. text color is invalid
// to make use of the default color of the tree widget's palette.
// If we temporarily set this color to dark and reset to an invalid
// color again we cannot do it with setTextColor() or setForeground(),
// respectively, because for any reason the color would always switch
// to black which will lead to unreadable text if the system background
// hss already a dark color.
// However, it works if we set the appropriate role to an empty QVariant().
#if QT_VERSION >= 0x040200
this->setData(0, Qt::ForegroundRole,QVariant());
#if QT_VERSION >= 0x040200
this->setData(0, Qt::ForegroundRole,QVariant());
#else
this->setData(0, Qt::TextColorRole,QVariant());
#endif
}
else { // invisible
QStyleOptionViewItem opt;
opt.initFrom(this->treeWidget());
#if QT_VERSION >= 0x040200
this->setData(0, Qt::TextColorRole,QVariant());
#endif
}
else { // invisible
QStyleOptionViewItem opt;
opt.initFrom(this->treeWidget());
#if QT_VERSION >= 0x040200
this->setForeground(0, opt.palette.color(QPalette::Disabled,QPalette::Text));
#else
this->setTextColor(0, opt.palette.color(QPalette::Disabled,QPalette::Text);
#endif
#endif
mode = QIcon::Disabled;
}