Skip to content
Permalink
Browse files
Editor: Fixed the freeze caused by not killed level file digger thread
  • Loading branch information
Wohlstand committed Apr 20, 2017
1 parent 8cc24e7 commit a8458ed7e1dd9c3376586a415a4e909b0e964a5f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
@@ -30,12 +30,17 @@ LevelFileList::LevelFileList(QString Folder, QString current, QWidget *parent) :
parentFolder = Folder;
lastCurrentFile = current;
ui->setupUi(this);
connect(this, SIGNAL(itemAdded(QString)), this, SLOT(addItem(QString)));
connect(this, &LevelFileList::itemAdded, this, &LevelFileList::addItem);
connect(this, &LevelFileList::digFinished, this, &LevelFileList::finalizeDig);
setCursor(Qt::BusyCursor);
fileWalker = QtConcurrent::run(this, &LevelFileList::buildLevelList);
}

LevelFileList::~LevelFileList()
{
if(fileWalker.isRunning())
fileWalker.cancel();
fileWalker.waitForFinished();
delete ui;
}

@@ -54,19 +59,18 @@ void LevelFileList::buildLevelList()
{
dirsList.next();
emit itemAdded(musicDir.relativeFilePath(dirsList.filePath()));

if(fileWalker.isCanceled()) break;
if(fileWalker.isCanceled())
break;
}
digFinished();
}

void LevelFileList::addItem(QString item)
{
ui->FileList->addItem(item);

if(lastCurrentFile == item)
{
QList<QListWidgetItem *> list = ui->FileList->findItems(item, Qt::MatchFixedString);

if(!list.isEmpty())
{
list.first()->setSelected(true);
@@ -75,22 +79,41 @@ void LevelFileList::addItem(QString item)
}
}

void LevelFileList::finalizeDig()
{
ui->FileList->sortItems(Qt::AscendingOrder);
QList<QListWidgetItem *> list = ui->FileList->findItems(lastCurrentFile, Qt::MatchFixedString);
if(!list.isEmpty())
{
list.first()->setSelected(true);
ui->FileList->scrollToItem(list.first());
}
setCursor(Qt::ArrowCursor);
}

void LevelFileList::on_FileList_itemDoubleClicked(QListWidgetItem *item)
{
SelectedFile = item->text();
if(fileWalker.isRunning())
fileWalker.cancel();
accept();
}

void LevelFileList::on_buttonBox_accepted()
{
foreach(QListWidgetItem *container, ui->FileList->selectedItems())
SelectedFile = container->text();

if(SelectedFile != "")
{
if(fileWalker.isRunning())
fileWalker.cancel();
accept();
}
}

void LevelFileList::on_buttonBox_rejected()
{
if(fileWalker.isRunning())
fileWalker.cancel();
reject();
}
@@ -25,14 +25,17 @@ class LevelFileList : public QDialog

private slots:
void addItem(QString item);
void finalizeDig();

void on_FileList_itemDoubleClicked(QListWidgetItem *item);

void on_buttonBox_accepted();
void on_buttonBox_rejected();


signals:
void itemAdded(QString item);
void digFinished();

private:
QFuture<void> fileWalker;
@@ -35,7 +35,9 @@ MusicFileList::MusicFileList(QString Folder, QString current, QWidget *parent) :
lastCurrentFile=current;

ui->setupUi(this);
connect(this, SIGNAL(itemAdded(QString)), this, SLOT(addItem(QString)));
connect(this, &MusicFileList::itemAdded, this, &MusicFileList::addItem);
connect(this, &MusicFileList::digFinished, this, &MusicFileList::finalizeDig);
setCursor(Qt::BusyCursor);
fileWalker = QtConcurrent::run(this, &MusicFileList::buildMusicList);
}

@@ -77,6 +79,7 @@ void MusicFileList::buildMusicList()
emit itemAdded(musicDir.relativeFilePath(dirsList.filePath()));
if(fileWalker.isCanceled()) break;
}
digFinished();
}

void MusicFileList::addItem(QString item)
@@ -93,9 +96,23 @@ void MusicFileList::addItem(QString item)
}
}

void MusicFileList::finalizeDig()
{
ui->FileList->sortItems(Qt::AscendingOrder);
QList<QListWidgetItem *> list = ui->FileList->findItems(lastCurrentFile, Qt::MatchFixedString);
if(!list.isEmpty())
{
list.first()->setSelected(true);
ui->FileList->scrollToItem(list.first());
}
setCursor(Qt::ArrowCursor);
}

void MusicFileList::on_FileList_itemDoubleClicked(QListWidgetItem *item)
{
SelectedFile = item->text();
if(fileWalker.isRunning())
fileWalker.cancel();
accept();
}

@@ -105,7 +122,11 @@ void MusicFileList::on_buttonBox_accepted()
SelectedFile = container->text();
}
if(SelectedFile!="")
{
if(fileWalker.isRunning())
fileWalker.cancel();
accept();
}
}

void MusicFileList::on_buttonBox_rejected()
@@ -42,9 +42,12 @@ class MusicFileList : public QDialog

signals:
void itemAdded(QString item);
void digFinished();

private slots:
void addItem(QString item);
void finalizeDig();

void on_FileList_itemDoubleClicked(QListWidgetItem *item);
void on_buttonBox_accepted();
void on_buttonBox_rejected();
@@ -44,6 +44,7 @@ patch 4
- Fixed an inability to setup default value for special spin-box value on NPC
- Added more detailed tool tip for elements in the item box hovered by the mouse cursor
- Added a tool tip showing on tileset item box elements
- Fixed the freeze caused by not killed level file digger thread

Editor 0.3.1.11
- Added Polish translation of the editor

0 comments on commit a8458ed

Please sign in to comment.