ui improvements

This commit is contained in:
Akash Mozumdar 2021-09-06 02:02:36 -06:00
parent c9ad8880fb
commit eddf1bf0ee
4 changed files with 17 additions and 14 deletions

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>107</height>
<height>80</height>
</rect>
</property>
<layout class="QVBoxLayout">

View File

@ -12,7 +12,7 @@ extern const char* HEXADECIMAL;
std::unordered_map<int64_t, std::unordered_set<int64_t>> links;
std::unordered_set<int64_t> universalLinks, empty;
bool separateSentences = true; // allow user to change?
bool separateSentences = false; // allow user to change?
concurrency::reader_writer_lock m;
class Window : public QDialog, Localizer
@ -34,14 +34,17 @@ private:
void Link()
{
bool ok1, ok2, ok3, ok4;
QString fromInput = QInputDialog::getText(this, THREAD_LINK_FROM, HEXADECIMAL, QLineEdit::Normal, "X", &ok1, Qt::WindowCloseButtonHint);
int from = fromInput.toInt(&ok2, 16),
to = QInputDialog::getText(this, THREAD_LINK_TO, HEXADECIMAL, QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
if (ok1 && (ok2 || fromInput == "X") && ok3 && ok4)
QString fromInput = QInputDialog::getText(this, THREAD_LINK_FROM, HEXADECIMAL, QLineEdit::Normal, "All", &ok1, Qt::WindowCloseButtonHint);
int from = fromInput.toInt(&ok2, 16);
if (ok1 && (fromInput == "All" || ok2))
{
int to = QInputDialog::getText(this, THREAD_LINK_TO, HEXADECIMAL, QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
if (ok3 && ok4)
{
std::scoped_lock lock(m);
if ((ok2 ? links[from] : universalLinks).insert(to).second)
ui.linkList->addItem((ok2 ? QString::number(from, 16) : "X") + "->" + QString::number(to, 16));
ui.linkList->addItem((ok2 ? QString::number(from, 16) : "All") + "->" + QString::number(to, 16));
}
}
}
@ -52,7 +55,7 @@ private:
QStringList link = ui.linkList->currentItem()->text().split("->");
ui.linkList->takeItem(ui.linkList->currentRow());
std::scoped_lock lock(m);
(link[0] == "X" ? universalLinks : links[link[0].toInt(nullptr, 16)]).erase(link[1].toInt(nullptr, 16));
(link[0] == "All" ? universalLinks : links[link[0].toInt(nullptr, 16)]).erase(link[1].toInt(nullptr, 16));
}
}
@ -69,7 +72,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
concurrency::reader_writer_lock::scoped_lock_read readLock(m);
auto action = separateSentences ? sentenceInfo["add sentence"] : sentenceInfo["add text"];
auto it = links.find(sentenceInfo["text number"]);
for (const auto& linkSet : { it != links.end() ? it->second : empty, universalLinks })
for (const auto& linkSet : { it != links.end() ? it->second : empty, sentenceInfo["text number"] > 1 ? universalLinks : empty })
for (auto link : linkSet)
((void(*)(int64_t, const wchar_t*))action)(link, sentence.c_str());
return false;

View File

@ -24,11 +24,11 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="unlinkButton">
<widget class="QPushButton" name="linkButton">
</widget>
</item>
<item>
<widget class="QPushButton" name="linkButton">
<widget class="QPushButton" name="unlinkButton">
</widget>
</item>
<item>

View File

@ -222,7 +222,7 @@ This file must be encoded in Unicode (UTF-16 Little Endian).)";
const char* THREAD_LINKER = u8"Thread Linker";
const char* LINK = u8"Link";
const char* UNLINK = u8"Unlink";
const char* THREAD_LINK_FROM = u8"Thread number to link from (or X to link from all threads)";
const char* THREAD_LINK_FROM = u8"Thread number to link from";
const char* THREAD_LINK_TO = u8"Thread number to link to";
const char* HEXADECIMAL = u8"Hexadecimal";