15 #include <QScriptValue>
59 #include "AssetsManager.h"
73 QApplication::setOverrideCursor(Qt::WaitCursor);
74 setWindowTitle(model->
data(root, Qt::DisplayRole).toString());
87 setAttribute(Qt::WA_DeleteOnClose);
89 QVBoxLayout* layout =
new QVBoxLayout(
this);
92 QHBoxLayout* buttons =
new QHBoxLayout();
97 auto exportCsv =
new QPushButton(tr(
"Export as CSV"),
this);
98 buttons->addWidget(exportCsv);
99 connect(exportCsv, SIGNAL(clicked()),
this, SLOT(
onExportAsCsv()));
102 exportCsv->setEnabled(
false);
103 exportCsv->setToolTip(tr(
"CSV export is not available for this type of ressources"));
107 exportCsv->setToolTip(tr(
"Export visible ressources to CSV file"));
110 layout->addLayout(buttons);
112 auto splitter =
new QSplitter(
this);
113 layout->addWidget(splitter);
115 myTree =
new QTreeView(
this);
118 splitter->addWidget(
myTree);
119 myTree->setIconSize(QSize(32, 32));
122 myTree->setSelectionMode(QAbstractItemView::SingleSelection);
123 myTree->setDragEnabled(
true);
124 myTree->setDropIndicatorShown(
true);
125 myTree->setDragDropMode(QAbstractItemView::DragDrop);
126 myTree->setContextMenuPolicy(Qt::CustomContextMenu);
127 connect(
myTree, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(
treeCustomMenu(
const QPoint&)));
130 QWidget* w =
new QWidget(splitter);
132 splitter->addWidget(w);
136 dummy->
addLabel(tr(
"No details available."),
nullptr);
167 splitter->setSizes({5000, 5000});
170 connect(
myModel, &QAbstractItemModel::rowsInserted, [
this](
const QModelIndex &parent,
int first,
int ) {
172 auto child =
myModel->index(first, 0, parent);
173 myTree->selectionModel()->select(child, QItemSelectionModel::ClearAndSelect);
174 myTree->setCurrentIndex(child);
178 QApplication::restoreOverrideCursor();
188 if (!current.isValid()) {
193 auto rc =
myModel->mapToSource(current);
205 newPanel->setAsset(item);
215 panel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
223 if (dlg.exec() != QDialog::Accepted)
237 QAction* clear =
new QAction(tr(
"(none)"),
this);
238 connect(clear, SIGNAL(triggered()),
this, SLOT(
clearFilter()));
246 QAction* a =
new QAction(filter->
name(),
this);
254 QAction* quick =
new QAction(tr(
"Quick filter..."),
this);
255 connect(quick, SIGNAL(triggered()),
this, SLOT(
onQuickFilter()));
257 QAction* dialog =
new QAction(tr(
"Filters definition..."),
this);
258 connect(dialog, SIGNAL(triggered()),
this, SLOT(
onFilter()));
273 if (dlg.exec() != QDialog::Accepted) {
285 myFilterButton->setText(filter.isEmpty() ? tr(
"Filter...") : tr(
"Filter: %1").arg(name));
287 if (!
myTreeRoot.isValid() || root.isValid()) {
288 if (
myTree->model() ==
nullptr) {
292 myTree->setRootIndex(root);
294 myTree->setModel(
nullptr);
302 assert(root->canExportAsCsv());
304 auto destination = QFileDialog::getSaveFileName(
this, tr(
"Export as CSV..."), QString(), tr(
"CSV file (*.csv);;All files (*.*)"));
305 if (destination.isEmpty())
309 root->fillCsvHeader(contents);
313 for (
int i = 0; i < count; i++) {
315 if (!idx.isValid()) {
318 idx =
myModel->mapToSource(idx);
319 auto w =
static_cast<const AssetWrapper *
>(idx.internalPointer());
323 QFile file(destination);
324 if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
325 QMessageBox::critical(
this, tr(
"Error writing CSV file %1").arg(destination), tr(
"Unable to write CSV file %1!").arg(destination));
329 file.write(contents.toLocal8Bit());
330 QMessageBox::information(
this, tr(
"Export complete"), tr(
"Ressources correctly exported to CSV file %1.").arg(destination));
337 QModelIndex index =
myModel->mapToSource(
myTree->indexAt(pos));
338 if (index.isValid() && index.internalPointer()) {
345 if (menu.actions().size() == 0)
347 menu.exec(
myTree->mapToGlobal(pos) + QPoint(5, 5));