All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
eafd18dac0
commit
25c3ba7338
@@ -20,8 +20,8 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
# include <QApplication>
|
||||
# include <QFont>
|
||||
#include <QApplication>
|
||||
#include <QFont>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
@@ -37,343 +37,393 @@
|
||||
using namespace Gui;
|
||||
namespace sp = std::placeholders;
|
||||
|
||||
namespace Gui {
|
||||
// forward declaration
|
||||
class ViewProviderIndex;
|
||||
namespace Gui
|
||||
{
|
||||
// forward declaration
|
||||
class ViewProviderIndex;
|
||||
|
||||
// Base class
|
||||
class DocumentModelIndex : public Base::BaseClass
|
||||
// Base class
|
||||
class DocumentModelIndex: public Base::BaseClass
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
~DocumentModelIndex() override
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
qDeleteAll(childItems);
|
||||
}
|
||||
|
||||
public:
|
||||
~DocumentModelIndex() override
|
||||
{ qDeleteAll(childItems); }
|
||||
|
||||
void setParent(DocumentModelIndex* parent)
|
||||
{ parentItem = parent; }
|
||||
DocumentModelIndex *parent() const
|
||||
{ return parentItem; }
|
||||
void appendChild(DocumentModelIndex *child)
|
||||
{ childItems.append(child); child->setParent(this); }
|
||||
void removeChild(int row)
|
||||
{ childItems.removeAt(row); }
|
||||
QList<DocumentModelIndex*> removeAll()
|
||||
{
|
||||
QList<DocumentModelIndex*> list = childItems;
|
||||
childItems.clear();
|
||||
return list;
|
||||
void setParent(DocumentModelIndex* parent)
|
||||
{
|
||||
parentItem = parent;
|
||||
}
|
||||
DocumentModelIndex* parent() const
|
||||
{
|
||||
return parentItem;
|
||||
}
|
||||
void appendChild(DocumentModelIndex* child)
|
||||
{
|
||||
childItems.append(child);
|
||||
child->setParent(this);
|
||||
}
|
||||
void removeChild(int row)
|
||||
{
|
||||
childItems.removeAt(row);
|
||||
}
|
||||
QList<DocumentModelIndex*> removeAll()
|
||||
{
|
||||
QList<DocumentModelIndex*> list = childItems;
|
||||
childItems.clear();
|
||||
return list;
|
||||
}
|
||||
DocumentModelIndex* child(int row)
|
||||
{
|
||||
return childItems.value(row);
|
||||
}
|
||||
int row() const
|
||||
{
|
||||
if (parentItem) {
|
||||
return parentItem->childItems.indexOf(const_cast<DocumentModelIndex*>(this));
|
||||
}
|
||||
DocumentModelIndex *child(int row)
|
||||
{ return childItems.value(row); }
|
||||
int row() const
|
||||
{
|
||||
if (parentItem)
|
||||
return parentItem->childItems.indexOf
|
||||
(const_cast<DocumentModelIndex*>(this));
|
||||
return 0;
|
||||
}
|
||||
int childCount() const
|
||||
{ return childItems.count(); }
|
||||
virtual QVariant data(int role) const
|
||||
{
|
||||
Q_UNUSED(role);
|
||||
return {};
|
||||
}
|
||||
virtual bool setData (const QVariant & value, int role)
|
||||
{
|
||||
Q_UNUSED(value);
|
||||
if (role == Qt::EditRole) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int childCount() const
|
||||
{
|
||||
return childItems.count();
|
||||
}
|
||||
virtual QVariant data(int role) const
|
||||
{
|
||||
Q_UNUSED(role);
|
||||
return {};
|
||||
}
|
||||
virtual bool setData(const QVariant& value, int role)
|
||||
{
|
||||
Q_UNUSED(value);
|
||||
if (role == Qt::EditRole) {
|
||||
return true;
|
||||
}
|
||||
virtual Qt::ItemFlags flags() const
|
||||
{
|
||||
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
|
||||
}
|
||||
|
||||
protected:
|
||||
void reset()
|
||||
{ qDeleteAll(childItems); childItems.clear(); }
|
||||
|
||||
protected:
|
||||
DocumentModelIndex() = default;
|
||||
DocumentModelIndex *parentItem{nullptr};
|
||||
QList<DocumentModelIndex*> childItems;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Root node
|
||||
class ApplicationIndex : public DocumentModelIndex
|
||||
return true;
|
||||
}
|
||||
virtual Qt::ItemFlags flags() const
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
ApplicationIndex() = default;
|
||||
int findChild(const Gui::Document& d) const;
|
||||
Qt::ItemFlags flags() const override;
|
||||
QVariant data(int role) const override;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Document nodes
|
||||
class DocumentIndex : public DocumentModelIndex
|
||||
{
|
||||
friend class ViewProviderIndex;
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
static QIcon* documentIcon;
|
||||
using IndexSet = boost::unordered_set<ViewProviderIndex*>;
|
||||
std::map<const ViewProviderDocumentObject*, IndexSet> vp_nodes;
|
||||
void addToDocument(ViewProviderIndex*);
|
||||
void removeFromDocument(ViewProviderIndex*);
|
||||
|
||||
public:
|
||||
const Gui::Document& d;
|
||||
explicit DocumentIndex(const Gui::Document& d) : d(d)
|
||||
{
|
||||
if (!documentIcon)
|
||||
documentIcon = new QIcon(Gui::BitmapFactory().pixmap("Document"));
|
||||
}
|
||||
~DocumentIndex() override
|
||||
{
|
||||
qDeleteAll(childItems); childItems.clear();
|
||||
}
|
||||
ViewProviderIndex* cloneViewProvider(const ViewProviderDocumentObject&) const;
|
||||
int rowOfViewProvider(const ViewProviderDocumentObject&) const;
|
||||
void findViewProviders(const ViewProviderDocumentObject&, QList<ViewProviderIndex*>&) const;
|
||||
QVariant data(int role) const override;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Object nodes
|
||||
class ViewProviderIndex : public DocumentModelIndex
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
const Gui::ViewProviderDocumentObject& v;
|
||||
ViewProviderIndex(const Gui::ViewProviderDocumentObject& v, DocumentIndex* d);
|
||||
~ViewProviderIndex() override;
|
||||
ViewProviderIndex* clone() const;
|
||||
void findViewProviders(const ViewProviderDocumentObject&, QList<ViewProviderIndex*>&) const;
|
||||
QVariant data(int role) const override;
|
||||
|
||||
private:
|
||||
DocumentIndex* d;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
int ApplicationIndex::findChild(const Gui::Document& d) const
|
||||
{
|
||||
int child=0;
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it, ++child) {
|
||||
auto doc = static_cast<DocumentIndex*>(*it);
|
||||
if (&doc->d == &d)
|
||||
return child;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
}
|
||||
|
||||
Qt::ItemFlags ApplicationIndex::flags() const
|
||||
protected:
|
||||
void reset()
|
||||
{
|
||||
return Qt::ItemIsEnabled;
|
||||
qDeleteAll(childItems);
|
||||
childItems.clear();
|
||||
}
|
||||
|
||||
QVariant ApplicationIndex::data(int role) const
|
||||
protected:
|
||||
DocumentModelIndex() = default;
|
||||
DocumentModelIndex* parentItem {nullptr};
|
||||
QList<DocumentModelIndex*> childItems;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Root node
|
||||
class ApplicationIndex: public DocumentModelIndex
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
ApplicationIndex() = default;
|
||||
int findChild(const Gui::Document& d) const;
|
||||
Qt::ItemFlags flags() const override;
|
||||
QVariant data(int role) const override;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Document nodes
|
||||
class DocumentIndex: public DocumentModelIndex
|
||||
{
|
||||
friend class ViewProviderIndex;
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
static QIcon* documentIcon;
|
||||
using IndexSet = boost::unordered_set<ViewProviderIndex*>;
|
||||
std::map<const ViewProviderDocumentObject*, IndexSet> vp_nodes;
|
||||
void addToDocument(ViewProviderIndex*);
|
||||
void removeFromDocument(ViewProviderIndex*);
|
||||
|
||||
public:
|
||||
const Gui::Document& d;
|
||||
explicit DocumentIndex(const Gui::Document& d)
|
||||
: d(d)
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return qApp->windowIcon();
|
||||
if (!documentIcon) {
|
||||
documentIcon = new QIcon(Gui::BitmapFactory().pixmap("Document"));
|
||||
}
|
||||
else if (role == Qt::DisplayRole) {
|
||||
return DocumentModel::tr("Application");
|
||||
}
|
||||
~DocumentIndex() override
|
||||
{
|
||||
qDeleteAll(childItems);
|
||||
childItems.clear();
|
||||
}
|
||||
ViewProviderIndex* cloneViewProvider(const ViewProviderDocumentObject&) const;
|
||||
int rowOfViewProvider(const ViewProviderDocumentObject&) const;
|
||||
void findViewProviders(const ViewProviderDocumentObject&, QList<ViewProviderIndex*>&) const;
|
||||
QVariant data(int role) const override;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Object nodes
|
||||
class ViewProviderIndex: public DocumentModelIndex
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
const Gui::ViewProviderDocumentObject& v;
|
||||
ViewProviderIndex(const Gui::ViewProviderDocumentObject& v, DocumentIndex* d);
|
||||
~ViewProviderIndex() override;
|
||||
ViewProviderIndex* clone() const;
|
||||
void findViewProviders(const ViewProviderDocumentObject&, QList<ViewProviderIndex*>&) const;
|
||||
QVariant data(int role) const override;
|
||||
|
||||
private:
|
||||
DocumentIndex* d;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
int ApplicationIndex::findChild(const Gui::Document& d) const
|
||||
{
|
||||
int child = 0;
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it, ++child) {
|
||||
auto doc = static_cast<DocumentIndex*>(*it);
|
||||
if (&doc->d == &d) {
|
||||
return child;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
return -1;
|
||||
}
|
||||
|
||||
QIcon* DocumentIndex::documentIcon = nullptr;
|
||||
Qt::ItemFlags ApplicationIndex::flags() const
|
||||
{
|
||||
return Qt::ItemIsEnabled;
|
||||
}
|
||||
|
||||
void DocumentIndex::addToDocument(ViewProviderIndex* vp)
|
||||
{
|
||||
vp_nodes[&vp->v].insert(vp);
|
||||
QVariant ApplicationIndex::data(int role) const
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return qApp->windowIcon();
|
||||
}
|
||||
|
||||
void DocumentIndex::removeFromDocument(ViewProviderIndex* vp)
|
||||
{
|
||||
vp_nodes[&vp->v].erase(vp);
|
||||
else if (role == Qt::DisplayRole) {
|
||||
return DocumentModel::tr("Application");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ViewProviderIndex*
|
||||
DocumentIndex::cloneViewProvider(const ViewProviderDocumentObject& vp) const
|
||||
{
|
||||
std::map<const ViewProviderDocumentObject*, boost::unordered_set<ViewProviderIndex*> >::const_iterator it;
|
||||
it = vp_nodes.find(&vp);
|
||||
if (it != vp_nodes.end()) {
|
||||
boost::unordered_set<ViewProviderIndex*>::const_iterator v;
|
||||
if (!it->second.empty()) {
|
||||
v = it->second.begin();
|
||||
if (*v)
|
||||
return (*v)->clone();
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
QIcon* DocumentIndex::documentIcon = nullptr;
|
||||
|
||||
void DocumentIndex::addToDocument(ViewProviderIndex* vp)
|
||||
{
|
||||
vp_nodes[&vp->v].insert(vp);
|
||||
}
|
||||
|
||||
void DocumentIndex::removeFromDocument(ViewProviderIndex* vp)
|
||||
{
|
||||
vp_nodes[&vp->v].erase(vp);
|
||||
}
|
||||
|
||||
ViewProviderIndex* DocumentIndex::cloneViewProvider(const ViewProviderDocumentObject& vp) const
|
||||
{
|
||||
std::map<const ViewProviderDocumentObject*, boost::unordered_set<ViewProviderIndex*>>::const_iterator it;
|
||||
it = vp_nodes.find(&vp);
|
||||
if (it != vp_nodes.end()) {
|
||||
boost::unordered_set<ViewProviderIndex*>::const_iterator v;
|
||||
if (!it->second.empty()) {
|
||||
v = it->second.begin();
|
||||
if (*v) {
|
||||
return (*v)->clone();
|
||||
}
|
||||
}
|
||||
return new ViewProviderIndex(vp, const_cast<DocumentIndex*>(this));
|
||||
}
|
||||
|
||||
void DocumentIndex::findViewProviders(const ViewProviderDocumentObject& vp,
|
||||
QList<ViewProviderIndex*>& index) const
|
||||
{
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it) {
|
||||
auto v = static_cast<ViewProviderIndex*>(*it);
|
||||
v->findViewProviders(vp, index);
|
||||
}
|
||||
}
|
||||
|
||||
int DocumentIndex::rowOfViewProvider(const ViewProviderDocumentObject& vp) const
|
||||
{
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
int index=0;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it, ++index) {
|
||||
auto v = static_cast<ViewProviderIndex*>(*it);
|
||||
if (&v->v == &vp)
|
||||
return index;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
QVariant DocumentIndex::data(int role) const
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return *documentIcon;
|
||||
}
|
||||
else if (role == Qt::DisplayRole) {
|
||||
App::Document* doc = d.getDocument();
|
||||
return QString::fromUtf8(doc->Label.getValue());
|
||||
}
|
||||
else if (role == Qt::FontRole) {
|
||||
Document* doc = Application::Instance->activeDocument();
|
||||
QFont font;
|
||||
font.setBold(doc==&d);
|
||||
return static_cast<QVariant>(font);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
ViewProviderIndex::ViewProviderIndex(const Gui::ViewProviderDocumentObject& v, DocumentIndex* d)
|
||||
: v(v),d(d)
|
||||
{
|
||||
if (d) d->addToDocument(this);
|
||||
}
|
||||
|
||||
ViewProviderIndex::~ViewProviderIndex()
|
||||
{
|
||||
if (d) d->removeFromDocument(this);
|
||||
}
|
||||
|
||||
ViewProviderIndex* ViewProviderIndex::clone() const
|
||||
{
|
||||
auto copy = new ViewProviderIndex(this->v, this->d);
|
||||
for (const auto & childItem : childItems) {
|
||||
ViewProviderIndex* c = static_cast<ViewProviderIndex*>(childItem)->clone();
|
||||
copy->appendChild(c);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
void ViewProviderIndex::findViewProviders(const ViewProviderDocumentObject& vp,
|
||||
QList<ViewProviderIndex*>& index) const
|
||||
{
|
||||
if (&this->v == &vp)
|
||||
index.push_back(const_cast<ViewProviderIndex*>(this));
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it) {
|
||||
auto v = static_cast<ViewProviderIndex*>(*it);
|
||||
v->findViewProviders(vp, index);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ViewProviderIndex::data(int role) const
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return v.getIcon();
|
||||
}
|
||||
else if (role == Qt::DisplayRole) {
|
||||
App::DocumentObject* obj = v.getObject();
|
||||
return QString::fromUtf8(obj->Label.getValue());
|
||||
}
|
||||
else if (role == Qt::FontRole) {
|
||||
App::DocumentObject* obj = v.getObject();
|
||||
App::DocumentObject* act = obj->getDocument()->getActiveObject();
|
||||
QFont font;
|
||||
font.setBold(obj==act);
|
||||
return static_cast<QVariant>(font);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::DocumentModelIndex, Base::BaseClass)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::ApplicationIndex,Gui::DocumentModelIndex)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::DocumentIndex, Gui::DocumentModelIndex)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::ViewProviderIndex, Gui::DocumentModelIndex)
|
||||
|
||||
struct DocumentModelP
|
||||
{
|
||||
DocumentModelP()
|
||||
{ rootItem = new ApplicationIndex(); }
|
||||
~DocumentModelP()
|
||||
{ delete rootItem; }
|
||||
ApplicationIndex *rootItem;
|
||||
};
|
||||
return new ViewProviderIndex(vp, const_cast<DocumentIndex*>(this));
|
||||
}
|
||||
|
||||
void DocumentIndex::findViewProviders(
|
||||
const ViewProviderDocumentObject& vp,
|
||||
QList<ViewProviderIndex*>& index
|
||||
) const
|
||||
{
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it) {
|
||||
auto v = static_cast<ViewProviderIndex*>(*it);
|
||||
v->findViewProviders(vp, index);
|
||||
}
|
||||
}
|
||||
|
||||
int DocumentIndex::rowOfViewProvider(const ViewProviderDocumentObject& vp) const
|
||||
{
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
int index = 0;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it, ++index) {
|
||||
auto v = static_cast<ViewProviderIndex*>(*it);
|
||||
if (&v->v == &vp) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
QVariant DocumentIndex::data(int role) const
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return *documentIcon;
|
||||
}
|
||||
else if (role == Qt::DisplayRole) {
|
||||
App::Document* doc = d.getDocument();
|
||||
return QString::fromUtf8(doc->Label.getValue());
|
||||
}
|
||||
else if (role == Qt::FontRole) {
|
||||
Document* doc = Application::Instance->activeDocument();
|
||||
QFont font;
|
||||
font.setBold(doc == &d);
|
||||
return static_cast<QVariant>(font);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
ViewProviderIndex::ViewProviderIndex(const Gui::ViewProviderDocumentObject& v, DocumentIndex* d)
|
||||
: v(v)
|
||||
, d(d)
|
||||
{
|
||||
if (d) {
|
||||
d->addToDocument(this);
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderIndex::~ViewProviderIndex()
|
||||
{
|
||||
if (d) {
|
||||
d->removeFromDocument(this);
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderIndex* ViewProviderIndex::clone() const
|
||||
{
|
||||
auto copy = new ViewProviderIndex(this->v, this->d);
|
||||
for (const auto& childItem : childItems) {
|
||||
ViewProviderIndex* c = static_cast<ViewProviderIndex*>(childItem)->clone();
|
||||
copy->appendChild(c);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
void ViewProviderIndex::findViewProviders(
|
||||
const ViewProviderDocumentObject& vp,
|
||||
QList<ViewProviderIndex*>& index
|
||||
) const
|
||||
{
|
||||
if (&this->v == &vp) {
|
||||
index.push_back(const_cast<ViewProviderIndex*>(this));
|
||||
}
|
||||
QList<DocumentModelIndex*>::const_iterator it;
|
||||
for (it = childItems.begin(); it != childItems.end(); ++it) {
|
||||
auto v = static_cast<ViewProviderIndex*>(*it);
|
||||
v->findViewProviders(vp, index);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ViewProviderIndex::data(int role) const
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
return v.getIcon();
|
||||
}
|
||||
else if (role == Qt::DisplayRole) {
|
||||
App::DocumentObject* obj = v.getObject();
|
||||
return QString::fromUtf8(obj->Label.getValue());
|
||||
}
|
||||
else if (role == Qt::FontRole) {
|
||||
App::DocumentObject* obj = v.getObject();
|
||||
App::DocumentObject* act = obj->getDocument()->getActiveObject();
|
||||
QFont font;
|
||||
font.setBold(obj == act);
|
||||
return static_cast<QVariant>(font);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::DocumentModelIndex, Base::BaseClass)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::ApplicationIndex, Gui::DocumentModelIndex)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::DocumentIndex, Gui::DocumentModelIndex)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Gui::ViewProviderIndex, Gui::DocumentModelIndex)
|
||||
|
||||
struct DocumentModelP
|
||||
{
|
||||
DocumentModelP()
|
||||
{
|
||||
rootItem = new ApplicationIndex();
|
||||
}
|
||||
~DocumentModelP()
|
||||
{
|
||||
delete rootItem;
|
||||
}
|
||||
ApplicationIndex* rootItem;
|
||||
};
|
||||
} // namespace Gui
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
DocumentModel::DocumentModel(QObject* parent)
|
||||
: QAbstractItemModel(parent), d(new DocumentModelP)
|
||||
: QAbstractItemModel(parent)
|
||||
, d(new DocumentModelP)
|
||||
{
|
||||
static bool inittype = false;
|
||||
if (!inittype) {
|
||||
inittype = true;
|
||||
DocumentModelIndex ::init();
|
||||
ApplicationIndex ::init();
|
||||
DocumentIndex ::init();
|
||||
ViewProviderIndex ::init();
|
||||
DocumentModelIndex ::init();
|
||||
ApplicationIndex ::init();
|
||||
DocumentIndex ::init();
|
||||
ViewProviderIndex ::init();
|
||||
}
|
||||
|
||||
//NOLINTBEGIN
|
||||
// Setup connections
|
||||
Application::Instance->signalNewDocument.connect(std::bind(&DocumentModel::slotNewDocument, this, sp::_1));
|
||||
Application::Instance->signalDeleteDocument.connect(std::bind(&DocumentModel::slotDeleteDocument, this, sp::_1));
|
||||
Application::Instance->signalRenameDocument.connect(std::bind(&DocumentModel::slotRenameDocument, this, sp::_1));
|
||||
Application::Instance->signalActiveDocument.connect(std::bind(&DocumentModel::slotActiveDocument, this, sp::_1));
|
||||
Application::Instance->signalRelabelDocument.connect(std::bind(&DocumentModel::slotRelabelDocument, this, sp::_1));
|
||||
//NOLINTEND
|
||||
// NOLINTBEGIN
|
||||
// Setup connections
|
||||
Application::Instance->signalNewDocument.connect(
|
||||
std::bind(&DocumentModel::slotNewDocument, this, sp::_1)
|
||||
);
|
||||
Application::Instance->signalDeleteDocument.connect(
|
||||
std::bind(&DocumentModel::slotDeleteDocument, this, sp::_1)
|
||||
);
|
||||
Application::Instance->signalRenameDocument.connect(
|
||||
std::bind(&DocumentModel::slotRenameDocument, this, sp::_1)
|
||||
);
|
||||
Application::Instance->signalActiveDocument.connect(
|
||||
std::bind(&DocumentModel::slotActiveDocument, this, sp::_1)
|
||||
);
|
||||
Application::Instance->signalRelabelDocument.connect(
|
||||
std::bind(&DocumentModel::slotRelabelDocument, this, sp::_1)
|
||||
);
|
||||
// NOLINTEND
|
||||
}
|
||||
|
||||
DocumentModel::~DocumentModel()
|
||||
{
|
||||
delete d; d = nullptr;
|
||||
delete d;
|
||||
d = nullptr;
|
||||
}
|
||||
|
||||
void DocumentModel::slotNewDocument(const Gui::Document& Doc)
|
||||
{
|
||||
//NOLINTBEGIN
|
||||
// NOLINTBEGIN
|
||||
Doc.signalNewObject.connect(std::bind(&DocumentModel::slotNewObject, this, sp::_1));
|
||||
Doc.signalDeletedObject.connect(std::bind(&DocumentModel::slotDeleteObject, this, sp::_1));
|
||||
Doc.signalChangedObject.connect(std::bind(&DocumentModel::slotChangeObject, this, sp::_1, sp::_2));
|
||||
@@ -381,9 +431,9 @@ void DocumentModel::slotNewDocument(const Gui::Document& Doc)
|
||||
Doc.signalActivatedObject.connect(std::bind(&DocumentModel::slotActiveObject, this, sp::_1));
|
||||
Doc.signalInEdit.connect(std::bind(&DocumentModel::slotInEdit, this, sp::_1));
|
||||
Doc.signalResetEdit.connect(std::bind(&DocumentModel::slotResetEdit, this, sp::_1));
|
||||
//NOLINTEND
|
||||
// NOLINTEND
|
||||
|
||||
QModelIndex parent = createIndex(0,0,d->rootItem);
|
||||
QModelIndex parent = createIndex(0, 0, d->rootItem);
|
||||
int count_docs = d->rootItem->childCount();
|
||||
beginInsertRows(parent, count_docs, count_docs);
|
||||
d->rootItem->appendChild(new DocumentIndex(Doc));
|
||||
@@ -394,7 +444,7 @@ void DocumentModel::slotDeleteDocument(const Gui::Document& Doc)
|
||||
{
|
||||
int row = d->rootItem->findChild(Doc);
|
||||
if (row > -1) {
|
||||
QModelIndex parent = createIndex(0,0,d->rootItem);
|
||||
QModelIndex parent = createIndex(0, 0, d->rootItem);
|
||||
beginRemoveRows(parent, row, row);
|
||||
DocumentModelIndex* item = d->rootItem->child(row);
|
||||
d->rootItem->removeChild(row);
|
||||
@@ -413,8 +463,8 @@ void DocumentModel::slotRelabelDocument(const Gui::Document& Doc)
|
||||
{
|
||||
int row = d->rootItem->findChild(Doc);
|
||||
if (row > -1) {
|
||||
QModelIndex parent = createIndex(0,0,d->rootItem);
|
||||
QModelIndex item = index (row, 0, parent);
|
||||
QModelIndex parent = createIndex(0, 0, d->rootItem);
|
||||
QModelIndex item = index(row, 0, parent);
|
||||
Q_EMIT dataChanged(item, item);
|
||||
}
|
||||
}
|
||||
@@ -422,9 +472,9 @@ void DocumentModel::slotRelabelDocument(const Gui::Document& Doc)
|
||||
void DocumentModel::slotActiveDocument(const Gui::Document& /*Doc*/)
|
||||
{
|
||||
// don't know which was the previous active document, so check simply all
|
||||
QModelIndex parent = createIndex(0,0,d->rootItem);
|
||||
QModelIndex top = index (0, 0, parent);
|
||||
QModelIndex bottom = index (d->rootItem->childCount()-1, 0, parent);
|
||||
QModelIndex parent = createIndex(0, 0, d->rootItem);
|
||||
QModelIndex top = index(0, 0, parent);
|
||||
QModelIndex bottom = index(d->rootItem->childCount() - 1, 0, parent);
|
||||
Q_EMIT dataChanged(top, bottom);
|
||||
}
|
||||
|
||||
@@ -445,7 +495,7 @@ void DocumentModel::slotNewObject(const Gui::ViewProviderDocumentObject& obj)
|
||||
int row = d->rootItem->findChild(*gdc);
|
||||
if (row > -1) {
|
||||
auto index = static_cast<DocumentIndex*>(d->rootItem->child(row));
|
||||
QModelIndex parent = createIndex(index->row(),0,index);
|
||||
QModelIndex parent = createIndex(index->row(), 0, index);
|
||||
int count_obj = index->childCount();
|
||||
beginInsertRows(parent, count_obj, count_obj);
|
||||
index->appendChild(new ViewProviderIndex(obj, index));
|
||||
@@ -462,7 +512,7 @@ void DocumentModel::slotDeleteObject(const Gui::ViewProviderDocumentObject& obj)
|
||||
auto doc_index = static_cast<DocumentIndex*>(d->rootItem->child(row));
|
||||
QList<ViewProviderIndex*> views;
|
||||
doc_index->findViewProviders(obj, views);
|
||||
for (auto & view : views) {
|
||||
for (auto& view : views) {
|
||||
DocumentModelIndex* parentitem = view->parent();
|
||||
QModelIndex parent = createIndex(doc_index->row(), 0, parentitem);
|
||||
int row = view->row();
|
||||
@@ -485,11 +535,11 @@ void DocumentModel::slotChangeObject(const Gui::ViewProviderDocumentObject& obj,
|
||||
auto doc_index = static_cast<DocumentIndex*>(d->rootItem->child(row));
|
||||
QList<ViewProviderIndex*> views;
|
||||
doc_index->findViewProviders(obj, views);
|
||||
for (const auto & view : std::as_const(views)) {
|
||||
for (const auto& view : std::as_const(views)) {
|
||||
DocumentModelIndex* parentitem = view->parent();
|
||||
QModelIndex parent = createIndex(0,0,parentitem);
|
||||
QModelIndex parent = createIndex(0, 0, parentitem);
|
||||
int row = view->row();
|
||||
QModelIndex item = index (row, 0, parent);
|
||||
QModelIndex item = index(row, 0, parent);
|
||||
Q_EMIT dataChanged(item, item);
|
||||
}
|
||||
}
|
||||
@@ -503,7 +553,7 @@ void DocumentModel::slotChangeObject(const Gui::ViewProviderDocumentObject& obj,
|
||||
if (row > -1) {
|
||||
QList<DocumentModelIndex*> del_items;
|
||||
auto doc_index = static_cast<DocumentIndex*>(d->rootItem->child(row));
|
||||
for (const auto & view : views) {
|
||||
for (const auto& view : views) {
|
||||
int row = doc_index->rowOfViewProvider(*view);
|
||||
// is it a top-level child in the document
|
||||
if (row >= 0) {
|
||||
@@ -519,8 +569,8 @@ void DocumentModel::slotChangeObject(const Gui::ViewProviderDocumentObject& obj,
|
||||
// get all occurrences of the view provider in the tree structure
|
||||
QList<ViewProviderIndex*> obj_index;
|
||||
doc_index->findViewProviders(obj, obj_index);
|
||||
for (const auto & it : std::as_const(obj_index)) {
|
||||
QModelIndex parent = createIndex(it->row(),0,it);
|
||||
for (const auto& it : std::as_const(obj_index)) {
|
||||
QModelIndex parent = createIndex(it->row(), 0, it);
|
||||
int count_obj = it->childCount();
|
||||
beginRemoveRows(parent, 0, count_obj);
|
||||
// remove all children but do not yet delete them
|
||||
@@ -528,7 +578,7 @@ void DocumentModel::slotChangeObject(const Gui::ViewProviderDocumentObject& obj,
|
||||
endRemoveRows();
|
||||
|
||||
beginInsertRows(parent, 0, (int)views.size());
|
||||
for (const auto & view : views) {
|
||||
for (const auto& view : views) {
|
||||
ViewProviderIndex* clone = doc_index->cloneViewProvider(*view);
|
||||
it->appendChild(clone);
|
||||
}
|
||||
@@ -557,8 +607,9 @@ void DocumentModel::slotActiveObject(const Gui::ViewProviderDocumentObject& obj)
|
||||
|
||||
const Document* DocumentModel::getDocument(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
if (!index.isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
Base::BaseClass* item = nullptr;
|
||||
item = static_cast<Base::BaseClass*>(index.internalPointer());
|
||||
if (item->is<DocumentIndex>()) {
|
||||
@@ -571,99 +622,110 @@ const Document* DocumentModel::getDocument(const QModelIndex& index) const
|
||||
|
||||
bool DocumentModel::isPropertyLink(const App::Property& prop) const
|
||||
{
|
||||
return prop.isDerivedFrom<App::PropertyLink>()
|
||||
|| prop.isDerivedFrom<App::PropertyLinkSub>()
|
||||
|| prop.isDerivedFrom<App::PropertyLinkList>()
|
||||
|| prop.isDerivedFrom<App::PropertyLinkSubList>();
|
||||
return prop.isDerivedFrom<App::PropertyLink>() || prop.isDerivedFrom<App::PropertyLinkSub>()
|
||||
|| prop.isDerivedFrom<App::PropertyLinkList>()
|
||||
|| prop.isDerivedFrom<App::PropertyLinkSubList>();
|
||||
}
|
||||
|
||||
std::vector<ViewProviderDocumentObject*>
|
||||
DocumentModel::claimChildren(const Gui::Document& doc, const ViewProviderDocumentObject& obj) const
|
||||
std::vector<ViewProviderDocumentObject*> DocumentModel::claimChildren(
|
||||
const Gui::Document& doc,
|
||||
const ViewProviderDocumentObject& obj
|
||||
) const
|
||||
{
|
||||
std::vector<ViewProviderDocumentObject*> views;
|
||||
std::vector<App::DocumentObject*> childs = obj.claimChildren();
|
||||
for (const auto & child : childs) {
|
||||
for (const auto& child : childs) {
|
||||
ViewProvider* view = doc.getViewProvider(child);
|
||||
if (view && view->isDerivedFrom<ViewProviderDocumentObject>())
|
||||
if (view && view->isDerivedFrom<ViewProviderDocumentObject>()) {
|
||||
views.push_back(static_cast<ViewProviderDocumentObject*>(view));
|
||||
}
|
||||
}
|
||||
|
||||
return views;
|
||||
}
|
||||
|
||||
int DocumentModel::columnCount (const QModelIndex & /*parent*/) const
|
||||
int DocumentModel::columnCount(const QModelIndex& /*parent*/) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant DocumentModel::data (const QModelIndex & index, int role) const
|
||||
QVariant DocumentModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
if (!index.isValid()) {
|
||||
return {};
|
||||
}
|
||||
return static_cast<DocumentModelIndex*>(index.internalPointer())->data(role);
|
||||
}
|
||||
|
||||
bool DocumentModel::setData(const QModelIndex& index, const QVariant & value, int role)
|
||||
bool DocumentModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if (!index.isValid())
|
||||
if (!index.isValid()) {
|
||||
return false;
|
||||
}
|
||||
return static_cast<DocumentModelIndex*>(index.internalPointer())->setData(value, role);
|
||||
}
|
||||
|
||||
Qt::ItemFlags DocumentModel::flags(const QModelIndex &index) const
|
||||
Qt::ItemFlags DocumentModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
//if (index.internalPointer() == d->rootItem)
|
||||
// return Qt::ItemIsEnabled;
|
||||
//return QAbstractItemModel::flags(index);
|
||||
if (!index.isValid())
|
||||
// if (index.internalPointer() == d->rootItem)
|
||||
// return Qt::ItemIsEnabled;
|
||||
// return QAbstractItemModel::flags(index);
|
||||
if (!index.isValid()) {
|
||||
return {};
|
||||
}
|
||||
return static_cast<DocumentModelIndex*>(index.internalPointer())->flags();
|
||||
}
|
||||
|
||||
QModelIndex DocumentModel::index (int row, int column, const QModelIndex & parent) const
|
||||
QModelIndex DocumentModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
DocumentModelIndex* item = nullptr;
|
||||
if (!parent.isValid())
|
||||
if (!parent.isValid()) {
|
||||
item = d->rootItem;
|
||||
else
|
||||
}
|
||||
else {
|
||||
item = static_cast<DocumentModelIndex*>(parent.internalPointer())->child(row);
|
||||
if (!item)
|
||||
}
|
||||
if (!item) {
|
||||
return {};
|
||||
}
|
||||
return createIndex(row, column, item);
|
||||
}
|
||||
|
||||
QModelIndex DocumentModel::parent (const QModelIndex & index) const
|
||||
QModelIndex DocumentModel::parent(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid() || index.internalPointer() == d->rootItem)
|
||||
if (!index.isValid() || index.internalPointer() == d->rootItem) {
|
||||
return {};
|
||||
}
|
||||
DocumentModelIndex* item = nullptr;
|
||||
item = static_cast<DocumentModelIndex*>(index.internalPointer());
|
||||
DocumentModelIndex* parent = item->parent();
|
||||
return createIndex(parent->row(), 0, parent);
|
||||
}
|
||||
|
||||
int DocumentModel::rowCount (const QModelIndex & parent) const
|
||||
int DocumentModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (!parent.isValid())
|
||||
return 1; // the root item
|
||||
if (!parent.isValid()) {
|
||||
return 1; // the root item
|
||||
}
|
||||
DocumentModelIndex* item = nullptr;
|
||||
item = static_cast<DocumentModelIndex*>(parent.internalPointer());
|
||||
return item->childCount();
|
||||
}
|
||||
|
||||
QVariant DocumentModel::headerData (int section, Qt::Orientation orientation, int role) const
|
||||
QVariant DocumentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
Q_UNUSED(section);
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role != Qt::DisplayRole)
|
||||
if (role != Qt::DisplayRole) {
|
||||
return {};
|
||||
}
|
||||
return tr("Labels & Attributes");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool DocumentModel::setHeaderData (int, Qt::Orientation, const QVariant &, int)
|
||||
bool DocumentModel::setHeaderData(int, Qt::Orientation, const QVariant&, int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user