window: getNextFreeCell(): reimplement without refering to grid

Does not work that way since when we search, the grid has changed.
So we cannot check inside the grid which ones are free. This
would give wrong results.
This commit is contained in:
Albert S. 2020-09-27 21:37:59 +02:00
γονέας 7bae1183c6
υποβολή 47c0358a25
1 αρχεία άλλαξαν με 32 προσθήκες και 11 διαγραφές

@ -136,7 +136,7 @@ void Window::addToFavourites(const EntryPushButton &button)
QString entryName = fi.completeBaseName() + ".qsrun"; QString entryName = fi.completeBaseName() + ".qsrun";
userConfig.entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName; userConfig.entryPath = this->settingsProvider->userEntriesPaths()[0] + "/" + entryName;
entryProvider->saveUserEntry(userConfig); entryProvider->saveUserEntry(userConfig);
initFromConfig(); userEntryButtons.append(createEntryButton(userConfig));
} }
void Window::closeWindow() void Window::closeWindow()
@ -154,23 +154,44 @@ void Window::closeWindow()
std::pair<int, int> Window::getNextFreeCell() std::pair<int, int> Window::getNextFreeCell()
{ {
int maxRow = 0; /* Not the most efficient way perhaps but for now it'll do */
for(EntryPushButton *button : userEntryButtons) std::sort(userEntryButtons.begin(), userEntryButtons.end(), [](EntryPushButton *a, EntryPushButton *b) {
{ const EntryConfig &config_a = a->getEntryConfig();
if(button->getRow() > maxRow) const EntryConfig &config_b = b->getEntryConfig();
if(config_a.row < config_b.row)
{ {
maxRow = button->getRow(); return true;
} }
} if(config_a.row > config_b.row)
{
return false;
}
return config_a.col < config_b.col;
});
int expectedRow = 1;
int expectedCol = 1;
int maxCols = this->settingsProvider->getMaxCols(); int maxCols = this->settingsProvider->getMaxCols();
for(int i = 1; i < maxCols; i++) for(EntryPushButton *current : userEntryButtons)
{ {
if(grid->itemAtPosition(maxRow, i) == 0) int currentRow = current->getEntryConfig().row;
int currentCol = current->getEntryConfig().col;
if(currentRow != expectedRow || currentCol != expectedCol)
{ {
return {maxRow, i + 1}; return {expectedRow, expectedCol};
}
if(expectedCol == maxCols)
{
expectedCol = 1;
++expectedRow;
}
else
{
++expectedCol;
} }
} }
return {maxRow + 1, 0}; return {expectedRow, expectedCol};
} }
QStringList Window::generatePATHSuggestions(const QString &text) QStringList Window::generatePATHSuggestions(const QString &text)