correctly pass on StageFactory

This commit is contained in:
Robert Haschke 2018-02-04 17:10:07 +01:00
parent 17683b12c9
commit 32660670a7
3 changed files with 13 additions and 11 deletions

View File

@ -68,7 +68,7 @@ public:
bool removeRows(int row, int count, const QModelIndex &parent) override;
/// providing a StageFactory makes the model accepting drops
void setStageFactory(const StageFactoryPtr &factory);
void setStageFactory(const StageFactoryPtr &factory) override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
QAbstractItemModel* getSolutionModel(const QModelIndex& index) override;

View File

@ -113,12 +113,13 @@ Qt::ItemFlags BaseTaskModel::flags(const QModelIndex &index) const
StageFactoryPtr getStageFactory()
{
static std::weak_ptr<StageFactory> factory;
if (!factory.expired())
return factory.lock();
StageFactoryPtr result = factory.lock();
if (result)
return result;
try {
StageFactoryPtr result(new StageFactory("moveit_task_constructor_core",
"moveit::task_constructor::Stage"));
result.reset(new StageFactory("moveit_task_constructor_core",
"moveit::task_constructor::Stage"));
// Hm. pluglinlib / ClassLoader cannot instantiate classes in implicitly loaded libs
result->addBuiltInClass<moveit::task_constructor::SerialContainer>("Serial Container", "");
factory = result; // remember for future uses
@ -285,7 +286,6 @@ bool TaskListModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, i
// create a new local task using the given container as root
auto *m = new LocalTaskModel(std::move(container), this);
m->setStageFactory(stage_factory_);
insertModel(m, row);
return true;
}

View File

@ -55,6 +55,10 @@ namespace moveit_rviz_plugin {
MOVEIT_CLASS_FORWARD(DisplaySolution)
MOVEIT_CLASS_FORWARD(RemoteTaskModel)
typedef PluginlibFactory<moveit::task_constructor::Stage> StageFactory;
typedef std::shared_ptr<StageFactory> StageFactoryPtr;
StageFactoryPtr getStageFactory();
/** Base class to represent a single local or remote Task as a Qt model. */
class BaseTaskModel : public QAbstractItemModel {
@ -76,6 +80,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QVariant data(const QModelIndex &index, int role) const override;
virtual void setStageFactory(const StageFactoryPtr &factory) {}
Qt::ItemFlags flags(const QModelIndex &index) const override;
unsigned int taskFlags() const { return flags_; }
@ -84,11 +89,6 @@ public:
};
typedef PluginlibFactory<moveit::task_constructor::Stage> StageFactory;
typedef std::shared_ptr<StageFactory> StageFactoryPtr;
StageFactoryPtr getStageFactory();
/** The TaskListModel maintains a list of multiple BaseTaskModels, local and/or remote.
*
* Each TaskDisplay owns a TaskListModel to maintain the list of tasks published on
@ -135,6 +135,8 @@ public:
/// insert a TaskModel, pos is relative to modelCount()
inline bool insertModel(BaseTaskModel* model, int pos = -1) {
Q_ASSERT(model && model->columnCount() == columnCount());
// pass on stage factory
model->setStageFactory(stage_factory_);
// just wrap the base class method to further constrain the model type
return FlatMergeProxyModel::insertModel(model, pos);
}