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:
parent
7bae1183c6
commit
47c0358a25
41
window.cpp
41
window.cpp
@ -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();
|
||||||
|
const EntryConfig &config_b = b->getEntryConfig();
|
||||||
|
if(config_a.row < config_b.row)
|
||||||
{
|
{
|
||||||
if(button->getRow() > maxRow)
|
return true;
|
||||||
|
}
|
||||||
|
if(config_a.row > config_b.row)
|
||||||
{
|
{
|
||||||
maxRow = button->getRow();
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user