visualization: qt4 support for signal connections

This commit is contained in:
v4hn 2017-11-12 12:27:35 +01:00
parent 481e2c4f12
commit 2ad6e1d622
4 changed files with 43 additions and 9 deletions

View File

@ -144,6 +144,8 @@ public:
} }
private: private:
void _q_sourceDestroyed(QObject* object);
void _q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end); void _q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
void _q_sourceRowsInserted(const QModelIndex &parent, int start, int end); void _q_sourceRowsInserted(const QModelIndex &parent, int start, int end);
void _q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); void _q_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
@ -151,7 +153,11 @@ private:
void _q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); void _q_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
void _q_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); void _q_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest);
#if Q_VERSION < 0x050000
void _q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
#else
void _q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); void _q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
#endif
}; };
@ -325,8 +331,9 @@ void TaskListModel::insertTask(BaseTaskModel* model, int row) {
// notice destruction of task // notice destruction of task
if (model->parent() != this) if (model->parent() != this)
connect(model, &BaseTaskModel::destroyed, connect(model, SIGNAL(destroyed(QObject*)),
[this](QObject* o) { removeTask(static_cast<BaseTaskModel*>(o), false); }); this, SLOT(_q_sourceDestroyed(QObject*)));
connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int))); this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
@ -340,8 +347,13 @@ void TaskListModel::insertTask(BaseTaskModel* model, int row) {
this, SLOT(_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); this, SLOT(_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
this, SLOT(_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))); this, SLOT(_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
#if Q_VERSION < 0x050000
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
#else
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>))); this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
#endif
} }
bool TaskListModel::removeTask(BaseTaskModel* model, bool disconnect_signals) { bool TaskListModel::removeTask(BaseTaskModel* model, bool disconnect_signals) {
@ -372,12 +384,21 @@ bool TaskListModel::removeTask(BaseTaskModel* model, bool disconnect_signals) {
this, SLOT(_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); this, SLOT(_q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
disconnect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), disconnect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
this, SLOT(_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))); this, SLOT(_q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
#if Q_VERSION < 0x050000
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
#else
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>))); this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
#endif
} }
return true; return true;
} }
void TaskListModelPrivate::_q_sourceDestroyed(QObject* o){
q_ptr->removeTask(static_cast<BaseTaskModel*>(o), false);
}
void TaskListModelPrivate::_q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) void TaskListModelPrivate::_q_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
{ {
q_ptr->beginInsertRows(mapFromSource(parent), start, end); q_ptr->beginInsertRows(mapFromSource(parent), start, end);
@ -419,10 +440,17 @@ void TaskListModelPrivate::_q_sourceRowsRemoved(const QModelIndex &parent, int s
q_ptr->endRemoveRows(); q_ptr->endRemoveRows();
} }
#if Q_VERSION < 0x050000
void TaskListModelPrivate::_q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
q_ptr->dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight));
}
#else
void TaskListModelPrivate::_q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) void TaskListModelPrivate::_q_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{ {
q_ptr->dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight), roles); q_ptr->dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight), roles);
} }
#endif
} }

View File

@ -102,6 +102,8 @@ public:
bool removeTask(BaseTaskModel* model, bool disconnect_signals = true); bool removeTask(BaseTaskModel* model, bool disconnect_signals = true);
private: private:
Q_PRIVATE_SLOT(d_func(), void _q_sourceDestroyed(QObject*))
Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeInserted(QModelIndex,int,int)) Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeInserted(QModelIndex,int,int))
Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsInserted(QModelIndex,int,int)) Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsInserted(QModelIndex,int,int))
Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)) Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeRemoved(QModelIndex,int,int))
@ -109,7 +111,11 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))
Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)) Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))
#if Q_VERSION < 0x050000
Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(QModelIndex,QModelIndex))
#else
Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)) Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>))
#endif
}; };
MOVEIT_CLASS_FORWARD(TaskListModel) MOVEIT_CLASS_FORWARD(TaskListModel)
typedef std::weak_ptr<TaskListModel> TaskListModelWeakPtr; typedef std::weak_ptr<TaskListModel> TaskListModelWeakPtr;

View File

@ -64,10 +64,10 @@ TaskListModelPtr TaskListModelCache::getModel(const QString &task_monitor_topic,
model = result = TaskListModelPtr(new TaskListModel()); model = result = TaskListModelPtr(new TaskListModel());
// connect newly created TaskListModel to global model // connect newly created TaskListModel to global model
connect(result.get(), &TaskListModel::rowsInserted, connect(result.get(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, &TaskListModelCache::onInsertTasks); this, SLOT(onInsertTasks(QModelIndex,int,int)));
connect(result.get(), &TaskListModel::rowsAboutToBeRemoved, connect(result.get(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
this, &TaskListModelCache::onRemoveTasks); this, SLOT(onRemoveTasks(QModelIndex,int,int)));
} else } else
result = model.lock(); result = model.lock();

View File

@ -81,9 +81,9 @@ TaskPanel::TaskPanel(QWidget* parent)
{ {
Q_D(TaskPanel); Q_D(TaskPanel);
// connect signals // connect signals
connect(d->actionNewTask, &QAction::triggered, this, &TaskPanel::onAddTask); connect(d->actionNewTask, SIGNAL(triggered()), this, SLOT(onAddTask()));
connect(d->actionNewStage, &QAction::triggered, this, &TaskPanel::onAddStage); connect(d->actionNewStage, SIGNAL(triggered()), this, SLOT(onAddStage()));
connect(d->actionRemoveStages, &QAction::triggered, this, &TaskPanel::onRemoveStages); connect(d->actionRemoveStages, SIGNAL(triggered()), this, SLOT(onRemoveStages()));
} }
TaskPanel::~TaskPanel() TaskPanel::~TaskPanel()