-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
detach additional database connection #2241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Be aware, I've changed attach behavior too in my last commit, please consider on review! |
|
Need help! What did I break? |
|
learned from @justinclift:
|
|
The same happened to my last pull request. I restarted the jobs and the
second time they finished on time.
|
|
I need your advice, please. In this PR I allready suggest to add to MainWindow.h (and I’m not happy with my naming): Meanwhile I realised, it's a matter of OOP. What I would like to have is a a set of protected read only methods to get all the usefull information from both of the structure-Widgets . Please, give me feedback if it’s ok when I go this way. |
|
@horst-p-w-neubauer - Have a look at the QTreeView API page. Extracting useful information would have to be done from a QTreeViewWidgetItem. A numerical index (or get that index via a search for a string name) would be required to get a View Item from Tree Model. The QTreeView description has links to overviews of Qt's Model/View Architecture. I'd encourage you to read through these pages first. |
|
@scottfurry , I struggle with all those longliners: In my opinion MainWindow should encapsulate the access details to getters. I've come upon this because there is indifferent use of the role attribute in the actual code and I've had some time to figure out they all do the same. |
|
And that's part of the reason I'm not big fan of Qt-Creator, but that is what is used for the project. A type alias may somehow alleviate the situation, but no promises. |
sorry, don't understand that |
|
I come from the world of VB .Net, but in that, you can create your own class, which does all the gruntwork of pulling from various 'longer' sources. A wrapper, if you like. So still OOP(sie daisy) but just 'cleaner'. The world of Qt might be totally different though... |
|
A yes - a facade class came into my mind too - I was just not brave enough to suggest. But if nobody mind I'd be fine with writing a facade to the treeViews holding DbStructureModels. |
Yeah, similar here when I was doing C++ on DB4S too. Personally, I tend to break things up into discrete units, as it's easier to mentally parse. It also means breakpoints can be set on individual lines when needing to debug / step through code and figure out what's going wrong. 😄 eg, something like this: Compilers generate the same code anyway, so it's not "more efficient" to have everything in long lines. 😄 |
|
But copy down a block of lines each time you just want to know which object type the actual selected dbStructure node does hold is boring - and as I've seen - not free of errors. If we hide all of this behind a tiny facade the code will look obvious and you don't get disturbed by all this utility stuff. |
|
Sounds like an improvement. 😄 |
|
Here's a bit of UML to show what I mean. DbStructureQItemViewFacade provides a simple read only interface to a QAbstractItemView (e.g. QTreeView) that holds a model() of type DBStructureModel. It is designed to simplify the access to the actual selected node. The Class follows the facade design pattern. Not in the picture: I forgot:
|
|
to solve #2242 "add path info to attached databases" I consider two different ways.
Which way should we go? Trying to understand the code I came up with this understanding of Colums (including a suggestion for 2. solution). Did I mix something up? |
|
And what about setting the file information to 'Name' column's tooltip? Visually I'd prefer it to be set in the Schema column, but that would be inappropriate with the column naming. Adding another column would make it to be either too far to the right (when appended) or displace other columns too far to the right (when inserted). |
|
Thanks to @scottfurry, I've realised we shouldn't allow to detach from the temp database. |
|
Looks like a good start to me 👍 One minor thing I just noticed is that the new files aren't yet added to the CMakeLists.txt file. Another thing is that this PR is doing much more than just adding a detach database feature by now. I don't know how familiar you are with Git but if you are, can you rewrite the commits for easier reviewing at some point? |
|
@mgrojo, I wonder about Your hint:
I thought ColumnXy of the model is only a structured datastore of the model. How it is shown on the front is a different thing. I'd not planed to bring ColumnUrl onto the tree as another column. I thougt to pick the data from this column and use it for columnName when it is asked in its DisplayRole. If this is not the right use of the columns in here, please tell me and I'm happy to change it. |
which of them do you mean? |
I'm not sure where to put this file. What is the difference between "set(SQLB_HDR" and "set(SQLB_MOC_HDR" in CMakeLists.txt file? |
scottfurry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed is that the new files aren't yet added to the CMakeLists.txt file
I'm not sure where to put this file. What is the difference between "set(SQLB_HDR" and "set(SQLB_MOC_HDR" in CMakeLists.txt file?
For educational purposes, a MOC_XXXX file is apart of Qt5 build sequence. The Meta-Object Compiler generates *.h and *.cxx or *.cpp files from the XML-like UI files created by Qt Creator and such. Without them, the program has no hooks in the QT5 ecosystem.
src/sqltextedit.cpp
Outdated
| registerImage(SqlUiLexer::ApiCompleterIconIdTable, QImage(":/icons/table")); | ||
| registerImage(SqlUiLexer::ApiCompleterIconIdColumn, QImage(":/icons/field")); | ||
| registerImage(SqlUiLexer::ApiCompleterIconIdSchema, QImage(":/icons/database")); | ||
| registerImage(SqlUiLexer::ApiCompleterIconIdSchema, QImage(":/icons/schema")); // ?hn rename to "schema" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference to this file resource has to exist in the directory tree.
In this case, you need the file [proj root]/src/icons/database.png
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a relict from Revert "rename "database" to "schema" internally" their shouldn't be a issue anymore - right?
src/VacuumDialog.cpp
Outdated
| QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeDatabases); | ||
| item->setText(0, QString::fromStdString(it.first)); | ||
| item->setIcon(0, QIcon(QString(":icons/database"))); | ||
| item->setIcon(0, QIcon(QString(":icons/schema"))); // ?hn rename to "schema" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment at end - resource needs to exist in tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a relict from Revert "rename "database" to "schema" internally" their shouldn't be a issue anymore - right?
src/DbStructureModel.cpp
Outdated
| // for schemata != "main"). For the normal structure branch of the tree we don't want to add the schema name because it's already obvious from | ||
| // the position of the item in the tree. | ||
| if(index.column() == ColumnName && data(index.sibling(index.row(), ColumnObjectType), Qt::EditRole).toString() =="schema" ){ | ||
| return item->text(index.column()) + " []"; // ?hn - remainder to add fileinfo later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be "problematic". You may want to read up on QAbstractItemModel to better understand why this column name is not a simple matter.
The QT view/item model is quirky but is fundamental to how qt manages data to/from a data source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scott. Sorry. You're commenting outdated changes.
take a look on: Revert "rename "database" to "schema" internally", please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. GitHub is showing a little "[Outdated]" tag next to the source code snippet. I have no idea why it's showing people the old code, rather than the latest. Doesn't seem useful. 😦
Sorry, I thought you were suggesting to bring that as a new column to the view too. I still prefer to have the file path as a tooltip. I think it's not something you need to have permanently visible and it'd make the column too wide and too "noisy". |
I've allready detached #2242 form this PR but you can see my UI proposal there. |
MKleusberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my full review 😄 These are all minor points which should be easy to fix.
src/MainWindow.cpp
Outdated
| QString type = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), DbStructureModel::ColumnObjectType)).toString(); | ||
| if(type == "table" || type == "view") | ||
| QString type = dbSelected->objectType(); | ||
| if(type == "table" || type == "view") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace added here 😉
src/MainWindow.cpp
Outdated
| ui->editDeleteObjectAction->setIcon(QIcon(QString(":icons/%1_delete").arg(type))); | ||
| ui->editModifyObjectAction->setIcon(QIcon(QString(":icons/%1_modify").arg(type))); | ||
| } | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra indentation added for the following lines.
|
|
||
| void MainWindow::fileDetachTreeSchemaDock() | ||
| { | ||
| fileDetachTreeViewSelected(ui->treeSchemaDock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use a single function here (e.g. just fileDetachTreeViewSelected) instead of two (fileDetachDbTree and fileDetachTreeSchemaDock) by using the sender() function and casting the result into a QTreeView* pointer. I'll add an example below.
| } | ||
|
|
||
| void MainWindow::fileDetachTreeViewSelected(QTreeView* treeView) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you remove the parameter, then add this at the beginning of the function to save the two extra functions above:
QTreeView* treeView = qobject_cast<QTreeView*>(sender());
src/MainWindow.h
Outdated
|
|
||
| #include <memory> | ||
| #include <QMainWindow> | ||
| #include <QTreeView> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to include QTreeView here. We try to keep the number of includes as low as possible to reduce the compile time. You can just add class QTreeView; a few lines below.
src/dbstructureqitemviewfacade.h
Outdated
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit DbStructureQItemViewFacade(QAbstractItemView *aitemView = new QTreeView()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you are specifying a default value here. I thought there is no point creating a DbStructureQItemViewFacade object without a tree view object. But if there is no point in doing so, this should be made clear to the user of the class by not even allowing it 😄
src/dbstructureqitemviewfacade.h
Outdated
| * | ||
| * @return displayName of selectedItem | ||
| */ | ||
| QString displayName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these functions (displayName, name, objectType, schema, sql, object) should be marked as const.
src/dbstructureqitemviewfacade.h
Outdated
| sqlb::ObjectIdentifier object(); | ||
|
|
||
| private: | ||
| QAbstractItemView *m_itemView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a reference instead of a pointer I guess.
src/sqlitedb.cpp
Outdated
| // }); | ||
|
|
||
| // if(ok == false) | ||
| // return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this code should be removed instead of being put in a comment.
src/MainWindow.cpp
Outdated
| popupSchemaDockMenu = new QMenu(this); | ||
| popupSchemaDockMenu->addAction(ui->actionPopupSchemaDockBrowseTable); | ||
| popupSchemaDockMenu->addAction(ui->actionPopupSchemaDockDetachDatabase); | ||
| // popupSchemaDockMenu->addAction(ui->fileDetachAction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old comment here which looks like it can be removed.
28b2a15 to
32c7c5e
Compare
|
I have just pulled out all the changes which aren't directly related to the detach feature (the facade, the removed double attach check, and the removed dirty check for the attach action) and merged them into master. The remaining changes are rebased and squashed into a single commit. So this should be pretty straightforward to review now 😄 |
32c7c5e to
8c79177
Compare
|
I have just fixed another issue which I probably introduced myself when rebasing this branch 😉 Looks good now. Thanks, @horst-p-w-neubauer! 👍 |

detach additional database connection
implements Detach Database #2239