signalsloteditorwindow.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 703 行 · 第 1/2 页
CPP
703 行
/******************************************************************************** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//*TRANSLATOR qdesigner_internal::ConnectionModel*/#include "signalsloteditorwindow.h"#include "signalsloteditor_p.h"#include "signalsloteditor.h"#include "qdesigner_integration_p.h"#include <iconloader_p.h>#include <QtDesigner/QDesignerFormWindowInterface>#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerFormWindowManagerInterface>#include <QtCore/QAbstractItemModel>#include <QtCore/QDebug>#include <QtGui/QStandardItemModel>#include <QtGui/QComboBox>#include <QtGui/QApplication>#include <QtGui/QItemDelegate>#include <QtGui/QItemEditorFactory>#include <QtGui/QTreeView>#include <QtGui/QVBoxLayout>#include <QtGui/QToolButton>#include <QtGui/QMessageBox>namespace qdesigner_internal {/********************************************************************************* ConnectionModel*/ConnectionModel::ConnectionModel(SignalSlotEditor *editor, QObject *parent) : QAbstractItemModel(parent){ m_editor = editor; connect(m_editor, SIGNAL(connectionAdded(Connection*)), this, SLOT(connectionAdded(Connection*))); connect(m_editor, SIGNAL(connectionRemoved(int)), this, SLOT(connectionRemoved(int))); connect(m_editor, SIGNAL(aboutToRemoveConnection(Connection*)), this, SLOT(aboutToRemoveConnection(Connection*))); connect(m_editor, SIGNAL(aboutToAddConnection(int)), this, SLOT(aboutToAddConnection(int))); connect(m_editor, SIGNAL(connectionChanged(Connection*)), this, SLOT(connectionChanged(Connection*)));}QVariant ConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const{ if (orientation == Qt::Vertical || role != Qt::DisplayRole) return QVariant(); static const QVariant senderTitle = tr("Sender"); static const QVariant signalTitle = tr("Signal"); static const QVariant receiverTitle = tr("Receiver"); static const QVariant slotTitle = tr("Slot"); switch (section) { case 0: return senderTitle; case 1: return signalTitle; case 2: return receiverTitle; case 3: return slotTitle; } return QVariant();}QModelIndex ConnectionModel::index(int row, int column, const QModelIndex &parent) const{ if (parent.isValid()) return QModelIndex(); if (row < 0 || row >= m_editor->connectionCount()) return QModelIndex(); return createIndex(row, column);}Connection *ConnectionModel::indexToConnection(const QModelIndex &index) const{ if (!index.isValid()) return 0; if (index.row() < 0 || index.row() >= m_editor->connectionCount()) return 0; return m_editor->connection(index.row());}QModelIndex ConnectionModel::connectionToIndex(Connection *con) const{ return createIndex(m_editor->indexOfConnection(con), 0);}QModelIndex ConnectionModel::parent(const QModelIndex&) const{ return QModelIndex();}int ConnectionModel::rowCount(const QModelIndex &parent) const{ if (parent.isValid()) return 0; return m_editor->connectionCount();}int ConnectionModel::columnCount(const QModelIndex &parent) const{ if (parent.isValid()) return 0; return 4;}QVariant ConnectionModel::data(const QModelIndex &index, int role) const{ if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant(); if (index.row() < 0 || index.row() >= m_editor->connectionCount()) { return QVariant(); } const SignalSlotConnection *con = static_cast<SignalSlotConnection*>(m_editor->connection(index.row())); Q_ASSERT(con != 0); static const QVariant senderDefault = tr("<sender>"); static const QVariant signalDefault = tr("<signal>"); static const QVariant receiverDefault = tr("<receiver>"); static const QVariant slotDefault = tr("<slot>"); switch (index.column()) { case 0: { const QString sender = con->sender(); if (sender.isEmpty()) return senderDefault; return sender; } case 1: { const QString signal = con->signal(); if (signal.isEmpty()) return signalDefault; return signal; } case 2: { const QString receiver = con->receiver(); if (receiver.isEmpty()) return receiverDefault; return receiver; } case 3: { const QString slot = con->slot(); if (slot.isEmpty()) return slotDefault; return slot; } } return QVariant();}bool ConnectionModel::setData(const QModelIndex &index, const QVariant &data, int){ if (!index.isValid()) return false; if (data.type() != QVariant::String) return false; SignalSlotConnection *con = static_cast<SignalSlotConnection*>(m_editor->connection(index.row())); QDesignerFormWindowInterface *form = m_editor->formWindow(); QString s = data.toString(); switch (index.column()) { case 0: { if (!s.isEmpty() && !objectNameList(form).contains(s)) s.clear(); m_editor->setSource(con, s); break; } case 1: { if (!memberList(form, con->object(CETypes::EndPoint::Source), SignalMember).contains(s)) s.clear(); m_editor->setSignal(con, s); break; } case 2: { if (!s.isEmpty() && !objectNameList(form).contains(s)) s.clear(); m_editor->setTarget(con, s); break; } case 3: { if (!memberList(form, con->object(CETypes::EndPoint::Target), SlotMember).contains(s)) s.clear(); m_editor->setSlot(con, s); break; } } return true;}void ConnectionModel::connectionAdded(Connection*){ endInsertRows();}void ConnectionModel::connectionRemoved(int){ endRemoveRows();}void ConnectionModel::aboutToRemoveConnection(Connection *con){ int idx = m_editor->indexOfConnection(con); beginRemoveRows(QModelIndex(), idx, idx);}void ConnectionModel::aboutToAddConnection(int idx){ beginInsertRows(QModelIndex(), idx, idx);}Qt::ItemFlags ConnectionModel::flags(const QModelIndex&) const{ return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;}void ConnectionModel::connectionChanged(Connection *con){ const int idx = m_editor->indexOfConnection(con); SignalSlotConnection *changedCon = static_cast<SignalSlotConnection*>(m_editor->connection(idx)); SignalSlotConnection *c = 0; for (int i=0; i<m_editor->connectionCount(); ++i) { if (i == idx) continue; c = static_cast<SignalSlotConnection*>(m_editor->connection(i)); if (c->sender() == changedCon->sender() && c->signal() == changedCon->signal() && c->receiver() == changedCon->receiver() && c->slot() == changedCon->slot()) { QMessageBox::warning(m_editor->parentWidget(), tr("Signal and Slot Editor"), tr("The connection already exists!<br>SENDER(%1), SIGNAL(%2), RECEIVER(%3), SLOT(%4)") .arg(changedCon->sender()) .arg(changedCon->signal()) .arg(changedCon->receiver()) .arg(changedCon->slot())); break; } } emit dataChanged(createIndex(idx, 0), createIndex(idx, 3));}void ConnectionModel::updateAll(){ emit dataChanged(index(0, 0), index(rowCount(), columnCount()));}/********************************************************************************* InlineEditor*/#define TITLE_ITEM 1class InlineEditorModel : public QStandardItemModel{ Q_OBJECTpublic: InlineEditorModel(int rows, int cols, QObject *parent = 0); void addTitle(const QString &title); void addTextList(const QStringList &text_list); void addText(const QString &text); bool isTitle(int idx) const; int findText(const QString &text) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const;};class InlineEditor : public QComboBox{ Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText USER true)public: InlineEditor(QWidget *parent = 0); ~InlineEditor(); QString text() const; void setText(const QString &text); void addTitle(const QString &title); void addText(const QString &text); void addTextList(const QStringList &text_list);private slots: void checkSelection(int idx);private: InlineEditorModel *m_model; int m_idx;};InlineEditorModel::InlineEditorModel(int rows, int cols, QObject *parent) : QStandardItemModel(rows, cols, parent){}void InlineEditorModel::addTitle(const QString &title){ const int cnt = rowCount(); insertRows(cnt, 1); QModelIndex cat_idx = index(cnt, 0); setData(cat_idx, title + QLatin1Char(':'), Qt::DisplayRole); setData(cat_idx, TITLE_ITEM, Qt::UserRole); QFont font = QApplication::font(); font.setBold(true);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?