#include "utils/dcqtitemmodel.h"
#include "dcsinglecolumntableview.h"
#include "DNUtils.h"
+#include "dnplugininfo.h"
#include <QLineEdit>
#include <QTableView>
#include <QHeaderView>
DCRenameCellDialog::DCRenameCellDialog(DCContainer *container, DCCreator *creator, DCCell *cell, QWidget *parent) :
- QDialog(parent), d_container(container), d_creator(creator), d_cell(cell)
+ QDialog(parent), d_container(container), d_creator(creator), d_cell(cell), d_pluginLibraryNameComboBox(NULL)
{
setWindowTitle(tr("Rename cell"));
d_textField = new QLineEdit;
- d_textField->setText(QString::fromStdString(cell->getName()));
+ if (d_container->getIsPluginType(cell->getType()))
+ {
+ d_pluginLibraryNameComboBox = new QComboBox;
+ d_pluginLibraryNameComboBox->setEditable(true);
+ d_pluginLibraryNameComboBox->addItems(d_container->getAvailablePluginLibraries());
+
+ DNPluginInfo info = DNPluginInfo::create(cell->getName());
+ d_textField->setText(QString::fromStdString(info.pluginValueName));
+ d_pluginLibraryNameComboBox->setEditText(QString::fromStdString(info.pluginName));
+ }
+ else
+ {
+ d_textField->setText(QString::fromStdString(cell->getName()));
+ }
d_table = new DCSingleColumnTableView();
QStringList headers;
QGridLayout *glayout = new QGridLayout;
glayout->addWidget(new QLabel(tr("name")),0,0);
glayout->addWidget(d_textField,0,1);
+ if (d_pluginLibraryNameComboBox)
+ {
+ glayout->addWidget(new QLabel(tr("plugin")),1,0);
+ glayout->addWidget(d_pluginLibraryNameComboBox,1,1);
+ }
((QVBoxLayout*)layout())->addLayout(glayout);
layout()->addWidget(d_table);
d_statusText = new QLabel;
connect(d_cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
connect(d_table,SIGNAL(selectionChangedSignal(QItemSelection,QItemSelection)), this, SLOT(listSelectionChanged(QItemSelection,QItemSelection)));
connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*)));
+ connect(d_pluginLibraryNameComboBox, SIGNAL(editTextChanged(QString)),this, SLOT(pluginNameChanged(QString)));
if (selection >= 0)
{
bool DCRenameCellDialog::checkInput()
{
+ bool valid = true;
+
d_message->setText("");
d_statusText->setText("");
if (d_selectedPagePath.length() == 0)
{
d_message->setText(tr("Select a page to place the cell"));
+ valid = false;
}
else if (d_textField->text().length() > 0)
{
- std::string path = getFQNString(d_selectedPagePath.toLocal8Bit().data(), d_textField->text().toLocal8Bit().data());
+ QString name;
+ if (d_container->getIsPluginType(d_cell->getType()))
+ {
+ if (d_pluginLibraryNameComboBox->currentText().length() == 0)
+ {
+ d_message->setText(tr("Input plugin name"));
+ valid = false;
+ }
+ else
+ {
+ name = d_container->createPluginCellName(d_textField->text(), d_cell->getType(),d_pluginLibraryNameComboBox->currentText());
+ }
+ }
+ else
+ {
+ name = d_textField->text();
+ }
+
+ std::string path = getFQNString(d_selectedPagePath.toLocal8Bit().data(), name.toLocal8Bit().data());
TKCell *cell = d_container->getCell(path);
if (cell)
{
if (cell != d_cell)
+ {
d_message->setText(tr("The cell name exists"));
+ valid = false;
+ }
}
else
{
d_statusText->setText(QString::fromStdString(path));
- d_okButton->setEnabled(true);
- d_okButton->setDefault(true);
- return true;
}
}
else
{
d_message->setText(tr("Input cell name"));
+ valid = false;
}
- d_okButton->setEnabled(false);
- d_cancelButton->setDefault(true);
- return false;
+
+ if (valid)
+ {
+ d_okButton->setEnabled(true);
+ d_okButton->setDefault(true);
+ }
+ else
+ {
+ d_okButton->setEnabled(false);
+ d_cancelButton->setDefault(true);
+ }
+
+ return valid;
}
void DCRenameCellDialog::textInputChanged(const QString &text)
{
if (checkInput())
{
- d_creator->doCommandRenameCell(this, d_cell, d_selectedPagePath, d_textField->text());
+ QString newName;
+ if (d_container->getIsPluginType(d_cell->getType()))
+ {
+ newName = d_container->createPluginCellName(d_textField->text(), d_cell->getType(), d_pluginLibraryNameComboBox->currentText());
+ }
+ else
+ {
+ newName = d_textField->text();
+ }
+
+ d_creator->doCommandRenameCell(this, d_cell, d_selectedPagePath, newName);
}
}
checkInput();
}
+void DCRenameCellDialog::pluginNameChanged(const QString &text)
+{
+ (void)text;
+ checkInput();
+}
+
void DCRenameCellDialog::commandExecuted(const QUndoCommand *executedCommand)
{
const DCCommand *command = dynamic_cast<const DCCommand*>(executedCommand);