-
Notifications
You must be signed in to change notification settings - Fork 3
refactoring / code quality improvements #47
Comments
@asw-dev since you're much better than me at this stuff, does this makes sense to you? have some hints what's good/bad with this and maybe some ideas what else should i do? i'd like to avoid having to clean it up later when it further grows, but as said, not a c++ developer and very little experience in this kind of design. |
I wouldn't call myself an expert at Qt but here is my 2 cents. QSqlQuery -> Query: seems fine, it's very close to a refactor I was thinking of. QAction & QToolButton: using data to hold an id is fine, but ideally you want to avoid ConnnectionManager having to know anything about the caller. Normally you could have the signal also pass data, but in this case that is probably not an option. Instead you can create a new slot in MainWindow (the current owner of QToolButton, but it could also be subclassed if you wanted to) that then calls m_connnectionManager.openConnection() using data() to get the arg to call with. refreshConnectionActions: The original idea of a "refresh" was to be a quick way to do all the things. A more clean (but verbose) way of doing this is to add all the individual state changes of ConnnectionManager as signals.
Then use emit to raise the signals when you change state, and connect them as need (and emit any additional signals as state is changed in those objects, etc.). Another refactor that comes to mind would be to take the ConnectionDialog and extract a ConnectionWidget that can be reused for both ConnectionDialog & ConnectionManagerDialog. |
but you do java development, so OOP is something you know much better than me and i'm trying to learn what good design looks like
what do you think about something like this: https://github.com/mispp/goat/tree/refactoring Made a custom class Query with member QSqlQuery. Didn't want to inherit QSqlQuery because i wanted that Query handles cloning of connection upon every execution. So basically Query::execute() should handle cloning of connection and internally setup results and threading. It compiles and works, but not sure if this is something decent. |
Some fixes were needed in the new branch, so now it works better. Problem: since every tab (actually Query) has it's own connection, during exit this needs to be released in a way that warning is not shown. Currently, in MainWindow exit function, there is a loop that closes all open connections and then removes them. |
Example warning:
|
From what I can see it looks reasonable. I saw that switchDatabase() & reconnectDatabase() are closing the db before m_query is deconstructed so it will cause warnings when removeDatabase() is called. Might require m_query being a pointer so you delete it when you want. The reuse of Query across threads would cause issues if you ever had two query threads running. It would be unlikely but if you failed to cancel without an error it would re-enable the query button for a second thread to work on the same Query reference. Not sure if it's worth considering at this point. |
Thanks for the review.
Suspected the same thing, but didn't want to touch it. Oh well.
Yes, this is an issue and it must not happen. Says in the docu that forward-only queries should not have any other queries ran on the same connection. This i know is a problem since ctrl-enter doesn't get disabled, so it can be triggered twice. Going to do the following and see if it works:
This way, each QueryTab will have its own thread for running QSqlQuery. |
Further down the road, each tab should have a Queue for data export. Each export should have its own thread. |
Instead of object, i guess only connectionId has to be moved around so this error is avoided. |
What i had in mind with QueryTab is done. It should be better now because it's decoupled, but still not the best. Not using QThread as mentioned before, but QtConcurrent::run |
Great advice. QMenu has a triggered(QAction*) signal, so i hooked that one to call openConnection which picks up data from QAction. |
finally managed to make QThread setup work here https://github.com/mispp/goat/tree/refactoring2 @asw-dev mind if you take a look and give me some feedback? it looks quite clean for me, so now that i figured it out, the next two things need to be done in the same way:
after both are done, should be merged into master. testing is not fully done, so i'm not sure how it works with multiple connections, disconnection, closing tab while query is running etc. Several issues are also present:
|
this now works (branch refactoring2), including querystopper and export. what i plan to do further:
|
Not sure if I was able to follow all the code changes, but here is what I saw. Looks like you are already aware of some of it.
in
|
i'll take a look. you usually use whatever is in Connection object to pass to openConnection or addConnection, so i'd need to update it somehow before passing.
let's keep it like this until it causes problems.
there is a connect signal which says on QThread::finished call QThread::deleteLater. same is done also for Query, so as far as i understand, this should initiate delete for both objects on Tab closing.
will do this. had this in mind already.
will convert this then to signal/slot instead of direct call. thanks for the review! |
this probably can be changed to QList since it has type information. |
some ideas:
take out QSqlQuery in it's own class called Query which should implement functions
not sure how to handle this QAction thing for the QToolButton
take out the loop from refreshConnectionActions() from MainWindow and move it to connection manager. i guess function has to stay here to first clear old actions before loading new ones
The text was updated successfully, but these errors were encountered: