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&)));
129 connect(
myModel, &QAbstractItemModel::rowsInserted, [
this](
const QModelIndex &parent,
int ,
int ) {
133 QWidget* w =
new QWidget(splitter);
135 splitter->addWidget(w);
139 dummy->
addLabel(tr(
"No details available."),
nullptr);
170 splitter->setSizes({5000, 5000});
172 QApplication::restoreOverrideCursor();
182 if (!current.isValid()) {
187 auto rc =
myModel->mapToSource(current);
199 newPanel->setAsset(item);
209 panel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
217 if (dlg.exec() != QDialog::Accepted)
231 QAction* clear =
new QAction(tr(
"(none)"),
this);
232 connect(clear, SIGNAL(triggered()),
this, SLOT(
clearFilter()));
240 QAction* a =
new QAction(filter->
name(),
this);
248 QAction* quick =
new QAction(tr(
"Quick filter..."),
this);
249 connect(quick, SIGNAL(triggered()),
this, SLOT(
onQuickFilter()));
251 QAction* dialog =
new QAction(tr(
"Filters definition..."),
this);
252 connect(dialog, SIGNAL(triggered()),
this, SLOT(
onFilter()));
267 if (dlg.exec() != QDialog::Accepted) {
279 myFilterButton->setText(filter.isEmpty() ? tr(
"Filter...") : tr(
"Filter: %1").arg(name));
281 if (!
myTreeRoot.isValid() || root.isValid()) {
282 if (
myTree->model() ==
nullptr) {
286 myTree->setRootIndex(root);
288 myTree->setModel(
nullptr);
296 assert(root->canExportAsCsv());
298 auto destination = QFileDialog::getSaveFileName(
this, tr(
"Export as CSV..."), QString(), tr(
"CSV file (*.csv);;All files (*.*)"));
299 if (destination.isEmpty())
303 root->fillCsvHeader(contents);
307 for (
int i = 0; i < count; i++) {
309 if (!idx.isValid()) {
312 idx =
myModel->mapToSource(idx);
313 auto w =
static_cast<const AssetWrapper *
>(idx.internalPointer());
317 QFile file(destination);
318 if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
319 QMessageBox::critical(
this, tr(
"Error writing CSV file %1").arg(destination), tr(
"Unable to write CSV file %1!").arg(destination));
323 file.write(contents.toLocal8Bit());
324 QMessageBox::information(
this, tr(
"Export complete"), tr(
"Ressources correctly exported to CSV file %1.").arg(destination));
331 QModelIndex index =
myModel->mapToSource(
myTree->indexAt(pos));
332 if (index.isValid() && index.internalPointer()) {
339 if (menu.actions().size() == 0)
341 menu.exec(
myTree->mapToGlobal(pos) + QPoint(5, 5));
346 auto name = QInputDialog::getText(
this,
"Create new quest",
"New quest code").toStdString();
350 if (getManager()->quests()->find(name)) {
351 QMessageBox::critical(
this,
"Quest already exists", tr(
"Quest %1 already exists!").arg(name.data()));
355 auto quest = quest_create(name.data());
356 quest->face = getManager()->faces()->get(
"quest_generic.111");
357 getManager()->quests()->define(name, quest);