24 #include <QStandardItem>
25 #include <QDataStream>
27 #include <QtDesigner/abstractmetadatabase.h>
31 QSortFilterProxyModel(parent),
35 setSourceModel(sModel);
37 connect(
this, SIGNAL(
reload()),
this, SLOT(onReload()));
45 void gui::ObjectExplorerModel::onReload()
52 setFilterCaseSensitivity(Qt::CaseInsensitive);
53 QSortFilterProxyModel::setFilterFixedString(searchPattern);
58 return sModel->getItemInformation(mapToSource(
index));
61 bool gui::ObjectExplorerModel::filterAcceptsRow(
int sourceRow,
const QModelIndex& sourceParent)
const
63 QModelIndex
index = sourceModel()->index(sourceRow, 0, sourceParent);
64 return showThis(
index);
67 bool gui::ObjectExplorerModel::showThis(
const QModelIndex&
index)
const
69 bool acceptRow =
false;
72 if (sourceModel()->rowCount(
index) > 0)
74 for (
int nChild = 0; nChild < sourceModel()->rowCount(
index); ++nChild)
76 QModelIndex childIndex = sourceModel()->index(nChild, 0,
index);
78 if (!childIndex.isValid())
83 acceptRow = showThis(childIndex);
93 QModelIndex useIndex = sourceModel()->index(
index.row(), 0,
index.parent());
94 QString name = sourceModel()->data(useIndex, Qt::DisplayRole).toString();
96 if (!name.contains(filterRegExp()) || name.isEmpty())
111 return sModel->getItemPixmap(mapToSource(
index));
117 gui::ObjectExplorerModel::ObjectExplorerModelPrivate::ObjectExplorerModelPrivate(
const controller::ControllerPtr&
control,
int rows,
int columns, QObject* parent) :
118 QStandardItemModel(rows, columns, parent),
124 void gui::ObjectExplorerModel::ObjectExplorerModelPrivate::onReload()
128 std::vector<std::string> collections =
controller->getMemoryXController()->getPriorKnowlegdeController()->getCollectionNames();
130 this->setRowCount(collections.size());
131 std::vector<memoryx::ObjectClassPtr> objects;
132 std::string objectName;
134 for (
int row = 0; row < (int)collections.size(); ++row)
136 objects =
controller->getMemoryXController()->getPriorKnowlegdeController()->getAllObjectClassesPtr(collections[row]);
140 if (objects.size() < 1)
142 ARMARX_WARNING_S <<
"No objects found in collection " << collections.at(row);
146 QStandardItem* item =
new QStandardItem(QString::fromStdString(collections[row]));
148 for (
int i = 0; i < (int)objects.size(); ++i)
150 objectName = objects[i]->getName();
152 if (
controller->getMemoryXController()->getPriorKnowlegdeController()->getCoinVisualisation(objects[i],
true) &&
controller->getMemoryXController()->getPriorKnowlegdeController()->getCoinVisualisation(objects[i],
false))
154 QStandardItem* child =
new QStandardItem(QString::fromStdString(objectName));
155 child->setSizeHint(sizeHint);
156 child->setIcon(this->getPreviewImageOfObject(
controller, objects[i]));
157 child->setEditable(
false);
158 item->setChild(i, child);
166 item->setSizeHint(QSize(30, 30));
167 item->setDragEnabled(
false);
168 this->appendRow(item);
173 std::pair<std::string, std::string> gui::ObjectExplorerModel::ObjectExplorerModelPrivate::getItemInformation(
const QModelIndex&
index)
175 std::pair<std::string, std::string> toReturn;
180 QStandardItem* item = itemFromIndex(
index);
184 toReturn.first = item->text().toStdString();
185 toReturn.second = item->parent()->text().toStdString();
194 QPixmap gui::ObjectExplorerModel::ObjectExplorerModelPrivate::getItemPixmap(
const QModelIndex&
index)
const
200 QStandardItem* item = itemFromIndex(
index);
201 pixmap = item->icon().pixmap(item->icon().actualSize(sizeHint));
205 QIcon i = QIcon(QPixmap::fromImage(QImage(
":/icons/armarx-gui.png")));
206 pixmap = i.pixmap(i.actualSize(sizeHint));
216 preview = QImage(
":/icons/armarx-gui.png");
228 return QIcon(QPixmap::fromImage(preview));
231 QStringList gui::ObjectExplorerModel::ObjectExplorerModelPrivate::mimeTypes()
const
234 types <<
"application/vnd.text.list";
238 QMimeData* gui::ObjectExplorerModel::ObjectExplorerModelPrivate::mimeData(
const QModelIndexList& indexes)
const
240 QMimeData* mimeData =
new QMimeData();
241 QByteArray encodedData;
243 QDataStream stream(&encodedData, QIODevice::WriteOnly);
245 foreach (QModelIndex
index, indexes)
249 QStandardItem* item = itemFromIndex(
index);
253 stream << item->parent()->text();
254 stream << item->text();
259 mimeData->setData(
"application/vnd.text.list", encodedData);