diff options
author | Lukáš Lalinský <lalinsky@gmail.com> | 2008-12-11 12:34:38 +0100 |
---|---|---|
committer | Lukáš Lalinský <lalinsky@gmail.com> | 2008-12-11 12:34:38 +0100 |
commit | 3b49b6a0d4c4d2ee94faeff207da10c452f70b07 (patch) | |
tree | 69ed42124a9b94be0f126c3b78e86f23812f3b3f /src/items/database | |
parent | f4d9a3f2ad1896c5117ce1d3af3b8b3a433b3961 (diff) | |
download | dbmodel-3b49b6a0d4c4d2ee94faeff207da10c452f70b07.tar.xz |
Support for generic diagram item properties editors + add relationship props editor UI
Diffstat (limited to 'src/items/database')
-rw-r--r-- | src/items/database/columnlistview.cpp | 3 | ||||
-rw-r--r-- | src/items/database/database.pri | 9 | ||||
-rw-r--r-- | src/items/database/databaserelationship.cpp | 7 | ||||
-rw-r--r-- | src/items/database/databaserelationship.h | 2 | ||||
-rw-r--r-- | src/items/database/databaserelationshipproperties.cpp | 60 | ||||
-rw-r--r-- | src/items/database/databaserelationshipproperties.h | 43 | ||||
-rw-r--r-- | src/items/database/databasetable.cpp | 7 | ||||
-rw-r--r-- | src/items/database/databasetable.h | 2 | ||||
-rw-r--r-- | src/items/database/databasetableproperties.cpp | 149 | ||||
-rw-r--r-- | src/items/database/databasetableproperties.h (renamed from src/items/database/tableproperties.h) | 31 | ||||
-rw-r--r-- | src/items/database/tableproperties.cpp | 97 | ||||
-rw-r--r-- | src/items/database/tableproperties.ui | 137 |
12 files changed, 292 insertions, 255 deletions
diff --git a/src/items/database/columnlistview.cpp b/src/items/database/columnlistview.cpp index 4edb4ee..cbfb4b9 100644 --- a/src/items/database/columnlistview.cpp +++ b/src/items/database/columnlistview.cpp @@ -23,6 +23,9 @@ ColumnListView::ColumnListView(QWidget *parent) : QTreeView(parent) { + setRootIsDecorated(false); + setItemsExpandable(false); + setExpandsOnDoubleClick(false); setModel(new ColumnListModel(this)); } diff --git a/src/items/database/database.pri b/src/items/database/database.pri index 53d4f6f..9a7ebe9 100644 --- a/src/items/database/database.pri +++ b/src/items/database/database.pri @@ -7,8 +7,9 @@ SOURCES += \ columnlistmodel.cpp \ columnlistview.cpp \ databasetable.cpp \ + databasetableproperties.cpp \ databaserelationship.cpp \ - tableproperties.cpp + databaserelationshipproperties.cpp HEADERS += \ databasecommands.h \ @@ -17,8 +18,6 @@ HEADERS += \ columnlistmodel.h \ columnlistview.h \ databasetable.h \ + databasetableproperties.h \ databaserelationship.h \ - tableproperties.h - -FORMS += \ - tableproperties.ui + databaserelationshipproperties.h diff --git a/src/items/database/databaserelationship.cpp b/src/items/database/databaserelationship.cpp index 8eb0e2f..5adda58 100644 --- a/src/items/database/databaserelationship.cpp +++ b/src/items/database/databaserelationship.cpp @@ -19,6 +19,7 @@ #include "diagramdocument.h" #include "databasetable.h" #include "databaserelationship.h" +#include "databaserelationshipproperties.h" #include "range.h" DatabaseRelationship::DatabaseRelationship(DiagramItem *parent) @@ -249,3 +250,9 @@ DatabaseRelationship::saveToXml(QDomDocument doc, QDomElement element) { DiagramConnection::saveToXml(doc, element); } + +DiagramItemProperties * +DatabaseRelationship::createPropertiesEditor(QWidget *parent) +{ + return new DatabaseRelationshipProperties(parent); +} diff --git a/src/items/database/databaserelationship.h b/src/items/database/databaserelationship.h index e9e26d0..0447d3b 100644 --- a/src/items/database/databaserelationship.h +++ b/src/items/database/databaserelationship.h @@ -47,6 +47,8 @@ public: void updatePositions(); + static DiagramItemProperties *createPropertiesEditor(QWidget *parent = 0); + protected slots: void updateLayout(); diff --git a/src/items/database/databaserelationshipproperties.cpp b/src/items/database/databaserelationshipproperties.cpp new file mode 100644 index 0000000..cb3866d --- /dev/null +++ b/src/items/database/databaserelationshipproperties.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2008 Lukas Lalinsky +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#include <QCheckBox> +#include <QGridLayout> +#include <QLabel> +#include <QLineEdit> +#include "databaserelationshipproperties.h" + +class DatabaseRelationshipProperties::PrivateData +{ +public: + PrivateData() + {} + + QWidget *nameEdit; + QCheckBox *generateNameCheckBox; +}; + +DatabaseRelationshipProperties::DatabaseRelationshipProperties(QWidget *parent) + : DiagramItemProperties(parent), d(new PrivateData) +{ + addPage(tr("&Relationship"), createRelationshipPage()); +} + +QWidget * +DatabaseRelationshipProperties::createRelationshipPage() +{ + QWidget *page = new QWidget(this); + QGridLayout *layout = new QGridLayout(page); + + d->nameEdit = new QLineEdit(page); + layout->addWidget(new QLabel(tr("Name:"), page), 0, 0); + layout->addWidget(d->nameEdit, 0, 1); + d->generateNameCheckBox = new QCheckBox(tr("Generated"), page); + connect(d->generateNameCheckBox, SIGNAL(toggled(bool)), d->nameEdit, SLOT(setDisabled(bool))); + d->generateNameCheckBox->setChecked(true); + layout->addWidget(d->generateNameCheckBox, 0, 2); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 1, 0, 1, 3); + + return page; +} + +void +DatabaseRelationshipProperties::switchCurrentItem(DiagramItem *oldItem, DiagramItem *newItem) +{ +} diff --git a/src/items/database/databaserelationshipproperties.h b/src/items/database/databaserelationshipproperties.h new file mode 100644 index 0000000..2cf8f29 --- /dev/null +++ b/src/items/database/databaserelationshipproperties.h @@ -0,0 +1,43 @@ +// Copyright (C) 2008 Lukas Lalinsky +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#ifndef DATABASERELATIONSHIPPROPERTIES_H +#define DATABASERELATIONSHIPPROPERTIES_H + +#include "diagramitemproperties.h" +class DatabaseRelationship; + +class DatabaseRelationshipProperties : public DiagramItemProperties +{ + Q_OBJECT + +public: + DatabaseRelationshipProperties(QWidget *parent = 0); + DatabaseRelationship *currentRelationship(); + +protected: + void switchCurrentItem(DiagramItem *oldItem, DiagramItem *newItem); + +protected slots: + +private: + class PrivateData; + PrivateData *d; + + QWidget *createRelationshipPage(); +}; + +#endif diff --git a/src/items/database/databasetable.cpp b/src/items/database/databasetable.cpp index 059284f..5c80629 100644 --- a/src/items/database/databasetable.cpp +++ b/src/items/database/databasetable.cpp @@ -18,6 +18,7 @@ #include <QMimeData> #include <QDebug> #include "databasetable.h" +#include "databasetableproperties.h" #include "diagramdocument.h" #include "column.h" #include "columnlist.h" @@ -220,3 +221,9 @@ DatabaseTable::saveToXml(QDomDocument doc, QDomElement element) appendStringElement(doc, columnElement, "notes", column->notes()); } } + +DiagramItemProperties * +DatabaseTable::createPropertiesEditor(QWidget *parent) +{ + return new DatabaseTableProperties(parent); +} diff --git a/src/items/database/databasetable.h b/src/items/database/databasetable.h index 4402586..da03a1a 100644 --- a/src/items/database/databasetable.h +++ b/src/items/database/databasetable.h @@ -57,6 +57,8 @@ public: // QMimeData *toMimeData(); + static DiagramItemProperties *createPropertiesEditor(QWidget *parent = 0); + signals: void propertyChanged(const QString &name, const QVariant &value); diff --git a/src/items/database/databasetableproperties.cpp b/src/items/database/databasetableproperties.cpp new file mode 100644 index 0000000..4c7b138 --- /dev/null +++ b/src/items/database/databasetableproperties.cpp @@ -0,0 +1,149 @@ +// Copyright (C) 2008 Lukas Lalinsky +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#include <QGridLayout> +#include <QLabel> +#include <QLineEdit> +#include <QPushButton> +#include "commands.h" +#include "columnlist.h" +#include "columnlistview.h" +#include "databasetable.h" +#include "databasetableproperties.h" +#include "diagramdocument.h" + +class DatabaseTableProperties::PrivateData +{ +public: + PrivateData() + {} + + QLineEdit *nameEdit; + ColumnListView *columnListView; + QPushButton *addColumnButton; + QPushButton *removeColumnButton; + QPushButton *moveColumnUpButton; + QPushButton *moveColumnDownButton; +}; + +DatabaseTableProperties::DatabaseTableProperties(QWidget *parent) + : DiagramItemProperties(parent), d(new PrivateData) +{ + addPage(tr("&Table"), createTablePage()); + addPage(tr("&Columns"), createColumnsPage()); +} + +DatabaseTable * +DatabaseTableProperties::currentTable() +{ + return static_cast<DatabaseTable *>(currentItem()); +} + +QWidget * +DatabaseTableProperties::createTablePage() +{ + QWidget *page = new QWidget(this); + QGridLayout *layout = new QGridLayout(page); + + d->nameEdit = new QLineEdit(page); + connect(d->nameEdit, SIGNAL(textEdited(const QString &)), SLOT(setTableName(const QString &))); + layout->addWidget(new QLabel(tr("Name:"), page), 0, 0); + layout->addWidget(d->nameEdit, 0, 1); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 1, 0, 1, 2); + + return page; +} + +QWidget * +DatabaseTableProperties::createColumnsPage() +{ + QWidget *page = new QWidget(this); + QGridLayout *layout = new QGridLayout(page); + + d->columnListView = new ColumnListView(page); + layout->addWidget(d->columnListView, 0, 0, 5, 1); + + connect(d->columnListView->selectionModel(), + SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), + SLOT(updateColumnSelection())); + + d->addColumnButton = new QPushButton(tr("&Add"), page); + d->removeColumnButton = new QPushButton(tr("&Remove"), page); + d->moveColumnUpButton = new QPushButton(tr("Move &Up"), page); + d->moveColumnDownButton = new QPushButton(tr("Move &Down"), page); + layout->addWidget(d->addColumnButton, 0, 1); + layout->addWidget(d->removeColumnButton, 1, 1); + layout->addWidget(d->moveColumnUpButton, 2, 1); + layout->addWidget(d->moveColumnDownButton, 3, 1); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 4, 1, 1, 1); + + connect(d->addColumnButton, SIGNAL(clicked()), d->columnListView, SLOT(addColumn())); + connect(d->removeColumnButton, SIGNAL(clicked()), d->columnListView, SLOT(removeColumn())); + connect(d->moveColumnUpButton, SIGNAL(clicked()), d->columnListView, SLOT(moveColumnUp())); + connect(d->moveColumnDownButton, SIGNAL(clicked()), d->columnListView, SLOT(moveColumnDown())); + + return page; +} + +void +DatabaseTableProperties::switchCurrentItem(DiagramItem *oldItem, DiagramItem *) +{ + if (oldItem) + disconnect(oldItem, 0, this, 0); + DatabaseTable *table = currentTable(); + if (table) { + d->nameEdit->setText(table->name()); + d->columnListView->setColumnList(table->columnList()); + connect(table, SIGNAL(propertyChanged(const QString &, const QVariant &)), SLOT(updateProperty(const QString &, const QVariant &))); + } + else { + d->nameEdit->clear(); + d->columnListView->setColumnList(NULL); + } + updateColumnSelection(); +} + +void +DatabaseTableProperties::updateProperty(const QString &name, const QVariant &value) +{ + if (name == "name") { + d->nameEdit->setText(value.toString()); + } +} + +void +DatabaseTableProperties::setTableName(const QString &name) +{ + DatabaseTable *table = currentTable(); + table->document()->undoStack()->push(new SetObjectPropertyCommand(table, "name", name)); +} + +void +DatabaseTableProperties::updateColumnSelection() +{ + QList<int> columns = d->columnListView->selectedColumns(); + if (columns.isEmpty()) { + d->removeColumnButton->setEnabled(false); + d->moveColumnUpButton->setEnabled(false); + d->moveColumnDownButton->setEnabled(false); + } + else { + int index = columns[0]; + d->removeColumnButton->setEnabled(true); + d->moveColumnUpButton->setEnabled(index > 0); + d->moveColumnDownButton->setEnabled(index + 1 < currentTable()->columnList()->columnCount()); + } +} diff --git a/src/items/database/tableproperties.h b/src/items/database/databasetableproperties.h index 6ad51a5..cd7fa14 100644 --- a/src/items/database/tableproperties.h +++ b/src/items/database/databasetableproperties.h @@ -14,35 +14,34 @@ // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -#ifndef TABLEPROPERTIES_H -#define TABLEPROPERTIES_H - -#include <QWidget> -#include <QTreeWidget> -#include "ui_tableproperties.h" +#ifndef DATABASETABLEPROPERTIES_H +#define DATABASETABLEPROPERTIES_H +#include "diagramitemproperties.h" class DatabaseTable; -class MainWindow; -class TableProperties : public QWidget +class DatabaseTableProperties : public DiagramItemProperties { Q_OBJECT public: - TableProperties(MainWindow *window, QWidget *parent = 0); + DatabaseTableProperties(QWidget *parent = 0); + DatabaseTable *currentTable(); - DatabaseTable *table() { return m_table; } - void setTable(DatabaseTable *table); +protected: + void switchCurrentItem(DiagramItem *oldItem, DiagramItem *newItem); protected slots: - void setSelectedTableName(const QString &name); - void updateColumnSelection(); void updateProperty(const QString &name, const QVariant &value); + void updateColumnSelection(); + void setTableName(const QString &name); private: - MainWindow *m_window; - DatabaseTable *m_table; - Ui_TableProperties ui; + class PrivateData; + PrivateData *d; + + QWidget *createTablePage(); + QWidget *createColumnsPage(); }; #endif diff --git a/src/items/database/tableproperties.cpp b/src/items/database/tableproperties.cpp deleted file mode 100644 index 11b3fc4..0000000 --- a/src/items/database/tableproperties.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2008 Lukas Lalinsky -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -#include "tableproperties.h" -#include "databasetable.h" -#include "mainwindow.h" -#include "commands.h" -#include "column.h" -#include <QCheckBox> -#include <QDebug> - -TableProperties::TableProperties(MainWindow *window, QWidget *parent) - : QWidget(parent), m_window(window), m_table(0) -{ - ui.setupUi(this); - setTable(0); - connect(ui.nameEdit, - SIGNAL(textEdited(const QString &)), - SLOT(setSelectedTableName(const QString &))); - connect(ui.addColumnButton, SIGNAL(clicked()), ui.columnsWidget, SLOT(addColumn())); - connect(ui.removeColumnButton, SIGNAL(clicked()), ui.columnsWidget, SLOT(removeColumn())); - connect(ui.moveColumnUpButton, SIGNAL(clicked()), ui.columnsWidget, SLOT(moveColumnUp())); - connect(ui.moveColumnDownButton, SIGNAL(clicked()), ui.columnsWidget, SLOT(moveColumnDown())); - connect(ui.columnsWidget->selectionModel(), - SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - SLOT(updateColumnSelection())); -} - -void -TableProperties::setSelectedTableName(const QString &name) -{ - if (m_table) { - m_window->currentUndoStack()->push(new SetObjectPropertyCommand(m_table, "name", name)); - } -} - -void -TableProperties::setTable(DatabaseTable *table) -{ - // Disconnect all connections from the previous table - if (m_table) { - disconnect(m_table, 0, this, 0); - } - - m_table = NULL; - if (table == NULL) { - setEnabled(false); - ui.nameEdit->clear(); - ui.columnsWidget->setColumnList(0); - } - else { - setEnabled(true); - ui.nameEdit->setText(table->name()); - ui.columnsWidget->setColumnList(table->columnList()); - connect(table, SIGNAL(propertyChanged(const QString &, const QVariant &)), SLOT(updateProperty(const QString &, const QVariant &))); - } - m_table = table; - updateColumnSelection(); -} - -void -TableProperties::updateProperty(const QString &name, const QVariant &value) -{ - if (name == "name") { - ui.nameEdit->setText(value.toString()); - } -} - -void -TableProperties::updateColumnSelection() -{ - QList<int> columns = ui.columnsWidget->selectedColumns(); - if (columns.isEmpty()) { - ui.removeColumnButton->setEnabled(false); - ui.moveColumnUpButton->setEnabled(false); - ui.moveColumnDownButton->setEnabled(false); - } - else { - int index = columns[0]; - ui.removeColumnButton->setEnabled(true); - ui.moveColumnUpButton->setEnabled(index > 0); - ui.moveColumnDownButton->setEnabled(index + 1 < m_table->columnList()->columnCount()); - } -} diff --git a/src/items/database/tableproperties.ui b/src/items/database/tableproperties.ui deleted file mode 100644 index 0ad531a..0000000 --- a/src/items/database/tableproperties.ui +++ /dev/null @@ -1,137 +0,0 @@ -<ui version="4.0" > - <class>TableProperties</class> - <widget class="QWidget" name="TableProperties" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>471</width> - <height>192</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout" > - <property name="margin" > - <number>0</number> - </property> - <item> - <widget class="QTabWidget" name="tabWidget" > - <property name="currentIndex" > - <number>0</number> - </property> - <widget class="QWidget" name="tab" > - <attribute name="title" > - <string>&Definition</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_2" > - <item row="0" column="0" > - <widget class="QLabel" name="label" > - <property name="text" > - <string>Name:</string> - </property> - </widget> - </item> - <item row="0" column="1" > - <widget class="QLineEdit" name="nameEdit" /> - </item> - <item row="1" column="0" colspan="2" > - <spacer name="verticalSpacer" > - <property name="orientation" > - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0" > - <size> - <width>158</width> - <height>113</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_2" > - <attribute name="title" > - <string>&Columns</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_3" > - <item rowspan="5" row="0" column="0" > - <widget class="ColumnListView" name="columnsWidget" > - <property name="rootIsDecorated" > - <bool>false</bool> - </property> - <property name="itemsExpandable" > - <bool>false</bool> - </property> - <property name="expandsOnDoubleClick" > - <bool>false</bool> - </property> - </widget> - </item> - <item row="0" column="1" > - <widget class="QPushButton" name="addColumnButton" > - <property name="toolTip" > - <string>Add new column</string> - </property> - <property name="text" > - <string>&Add</string> - </property> - </widget> - </item> - <item row="1" column="1" > - <widget class="QPushButton" name="removeColumnButton" > - <property name="toolTip" > - <string>Remove selected column</string> - </property> - <property name="text" > - <string>&Remove</string> - </property> - </widget> - </item> - <item row="2" column="1" > - <widget class="QPushButton" name="moveColumnUpButton" > - <property name="toolTip" > - <string>Move selected column up</string> - </property> - <property name="text" > - <string>Move &Up</string> - </property> - </widget> - </item> - <item row="3" column="1" > - <widget class="QPushButton" name="moveColumnDownButton" > - <property name="toolTip" > - <string>Move selected column down</string> - </property> - <property name="text" > - <string>Move &Down</string> - </property> - </widget> - </item> - <item row="4" column="1" > - <spacer name="verticalSpacer_2" > - <property name="orientation" > - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0" > - <size> - <width>17</width> - <height>21</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>ColumnListView</class> - <extends>QTreeView</extends> - <header>items/database/columnlistview.h</header> - </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> |