forked from Public-Mirror/Textractor
fix thread linker crash and other minor improvements
This commit is contained in:
parent
b4aa113fac
commit
d74dcdc286
@ -16,6 +16,13 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="regexEdit"/>
|
<widget class="QLineEdit" name="regexEdit"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="saveButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -28,13 +35,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="saveButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Save</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel">
|
<widget class="QLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -16,10 +16,10 @@ std::vector<int> GenerateSuffixArray(const std::wstring& text)
|
|||||||
eqClasses[suffixArray[0]] = 0;
|
eqClasses[suffixArray[0]] = 0;
|
||||||
for (int i = 1; i < text.size(); ++i)
|
for (int i = 1; i < text.size(); ++i)
|
||||||
{
|
{
|
||||||
int currentSuffix = suffixArray[i];
|
int currentSuffix = suffixArray[i], lastSuffix = suffixArray[i - 1];
|
||||||
int lastSuffix = suffixArray[i - 1];
|
|
||||||
if (currentSuffix + length < text.size() && prevEqClasses[currentSuffix] == prevEqClasses[lastSuffix] &&
|
if (currentSuffix + length < text.size() && prevEqClasses[currentSuffix] == prevEqClasses[lastSuffix] &&
|
||||||
prevEqClasses[currentSuffix + length / 2] == prevEqClasses.at(lastSuffix + length / 2)) // not completely certain that this will stay in range
|
prevEqClasses[currentSuffix + length / 2] == prevEqClasses[lastSuffix + length / 2]
|
||||||
|
)
|
||||||
eqClasses[currentSuffix] = eqClasses[lastSuffix];
|
eqClasses[currentSuffix] = eqClasses[lastSuffix];
|
||||||
else eqClasses[currentSuffix] = i;
|
else eqClasses[currentSuffix] = i;
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
extern const char* THREAD_LINKER;
|
extern const char* THREAD_LINKER;
|
||||||
extern const char* LINK;
|
extern const char* LINK;
|
||||||
|
extern const char* UNLINK;
|
||||||
extern const char* THREAD_LINK_FROM;
|
extern const char* THREAD_LINK_FROM;
|
||||||
extern const char* THREAD_LINK_TO;
|
extern const char* THREAD_LINK_TO;
|
||||||
extern const char* HEXADECIMAL;
|
extern const char* HEXADECIMAL;
|
||||||
|
|
||||||
std::unordered_map<int64_t, std::unordered_multiset<int64_t>> linkedTextHandles;
|
std::unordered_map<int64_t, std::unordered_set<int64_t>> linkedTextHandles;
|
||||||
std::shared_mutex m;
|
std::shared_mutex m;
|
||||||
|
|
||||||
class Window : public QDialog, Localizer
|
class Window : public QDialog, Localizer
|
||||||
@ -17,9 +18,14 @@ public:
|
|||||||
Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
|
Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
|
||||||
{
|
{
|
||||||
connect(&linkButton, &QPushButton::clicked, this, &Window::Link);
|
connect(&linkButton, &QPushButton::clicked, this, &Window::Link);
|
||||||
|
connect(&unlinkButton, &QPushButton::clicked, this, &Window::Unlink);
|
||||||
|
|
||||||
layout.addWidget(&linkList);
|
layout.addWidget(&linkList);
|
||||||
layout.addWidget(&linkButton);
|
layout.addLayout(&buttons);
|
||||||
|
buttons.addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||||
|
buttons.addWidget(&linkButton);
|
||||||
|
buttons.addWidget(&unlinkButton);
|
||||||
|
buttons.addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||||
|
|
||||||
setWindowTitle(THREAD_LINKER);
|
setWindowTitle(THREAD_LINKER);
|
||||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||||
@ -34,14 +40,13 @@ private:
|
|||||||
if (ok1 && ok2 && ok3 && ok4)
|
if (ok1 && ok2 && ok3 && ok4)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m);
|
std::scoped_lock lock(m);
|
||||||
linkedTextHandles[from].insert(to);
|
if (linkedTextHandles[from].insert(to).second) linkList.addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
|
||||||
linkList.addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent* event) override
|
void Unlink()
|
||||||
{
|
{
|
||||||
if (event->key() == Qt::Key_Delete && linkList.currentItem())
|
if (linkList.currentItem())
|
||||||
{
|
{
|
||||||
QStringList link = linkList.currentItem()->text().split("->");
|
QStringList link = linkList.currentItem()->text().split("->");
|
||||||
linkList.takeItem(linkList.currentRow());
|
linkList.takeItem(linkList.currentRow());
|
||||||
@ -50,18 +55,22 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void keyPressEvent(QKeyEvent* event) override
|
||||||
|
{
|
||||||
|
if (event->key() == Qt::Key_Delete) Unlink();
|
||||||
|
}
|
||||||
|
|
||||||
QHBoxLayout layout{ this };
|
QHBoxLayout layout{ this };
|
||||||
|
QVBoxLayout buttons;
|
||||||
QListWidget linkList{ this };
|
QListWidget linkList{ this };
|
||||||
QPushButton linkButton{ LINK, this };
|
QPushButton linkButton{ LINK, this }, unlinkButton{ UNLINK, this };
|
||||||
} window;
|
} window;
|
||||||
|
|
||||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||||
{
|
{
|
||||||
std::shared_lock lock(m);
|
std::shared_lock lock(m);
|
||||||
int64_t textHandle = sentenceInfo["text number"];
|
auto links = linkedTextHandles.find(sentenceInfo["text number"]);
|
||||||
|
if (links != linkedTextHandles.end()) for (auto link : links->second)
|
||||||
for (auto linkedHandle : linkedTextHandles[textHandle])
|
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(link, sentence.c_str());
|
||||||
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(linkedHandle, sentence.c_str());
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
1
text.cpp
1
text.cpp
@ -221,6 +221,7 @@ Whitespace in original_text is ignored, but replacement_text can contain spaces,
|
|||||||
This file must be encoded in Unicode (UTF-16 Little Endian).)";
|
This file must be encoded in Unicode (UTF-16 Little Endian).)";
|
||||||
const char* THREAD_LINKER = u8"Thread Linker";
|
const char* THREAD_LINKER = u8"Thread Linker";
|
||||||
const char* LINK = u8"Link";
|
const char* LINK = u8"Link";
|
||||||
|
const char* UNLINK = u8"Unlink";
|
||||||
const char* THREAD_LINK_FROM = u8"Thread number to link from";
|
const char* THREAD_LINK_FROM = u8"Thread number to link from";
|
||||||
const char* THREAD_LINK_TO = u8"Thread number to link to";
|
const char* THREAD_LINK_TO = u8"Thread number to link to";
|
||||||
const char* HEXADECIMAL = u8"Hexadecimal";
|
const char* HEXADECIMAL = u8"Hexadecimal";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user