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/databasetableproperties.cpp | |
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/databasetableproperties.cpp')
-rw-r--r-- | src/items/database/databasetableproperties.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
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()); + } +} |