From: tkawata Date: Sun, 23 Dec 2012 15:32:24 +0000 (+0900) Subject: [denncoCreator] Implemented cell code scripts tree view. X-Git-Url: http://git.osdn.net/view?p=dennco%2FdenncoCreator.git;a=commitdiff_plain;h=53bf1c1b4b69b3659f17c93182ce07203011ceb7 [denncoCreator] Implemented cell code scripts tree view. --- diff --git a/Source/cellcodescripttreeview/dccellcodescripttreeviewwidget.cpp b/Source/cellcodescripttreeview/dccellcodescripttreeviewwidget.cpp new file mode 100644 index 0000000..daae68f --- /dev/null +++ b/Source/cellcodescripttreeview/dccellcodescripttreeviewwidget.cpp @@ -0,0 +1,419 @@ +// Copyright (c) 2012 Dennco Project +// +// 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 3 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, see . + +// +// Created by tkawata on Dec-24/2012. +// +#include "dccellcodescripttreeviewwidget.h" + +#include "dccreator.h" +#include "dccontainer.h" +#include "dccellcode.h" +#include "mainwindow.h" +#include "dialog/dcaddcellcodeclassdialog.h" +#include "utils/dcqtitemmodel.h" + +const static QString S_ScriptTreeStyle = + "QTreeView::branch:!has-children:adjoins-item {" + "border-image: url(:/docIcon.png) 0;" + "}"; + +class ScriptTreeModelItem : public DCQtItemModelItem +{ + QVector mItemUserData; +public: + ScriptTreeModelItem(const QVector &data, DCQtItemModelItem *parent) + : DCQtItemModelItem(data, parent), mItemUserData(data) + { + } + + ScriptTreeModelItem(const QStringList &headers, DCQtItemModelItem *parent = 0) + : DCQtItemModelItem(headers, parent) + { + QVector rootData; + foreach (QString header, headers) + { + rootData << header; + } + mItemUserData = rootData; + } + + virtual ~ScriptTreeModelItem() + { + } + + + QVariant userData(int column) const + { + return mItemUserData.value(column); + } + + virtual bool insertChildren(int position, int count, int columns) + { + if (position < 0 || position > mChildItems.size()) + return false; + + for (int row = 0; row < count; ++row) { + QVector data(columns); + DCQtItemModelItem *item = new ScriptTreeModelItem(data, this); + mChildItems.insert(position, item); + } + + return true; + } + + virtual bool insertColumns(int position, int columns) + { + if (!DCQtItemModelItem::insertColumns(position, columns)) + return false; + + for (int column = 0; column < columns; ++column) + mItemUserData.insert(position, QVariant()); + + return true; + } + + virtual bool removeColumns(int position, int columns) + { + if (!DCQtItemModelItem::removeColumns(position, columns)) + return false; + + for (int column = 0; column < columns; ++column) + mItemUserData.remove(position); + + return true; + } + + bool setUserData(int column, const QVariant &value) + { + if (column < 0 || column >= mItemUserData.size()) + return false; + + mItemUserData[column] = value; + return true; + } +}; + +class ScriptTreeModel : public DCQtItemModel +{ +public: + ScriptTreeModel(const QStringList &headers, QObject *parent = 0) + : DCQtItemModel(headers, new ScriptTreeModelItem(headers), parent) + {} + + virtual ~ScriptTreeModel() + { + } + + + virtual QVariant data(const QModelIndex &index, int role) const + { + if (!index.isValid()) + return QVariant(); + + if (role == Qt::UserRole) + { + ScriptTreeModelItem *item = dynamic_cast(getItem(index)); + if (item) + return item->userData(index.column()); + } + else + { + return DCQtItemModel::data(index,role); + } + + return QVariant(); + } + + + virtual bool setData(const QModelIndex &index, const QVariant &value, int role) + { + bool result = false; + if (role == Qt::UserRole) + { + ScriptTreeModelItem *item = dynamic_cast(getItem(index)); + if (item) + result = item->setUserData(index.column(), value); + } + else + { + return DCQtItemModel::setData(index,value,role); + } + + if (result) + emit dataChanged(index, index); + + return result; + } + +}; + + +DCCellCodeScriptTreeViewWidget::DCCellCodeScriptTreeViewWidget(QWidget *parent, DCCreator *creator) : + QTreeView(parent), d_creator(creator) +{ + QStringList headers; + headers << "Name"; + d_model = new ScriptTreeModel(headers); + + setIndentation(15); + setModel(d_model); + setStyleSheet(S_ScriptTreeStyle); + + connect(d_creator, SIGNAL(contentRootPathChanged(const void*, QString)), this, SLOT(contentRootPathChanged(const void*, QString))); + connect(d_creator, SIGNAL(destroyed(QObject*)), this, SLOT(creatorDestroyed())); + connect(d_creator, SIGNAL(commandExecuted(const QUndoCommand*)), this, SLOT(commandExecuted(const QUndoCommand*))); + + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(doContextMenu(const QPoint&))); +} + +DCCellCodeScriptTreeViewWidget::~DCCellCodeScriptTreeViewWidget() +{ + if (d_model) + d_model->deleteLater(); +} + + +void DCCellCodeScriptTreeViewWidget::rebuildModel() +{ + if (!d_model) + return; + + if (!d_creator || !d_creator->getCurrentContainer()) + return; + + d_model->removeAllItems(); + + QVector pathNames; + DCContainer *container = d_creator->getCurrentContainer(); + const TKCellCodeMap* cellCodeScripts = container->getCellCodes(); + TKCellCodeMap::const_iterator it = cellCodeScripts->begin(); + while(it != cellCodeScripts->end()) + { + pathNames.append(QString::fromStdString(it->first)); + it++; + } + qSort(pathNames); + + QVector::const_iterator sit = pathNames.begin(); + while(sit != pathNames.end()) + { + QStringList nodes = (*sit).split("/"); + + QModelIndex index; + if (nodes.length() < 1) + { + ++sit; + continue; + } + + for (int i = 1; i < nodes.length() -1; i++) + { + QString n = nodes.at(i); + index = childNode(n, index); + } + QString ln = nodes.at(nodes.length()-1); + int p = ln.lastIndexOf("#"); + if (p <= 0) + { + //invalid + ++sit; + continue; + } + QString fName = ln.left(p); + QString cName = ln.mid(p+1); + index = childNode(fName, index); + index = childNode(cName, index); + d_model->setData(index, QVariant(*sit), Qt::UserRole); + ++sit; + } + expandAll(); +} + +void DCCellCodeScriptTreeViewWidget::selectPath(const QString path) +{ + QStringList nodes = path.split("/"); + + QModelIndex index; + if (path.length() < 1) + { + return; + } + + for (int i = 1; i < nodes.length() -1; i++) + { + QString n = nodes.at(i); + index = childNode(n, index, false); + if (!index.isValid()) + break; + } + + QString ln = nodes.at(nodes.length()-1); + int p = ln.lastIndexOf("#"); + if (p>0) + { + QString fName = ln.left(p); + QString cName = ln.mid(p+1); + + index = childNode(fName, index, false); + if (index.isValid()) + { + index = childNode(cName, index, false); + selectionModel()->select(index, QItemSelectionModel::Select); + } + } +} + +QModelIndex DCCellCodeScriptTreeViewWidget::childNode(const QString& nodeName, const QModelIndex& currentIndex, bool createWhenNotExist) +{ + QModelIndex childIndex; + + for (int j = 0; j < d_model->rowCount(currentIndex); j++) + { + if (d_model->data(d_model->index(j,0,currentIndex), Qt::EditRole).toString() == nodeName) + { + childIndex = d_model->index(j,0,currentIndex); + break; + } + } + if (!childIndex.isValid() && createWhenNotExist) + { + int position = d_model->rowCount(currentIndex);; + d_model->insertRows(position,1,currentIndex); + childIndex = d_model->index(position,0,currentIndex); + d_model->setData(childIndex,QVariant(nodeName)); + } + return childIndex; +} + +void DCCellCodeScriptTreeViewWidget::contentRootPathChanged(const void *requester, QString rootPath) +{ + rebuildModel(); +} + +void DCCellCodeScriptTreeViewWidget::creatorDestroyed() +{ + d_creator = NULL; +} + +void DCCellCodeScriptTreeViewWidget::commandExecuted(const QUndoCommand *) +{ + rebuildModel(); +} + +void DCCellCodeScriptTreeViewWidget::doContextMenu(const QPoint& pos) +{ + if (!d_creator || !d_creator->getCurrentContainer()) + return; + + QPoint globalPos = mapToGlobal(pos); + + QMenu menu; + + QAction *addCellCodeScriptAction = NULL; + QAction *removeCellCodeScriptAction = NULL; + + QString path = ""; + QModelIndex index; + QModelIndexList indexes = selectedIndexes(); + addCellCodeScriptAction = menu.addAction(tr("Add cell code script...")); + if (indexes.length() > 0) + { + index = indexes.at(0); + QString pathName = d_model->data(index, Qt::UserRole).toString(); + if (!pathName.isEmpty() && pathName.length() > 0) + { + removeCellCodeScriptAction = menu.addAction(tr("Remove...")); + path = pathName; + } + else + { + QModelIndex topIndex; + while (index != topIndex) + { + path.prepend(d_model->data(index, Qt::EditRole).toString()); + index = index.parent(); + path.prepend("/"); + + } + } + } + + QAction* selectedItem = menu.exec(globalPos); + if (selectedItem == addCellCodeScriptAction) + { + int s = path.lastIndexOf("#"); + if (s>0) + { + path = path.left(s); + } + DCAddCellCodeClassDialog dialog(d_creator, path); + dialog.exec(); + QString addedPathName = dialog.getAddedCellCodeClassName(); + if (!addedPathName.isEmpty() && addedPathName.length()>0) + { + selectPath(addedPathName); + } + } + else if (selectedItem == removeCellCodeScriptAction) + { + qDebug() << "Remove cell code script!!"; + qDebug() << path; + DCContainer *container = d_creator->getCurrentContainer(); + if (container) + { + DCCellCode *cellCode = dynamic_cast(container->getCellCode(path.toStdString())); + if (cellCode) + { + QString msg = "Deleting Cell code script:\n" + path + "\nDo you want to continue?"; + QMessageBox msgBox(QMessageBox::Warning, tr("Delete cell code script"), msg); + msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes); + int ret = msgBox.exec(); + if (ret == QMessageBox::Yes) + { + d_creator->doCommandRemoveCellCode(this, container, cellCode); + } + } + } + } +} + +void DCCellCodeScriptTreeViewWidget::mouseDoubleClickEvent(QMouseEvent *event) +{ + (void) event; + + if (!d_creator || !d_creator->getCurrentContainer()) + return; + + QModelIndex index = currentIndex(); + if (index.isValid()) + { + QString pathName = d_model->data(index, Qt::UserRole).toString(); + + if (!pathName.isEmpty() && pathName.length()>0) + { + DCContainer *container = d_creator->getCurrentContainer(); + if (container) + { + DCCellCode *cellCode = dynamic_cast(container->getCellCode(pathName.toStdString())); + if (cellCode) + { + MainWindow::openExternalEditorFor(cellCode->getWorkFilePathForCellCodeScript()); + } + } + } + } +} diff --git a/Source/cellcodescripttreeview/dccellcodescripttreeviewwidget.h b/Source/cellcodescripttreeview/dccellcodescripttreeviewwidget.h new file mode 100644 index 0000000..dc2bc7a --- /dev/null +++ b/Source/cellcodescripttreeview/dccellcodescripttreeviewwidget.h @@ -0,0 +1,55 @@ +// Copyright (c) 2012 Dennco Project +// +// 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 3 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, see . + +// +// Created by tkawata on Dec-24/2012. +// +#ifndef DCCELLCODESCRIPTTREEVIEWWIDGET_H +#define DCCELLCODESCRIPTTREEVIEWWIDGET_H + +#include +#include +#include + +class DCCreator; +class DCQtItemModel; + +class DCCellCodeScriptTreeViewWidget : public QTreeView +{ + Q_OBJECT + DCQtItemModel *d_model; + DCCreator *d_creator; + + void rebuildModel(); + QModelIndex childNode(const QString& nodeName, const QModelIndex& currentIndex, bool createWhenNotExist = true); + void selectPath(const QString path); + +public: + DCCellCodeScriptTreeViewWidget(QWidget *parent, DCCreator *creator); + ~DCCellCodeScriptTreeViewWidget(); + +protected: + virtual void mouseDoubleClickEvent(QMouseEvent *event); + +signals: + +public slots: + void contentRootPathChanged(const void *requester, QString rootPath); + void creatorDestroyed(); + void commandExecuted(const QUndoCommand*); + void doContextMenu(const QPoint&); +}; + +#endif // DCCELLCODESCRIPTTREEVIEWWIDGET_H diff --git a/Source/codeeditor/dccellscriptseditorpagewidget.cpp b/Source/codeeditor/dccellscriptseditorpagewidget.cpp index 73d91d2..f9e9e07 100644 --- a/Source/codeeditor/dccellscriptseditorpagewidget.cpp +++ b/Source/codeeditor/dccellscriptseditorpagewidget.cpp @@ -21,7 +21,6 @@ #include #include -#include "dccreator.h" #include "dccontainer.h" #include "dccodeeditor.h" #include "dccell.h" @@ -136,13 +135,6 @@ DCCellScriptsEditorPageWidget::~DCCellScriptsEditorPageWidget() disconnect(d_cell, 0, this, 0); } this->disconnect(); - - QList::iterator it = d_processes.begin(); - while (it != d_processes.end()) - { - delete (*it); - it = d_processes.erase(it); - } } //slot @@ -248,7 +240,7 @@ void DCCellScriptsEditorPageWidget::useExternalEditorForCustomScriptPressed() } else { - if (openExternalEditor(d_cell->getWorkFilePathForCustomScript())) + if (MainWindow::openExternalEditorFor(d_cell->getWorkFilePathForCustomScript())) { saveCustomScriptOnlyToFile(true); d_customScriptExternalMode = true; @@ -274,7 +266,7 @@ void DCCellScriptsEditorPageWidget::useExternalEditorForCellCodeScriptPressed() else { DCCellCode *cellCode = d_cell->getCellCode(); - if (openExternalEditor(cellCode->getWorkFilePathForCellCodeScript())) + if (MainWindow::openExternalEditorFor(cellCode->getWorkFilePathForCellCodeScript())) { saveCellCodeScriptOnlyToFile(true); d_cellCodeScriptExternalMode = true; @@ -298,53 +290,6 @@ void DCCellScriptsEditorPageWidget::updateModifiedStatus() } } -bool DCCellScriptsEditorPageWidget::openExternalEditor(const QString& path) -{ - QString editorPath = MainWindow::readSettingsForExternalScriptEditorPath(); - if (editorPath.isEmpty() || editorPath.length() == 0) - { - DCCodeEditorExternalEditorSettingDialog dialog; - dialog.exec(); - editorPath = MainWindow::readSettingsForExternalScriptEditorPath(); - } - if (editorPath.isEmpty() || editorPath.length() == 0) - return false; - - QString parameterOrg = MainWindow::readSettingsForExternalScriptEditorParameters(); - QString parameter = ""; - int i = 0; - int j = parameterOrg.indexOf(QRegExp("%F[ \t\"']|%F$"),i); - while (j >= 0) - { - parameter += parameterOrg.mid(i, j-i); - parameter += path; - i = j + 2; - if (i > parameterOrg.length()) - break; - j = parameterOrg.indexOf(QRegExp("%F[ \t\"']|%F$"),i); - } - if (i < parameterOrg.length()) - parameter += parameterOrg.mid(i); - - QList::iterator it = d_processes.begin(); - while (it != d_processes.end()) - { - if ((*it)->state() != QProcess::Running) - { - delete (*it); - it = d_processes.erase(it); - } - else - ++it; - } - QProcess *newProcess = new QProcess; - newProcess->start("\"" + editorPath + "\" " + parameter); - - d_processes.append(newProcess); - - return true; -} - bool DCCellScriptsEditorPageWidget::getIsModified() const { return d_modified; diff --git a/Source/codeeditor/dccellscriptseditorpagewidget.h b/Source/codeeditor/dccellscriptseditorpagewidget.h index 524af2b..4774f99 100644 --- a/Source/codeeditor/dccellscriptseditorpagewidget.h +++ b/Source/codeeditor/dccellscriptseditorpagewidget.h @@ -22,7 +22,6 @@ #include #include #include -#include #include "dceditscriptfolder.h" @@ -50,13 +49,11 @@ class DCCellScriptsEditorPageWidget : public QWidget QPushButton *d_cellCodeScriptEditExternalButton; bool d_customScriptExternalMode; bool d_cellCodeScriptExternalMode; - QList d_processes; bool loadCustomScript(bool forceReload = false); bool loadCellCodeScript(bool forceReload = false); bool loadScripts(); void updateModifiedStatus(); - bool openExternalEditor(const QString& path); public: DCCellScriptsEditorPageWidget(DCCell *targetCell, QWidget *parent = 0); diff --git a/Source/dccreator.cpp b/Source/dccreator.cpp index c5909e5..03041e0 100644 --- a/Source/dccreator.cpp +++ b/Source/dccreator.cpp @@ -513,6 +513,11 @@ void DCCreator::doCommandRemoveCell(const void *requester, DCContainer *containe DCCommandUtil::postRemoveCellCommand(requester, this, container, cell); } +void DCCreator::doCommandRemoveCellCode(const void *requester, DCContainer *container, DCCellCode *cellCode) +{ + DCCommandUtil::postRemoveCellCodeCommand(requester, this, container, cellCode); +} + void DCCreator::doCommandAddPage(const void *requester, const QString &containerBasedPath) { DCCommandUtil::postAddPageCommand(requester, this, containerBasedPath); diff --git a/Source/dccreator.h b/Source/dccreator.h index a2ccd53..ab7433e 100644 --- a/Source/dccreator.h +++ b/Source/dccreator.h @@ -110,6 +110,7 @@ public: void doCommandRenameCell(const void *requester, DCCell *cell, const QString& newContainerBasedPath, const QString& newName); void doCommandChangeCellType(const void *requester, DCCell *cell, const QString& newType); void doCommandRemoveCell(const void *requester, DCContainer *container, DCCell* cell); + void doCommandRemoveCellCode(const void *requester, DCContainer *container, DCCellCode* cellCode); void doCommandAddPage(const void *requester, const QString& containerBasedPath); void doCommandMovePage(const void *requester, const QString &oldContainerBasedPath, const QString &newContainerBasedPath); void doCommandRemovePage(const void *requester, DCVCPage *page); diff --git a/Source/denncoCreator.pro b/Source/denncoCreator.pro index 7423ca2..16aa295 100644 --- a/Source/denncoCreator.pro +++ b/Source/denncoCreator.pro @@ -1,7 +1,7 @@ QT += core gui xml opengl sql webkit network -INCLUDEPATH += engine/layer1 engine/layer2 visualizer visualizer/component visualizer/toolwindow visualizer/component/shape treeview codeeditor receptoreditor axoneditor axonterminaleditor +INCLUDEPATH += engine/layer1 engine/layer2 visualizer visualizer/component visualizer/toolwindow visualizer/component/shape treeview codeeditor receptoreditor axoneditor axonterminaleditor cellcodescripttreeview HEADERS = mainwindow.h \ visualizer/dcscene.h \ @@ -102,7 +102,8 @@ HEADERS = mainwindow.h \ engine/versioninfo.h \ codeeditor/dceditscriptfolder.h \ codeeditor/dccodeeditorscriptmanager.h \ - dialog/dccodeeditorexternaleditorsettingdialog.h + dialog/dccodeeditorexternaleditorsettingdialog.h \ + cellcodescripttreeview/dccellcodescripttreeviewwidget.h SOURCES = main.cpp \ mainwindow.cpp \ @@ -198,7 +199,8 @@ SOURCES = main.cpp \ dialog/dcmanagecellcodedialog.cpp \ codeeditor/dceditscriptfolder.cpp \ codeeditor/dccodeeditorscriptmanager.cpp \ - dialog/dccodeeditorexternaleditorsettingdialog.cpp + dialog/dccodeeditorexternaleditorsettingdialog.cpp \ + cellcodescripttreeview/dccellcodescripttreeviewwidget.cpp RESOURCES = denncoCreator.qrc diff --git a/Source/denncoCreator.qrc b/Source/denncoCreator.qrc index 6c5c194..4307b6c 100644 --- a/Source/denncoCreator.qrc +++ b/Source/denncoCreator.qrc @@ -11,5 +11,6 @@ images/page.png images/folder.png images/playbutton.png + images/docIcon.png diff --git a/Source/images/docIcon.png b/Source/images/docIcon.png new file mode 100644 index 0000000..5a2a096 Binary files /dev/null and b/Source/images/docIcon.png differ diff --git a/Source/mainwindow.cpp b/Source/mainwindow.cpp index 03c3369..3e9f957 100644 --- a/Source/mainwindow.cpp +++ b/Source/mainwindow.cpp @@ -25,6 +25,7 @@ #include "dccontent.h" #include "dcglvisualizerwidget.h" #include "dctreeviewwidget.h" +#include "dccellcodescripttreeviewwidget.h" #include "TKConsole.h" #include "utils/dcresources.h" #include "utils/dcskeltoncreatorutil.h" @@ -80,10 +81,15 @@ MainWindow::MainWindow(QWidget *parent) : d_treeViewWidget = new DCTreeViewWidget(this, d_creator); ui->treeViewDock->layout()->addWidget(d_treeViewWidget); + d_cellCodeScriptTreeViewWidget = new DCCellCodeScriptTreeViewWidget(this, d_creator); + ui->cellCodeScriptTreeViewDock->layout()->addWidget(d_cellCodeScriptTreeViewWidget); + DCCellScriptsEditorWindow::construct(d_creator); setCurrentContent(""); setUnifiedTitleAndToolBarOnMac(true); + + tabifyDockWidget(ui->dock2,ui->dock1); } MainWindow::~MainWindow() @@ -584,3 +590,57 @@ void MainWindow::manageCellCode() DCManageCellCodeDialog dialog(d_creator, NULL, this); dialog.exec(); } + + +//static +bool MainWindow::openExternalEditorFor(const QString &path) +{ + static QList s_processes; + static QMutex s_mutex; + + QMutexLocker locker(&s_mutex); + + QString editorPath = readSettingsForExternalScriptEditorPath(); + if (editorPath.isEmpty() || editorPath.length() == 0) + { + DCCodeEditorExternalEditorSettingDialog dialog; + dialog.exec(); + editorPath = readSettingsForExternalScriptEditorPath(); + } + if (editorPath.isEmpty() || editorPath.length() == 0) + return false; + + QString parameterOrg = readSettingsForExternalScriptEditorParameters(); + QString parameter = ""; + int i = 0; + int j = parameterOrg.indexOf(QRegExp("%F[ \t\"']|%F$"),i); + while (j >= 0) + { + parameter += parameterOrg.mid(i, j-i); + parameter += path; + i = j + 2; + if (i > parameterOrg.length()) + break; + j = parameterOrg.indexOf(QRegExp("%F[ \t\"']|%F$"),i); + } + if (i < parameterOrg.length()) + parameter += parameterOrg.mid(i); + + QList::iterator it = s_processes.begin(); + while (it != s_processes.end()) + { + if ((*it)->state() != QProcess::Running) + { + delete (*it); + it = s_processes.erase(it); + } + else + ++it; + } + QProcess *newProcess = new QProcess; + newProcess->start("\"" + editorPath + "\" " + parameter); + + s_processes.append(newProcess); + + return true; +} diff --git a/Source/mainwindow.h b/Source/mainwindow.h index 3347141..0cfaa92 100644 --- a/Source/mainwindow.h +++ b/Source/mainwindow.h @@ -30,6 +30,7 @@ class MainWindow; class DCCreator; class DCGLVisualizerWidget; class DCTreeViewWidget; +class DCCellCodeScriptTreeViewWidget; class MainWindow : public QMainWindow { @@ -45,6 +46,7 @@ public: static QString readSettingsForExternalScriptEditorParameters(); static void writeSettingsForExternalScriptEditorPath(const QString& arg); static void writeSettingsForExternalScriptEditorParameters(const QString& arg); + static bool openExternalEditorFor(const QString& path); protected: void closeEvent(QCloseEvent *event); @@ -106,12 +108,13 @@ private: Ui::MainWindow *ui; - DCCreator *d_creator; - DCGLVisualizerWidget *d_visualizerWidget; - DCTreeViewWidget *d_treeViewWidget; - QProcess d_player; - QString d_IPCServerName; - QStringList d_contentOpenHistory; + DCCreator *d_creator; + DCGLVisualizerWidget *d_visualizerWidget; + DCTreeViewWidget *d_treeViewWidget; + DCCellCodeScriptTreeViewWidget *d_cellCodeScriptTreeViewWidget; + QProcess d_player; + QString d_IPCServerName; + QStringList d_contentOpenHistory; }; #endif // MAINWINDOW_H diff --git a/Source/mainwindow.ui b/Source/mainwindow.ui index 389db37..f59c2c6 100644 --- a/Source/mainwindow.ui +++ b/Source/mainwindow.ui @@ -47,6 +47,20 @@ + + + QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable + + + Cell Code Scripts + + + 1 + + + + + diff --git a/Source/utils/dccommandutil.cpp b/Source/utils/dccommandutil.cpp index 53e43d8..3bf732a 100644 --- a/Source/utils/dccommandutil.cpp +++ b/Source/utils/dccommandutil.cpp @@ -123,6 +123,12 @@ void DCCommandUtil::postRemoveCellCommand(const void *requester, DCCreator *crea } //static +void DCCommandUtil::postRemoveCellCodeCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCellCode* cellCode) +{ + postEvent(creator, new DCRemoveCellCodeClassCommand(requester, creator, container, cellCode)); +} + +//static void DCCommandUtil::postRemoveCellsCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList &cells) { postEvent(creator, new DCRemoveCellCommand(requester, creator, container, cells)); diff --git a/Source/utils/dccommandutil.h b/Source/utils/dccommandutil.h index 70d1c51..1779d00 100644 --- a/Source/utils/dccommandutil.h +++ b/Source/utils/dccommandutil.h @@ -51,6 +51,7 @@ struct DCCommandUtil static void postRenameCellCommand(const void *requester, DCCreator *creator, DCCell *cell, const QString& newContainerBasedPath, const QString& newName); static void postChangeCellTypeCommand(const void* requester, DCCreator *creator, DCCell *cell, const QString& newType); static void postRemoveCellCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCell *cells); + static void postRemoveCellCodeCommand(const void *requester, DCCreator *creator, DCContainer *container, DCCellCode *cells); static void postRemoveCellsCommand(const void *requester, DCCreator *creator, DCContainer *container, const QList &cells); static void postAddPageCommand(const void *requester, DCCreator *creator, const QString& containerBasedPath); static void postMovePageCommand(const void *requester, DCCreator *creator, const QString &oldContainerBasedPath, const QString& newContainerBasedPath); diff --git a/Source/utils/dcqtitemmodel.cpp b/Source/utils/dcqtitemmodel.cpp index 67f3e2d..9e4f5fd 100644 --- a/Source/utils/dcqtitemmodel.cpp +++ b/Source/utils/dcqtitemmodel.cpp @@ -27,6 +27,18 @@ DCQtItemModelItem::DCQtItemModelItem(const QVector &data, DCQtItemMode { } +DCQtItemModelItem::DCQtItemModelItem(const QStringList &headers, DCQtItemModelItem *parent) + :mParentItem(parent) +{ + QVector rootData; + foreach (QString header, headers) + { + rootData << header; + } + mItemData = rootData; +} + + DCQtItemModelItem::~DCQtItemModelItem() { qDeleteAll(mChildItems); @@ -131,7 +143,7 @@ bool DCQtItemModelItem::setData(int column, const QVariant &value) -DCQtItemModel::DCQtItemModel(const QStringList &headers, QObject *parent) +DCQtItemModel::DCQtItemModel(const QStringList &headers, DCQtItemModelItem *rootItem, QObject *parent) : QAbstractItemModel(parent) { QVector rootData; @@ -141,7 +153,10 @@ DCQtItemModel::DCQtItemModel(const QStringList &headers, QObject *parent) mReadOnlyAttrib.push_back(true); } - mRootItem = new DCQtItemModelItem(rootData); + if (rootItem) + mRootItem = rootItem; + else + mRootItem = new DCQtItemModelItem(rootData); } DCQtItemModel::~DCQtItemModel() diff --git a/Source/utils/dcqtitemmodel.h b/Source/utils/dcqtitemmodel.h index c19bf00..5124774 100644 --- a/Source/utils/dcqtitemmodel.h +++ b/Source/utils/dcqtitemmodel.h @@ -27,21 +27,22 @@ class DCQtItemModelItem { public: DCQtItemModelItem(const QVector &data, DCQtItemModelItem *parent = 0); + DCQtItemModelItem(const QStringList &headers, DCQtItemModelItem *parent = 0); virtual ~DCQtItemModelItem(); DCQtItemModelItem *child(int number); int childCount() const; int columnCount() const; - QVariant data(int column) const; - bool insertChildren(int position, int count, int columns); - bool insertColumns(int position, int columns); - DCQtItemModelItem *parent(); - bool removeChildren(int position, int count); - bool removeColumns(int position, int columns); + virtual QVariant data(int column) const; + virtual bool insertChildren(int position, int count, int columns); + virtual bool insertColumns(int position, int columns); + virtual DCQtItemModelItem *parent(); + virtual bool removeChildren(int position, int count); + virtual bool removeColumns(int position, int columns); int childNumber() const; - bool setData(int column, const QVariant &value); + virtual bool setData(int column, const QVariant &value); -private: +protected: QList mChildItems; QVector mItemData; DCQtItemModelItem *mParentItem; @@ -51,7 +52,7 @@ class DCQtItemModel : public QAbstractItemModel { Q_OBJECT public: - DCQtItemModel(const QStringList &headers, QObject *parent = 0); + DCQtItemModel(const QStringList &headers, DCQtItemModelItem *rootItem = 0, QObject *parent = 0); virtual ~DCQtItemModel(); QVariant data(const QModelIndex &index, int role) const;