Created attachment 101714 [details] Proposed fix Especially with the biblatex style, adding a new entry to a database can be extremely slow. It takes up to ~10 seconds until the widget edit dialog finally pops up. Debugging revealed that the culprit is FileView::setSelectedElement, more precisely the loop over all columns added in https://quickgit.kde.org/?p=kbibtex.git&a=commit&h=4f529a8444e4c In my case, this loops over all (130!) columns just for the sake of selecting the whole row after the new entry has been added. I'll attach a patch which uses the QItemSelectionModel::Rows flag instead, which has the same effect but is _much_ faster (the editing window now pops up almost instantaneously).
BTW, independent of my patch, the selection of the new entry fails if (1.) the database has comments or macros and (2.) if "Show comments" or "Show macros" is disabled in the prefs. Presumably due to a mismatch of the rows in the file model and the QAbstractItemModel. I had a look but did not find a solution how these can be synchronized.
Created attachment 101718 [details] Updated patch (addressing the mentioned additional issue) I found the solution to the index mismatching problem: We have to use sortFilterProxyModel()->mapFromSource. The updated patch does this.
Git commit 98e55392df85285a67d628209ac77bd5ed3b071b by Thomas Fischer, on behalf of Juergen Spitzmueller. Committed on 23/10/2016 at 13:50. Pushed by thomasfischer into branch 'kbibtex/0.6'. Speeding up selection of elements The old code manually iterated over all columns of rows to be selected, which was expensive in the case of many columns (e.g. for BibLaTeX) and large files (many rows). This patch uses a Qt-internal flag when selecting elements to select the full row with a single call. Furthermore, the unused function 'setSelectedElement(QList<QSharedPointer<Element> > &)' has been completely removed as it was unused. Signed-off-by: Thomas Fischer <fischer@unix-ag.uni-kl.de> M +3 -20 src/gui/file/fileview.cpp M +0 -1 src/gui/file/fileview.h http://commits.kde.org/kbibtex/98e55392df85285a67d628209ac77bd5ed3b071b
(In reply to Juergen Spitzmueller from comment #2) > Created attachment 101718 [details] > Updated patch (addressing the mentioned additional issue) > > I found the solution to the index mismatching problem: We have to use > sortFilterProxyModel()->mapFromSource. > > The updated patch does this. Thank you for your bug report and patch! I was not aware that QItemSelectionModel::Select and QItemSelectionModel::Rows combined have such an effect. I modified your patch in two ways: 1. Removed setSelectedElements as it is not used anywhere. 2. Made both variables row and idx 'const'.