mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Changed the way change hilight of three cells works to bring down the
number of QTimer instances and the number of redraws to hopefully increase performance. Changed so that when a child gets hilighted it will hilight its parent.
This commit is contained in:
parent
c1689b2205
commit
d03282d9b0
@ -27,6 +27,45 @@
|
||||
|
||||
#include "treeitem.h"
|
||||
|
||||
HighLightManager::HighLightManager(long checkingInterval)
|
||||
{
|
||||
m_expirationTimer.start(checkingInterval);
|
||||
connect(&m_expirationTimer, SIGNAL(timeout()), this, SLOT(checkItemsExpired()));
|
||||
}
|
||||
|
||||
bool HighLightManager::add(TreeItem *itemToAdd)
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
if(!m_itemsList.contains(itemToAdd))
|
||||
{
|
||||
m_itemsList.append(itemToAdd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HighLightManager::remove(TreeItem *itemToRemove)
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
return m_itemsList.removeOne(itemToRemove);
|
||||
}
|
||||
|
||||
void HighLightManager::checkItemsExpired()
|
||||
{
|
||||
QMutexLocker locker(&m_listMutex);
|
||||
QMutableLinkedListIterator<TreeItem*> iter(m_itemsList);
|
||||
QTime now = QTime::currentTime();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
TreeItem* item = iter.next();
|
||||
if(item->getHiglightExpires() < now)
|
||||
{
|
||||
item->removeHighlight();
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TreeItem::m_highlightTimeMs = 500;
|
||||
|
||||
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
|
||||
@ -36,7 +75,6 @@ TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
|
||||
m_highlight(false),
|
||||
m_changed(false)
|
||||
{
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
||||
}
|
||||
|
||||
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
|
||||
@ -46,7 +84,6 @@ TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
|
||||
m_changed(false)
|
||||
{
|
||||
m_data << data << "" << "";
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
||||
}
|
||||
|
||||
TreeItem::~TreeItem()
|
||||
@ -112,17 +149,34 @@ void TreeItem::setHighlight(bool highlight) {
|
||||
m_highlight = highlight;
|
||||
m_changed = false;
|
||||
if (highlight) {
|
||||
if (m_timer.isActive()) {
|
||||
m_timer.stop();
|
||||
m_highlightExpires = QTime::currentTime().addMSecs(m_highlightTimeMs);
|
||||
if(m_highlightManager->add(this))
|
||||
{
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
m_timer.setSingleShot(true);
|
||||
m_timer.start(m_highlightTimeMs);
|
||||
}
|
||||
emit updateHighlight(this);
|
||||
else if(m_highlightManager->remove(this))
|
||||
{
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
if(m_parent)
|
||||
{
|
||||
m_parent->setHighlight(highlight);
|
||||
}
|
||||
}
|
||||
|
||||
void TreeItem::removeHighlight() {
|
||||
m_highlight = false;
|
||||
update();
|
||||
//update();
|
||||
emit updateHighlight(this);
|
||||
}
|
||||
|
||||
void TreeItem::setHighlightManager(HighLightManager *mgr)
|
||||
{
|
||||
m_highlightManager = mgr;
|
||||
}
|
||||
|
||||
QTime TreeItem::getHiglightExpires()
|
||||
{
|
||||
return m_highlightExpires;
|
||||
}
|
||||
|
@ -32,10 +32,31 @@
|
||||
#include "uavmetaobject.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QLinkedList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QTCore/QTime>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
class TreeItem;
|
||||
|
||||
class HighLightManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HighLightManager(long checkingInterval);
|
||||
bool add(TreeItem* itemToAdd);
|
||||
bool remove(TreeItem* itemToRemove);
|
||||
|
||||
private slots:
|
||||
void checkItemsExpired();
|
||||
|
||||
private:
|
||||
QTimer m_expirationTimer;
|
||||
QLinkedList<TreeItem*> m_itemsList;
|
||||
QMutex m_listMutex;
|
||||
};
|
||||
|
||||
class TreeItem : public QObject
|
||||
{
|
||||
@ -77,11 +98,16 @@ public:
|
||||
inline bool changed() { return m_changed; }
|
||||
inline void setChanged(bool changed) { m_changed = changed; }
|
||||
|
||||
virtual void setHighlightManager(HighLightManager* mgr);
|
||||
|
||||
QTime getHiglightExpires();
|
||||
|
||||
virtual void removeHighlight();
|
||||
|
||||
signals:
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
private slots:
|
||||
void removeHighlight();
|
||||
|
||||
private:
|
||||
QList<TreeItem*> m_children;
|
||||
@ -91,7 +117,8 @@ private:
|
||||
TreeItem *m_parent;
|
||||
bool m_highlight;
|
||||
bool m_changed;
|
||||
QTimer m_timer;
|
||||
QTime m_highlightExpires;
|
||||
HighLightManager* m_highlightManager;
|
||||
public:
|
||||
static const int dataColumn = 1;
|
||||
private:
|
||||
|
@ -46,7 +46,7 @@ UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
m_highlightManager = new HighLightManager(300);
|
||||
connect(objManager, SIGNAL(newObject(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
|
||||
@ -56,6 +56,7 @@ UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
|
||||
UAVObjectTreeModel::~UAVObjectTreeModel()
|
||||
{
|
||||
delete m_highlightManager;
|
||||
delete m_rootItem;
|
||||
}
|
||||
|
||||
@ -67,9 +68,12 @@ void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
|
||||
m_rootItem = new TreeItem(rootData);
|
||||
|
||||
m_settingsTree = new TopTreeItem(tr("Settings"), m_rootItem);
|
||||
m_settingsTree->setHighlightManager(m_highlightManager);
|
||||
m_rootItem->appendChild(m_settingsTree);
|
||||
m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), m_rootItem);
|
||||
m_nonSettingsTree->setHighlightManager(m_highlightManager);
|
||||
m_rootItem->appendChild(m_nonSettingsTree);
|
||||
m_rootItem->setHighlightManager(m_highlightManager);
|
||||
connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
|
||||
@ -96,6 +100,7 @@ void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
|
||||
addInstance(obj, root->child(index));
|
||||
} else {
|
||||
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName() + " (" + QString::number(obj->getNumBytes()) + " bytes)");
|
||||
data->setHighlightManager(m_highlightManager);
|
||||
connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
int index = root->nameIndex(obj->getName());
|
||||
root->insert(index, data);
|
||||
@ -110,6 +115,7 @@ void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
{
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||
MetaObjectTreeItem *meta = new MetaObjectTreeItem(obj, tr("Meta Data"));
|
||||
meta->setHighlightManager(m_highlightManager);
|
||||
connect(meta, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
foreach (UAVObjectField *field, obj->getFields()) {
|
||||
if (field->getNumElements() > 1) {
|
||||
@ -132,6 +138,7 @@ void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||
} else {
|
||||
QString name = tr("Instance") + " " + QString::number(obj->getInstID());
|
||||
item = new InstanceTreeItem(obj, name);
|
||||
item->setHighlightManager(m_highlightManager);
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->appendChild(item);
|
||||
}
|
||||
@ -148,6 +155,7 @@ void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||
void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
|
||||
{
|
||||
TreeItem *item = new ArrayFieldTreeItem(field->getName());
|
||||
item->setHighlightManager(m_highlightManager);
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
for (uint i = 0; i < field->getNumElements(); ++i) {
|
||||
addSingleField(i, field, item);
|
||||
@ -192,6 +200,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
item->setHighlightManager(m_highlightManager);
|
||||
connect(item, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->appendChild(item);
|
||||
}
|
||||
@ -352,7 +361,6 @@ void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
|
||||
Q_ASSERT(obj);
|
||||
ObjectTreeItem *item = findObjectTreeItem(obj);
|
||||
Q_ASSERT(item);
|
||||
item->setHighlight(true);
|
||||
item->update();
|
||||
QModelIndex itemIndex = index(item);
|
||||
Q_ASSERT(itemIndex != QModelIndex());
|
||||
|
@ -97,6 +97,7 @@ private:
|
||||
int m_recentlyUpdatedTimeout;
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
HighLightManager *m_highlightManager;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTTREEMODEL_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user