feat(vqt6): 新增 QTreeWidget/QTreeWidgetItem 桥接与树统计助手
This commit is contained in:
1 parent
90a58d05b1
commit
2e72ef0359
5 files changed
+410
No files matched your search
@@ -28,6 +28,7 @@
|
||||
#include <QFormLayout>
|
||||
#include <QStackedWidget>
|
||||
#include <QTabWidget>
|
||||
#include <QTreeWidget>
|
||||
#include <QMenuBar>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
@@ -42,6 +43,7 @@
|
||||
#include <QStringList>
|
||||
#include <QFont>
|
||||
#include <QColor>
|
||||
#include <QVariant>
|
||||
#include <QPixmap>
|
||||
#include <QIcon>
|
||||
#include <QCursor>
|
||||
@@ -768,6 +770,11 @@ extern "C" VQT6_API void vqt6_qplaintextedit_append_utf8(void* pte, const char*
|
||||
static_cast<QPlainTextEdit*>(pte)->appendPlainText(QString::fromUtf8(utf8));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qplaintextedit_set_plain_text_utf8(void* pte, const char* utf8) {
|
||||
if (pte == nullptr || utf8 == nullptr) return;
|
||||
static_cast<QPlainTextEdit*>(pte)->setPlainText(QString::fromUtf8(utf8));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qwidget_set_stylesheet_utf8(void* widget, const char* utf8) {
|
||||
if (widget == nullptr || utf8 == nullptr) return;
|
||||
static_cast<QWidget*>(widget)->setStyleSheet(QString::fromUtf8(utf8));
|
||||
@@ -1766,6 +1773,144 @@ extern "C" VQT6_API void* vqt6_qfiledialog_get_open_file_names(void* parent, voi
|
||||
));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// QTreeWidget / QTreeWidgetItem
|
||||
// ============================================================
|
||||
extern "C" VQT6_API void* vqt6_qtreewidget_create(void) {
|
||||
return new QTreeWidget();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtreewidget_create_with_parent(void* parent) {
|
||||
if (parent == nullptr) return nullptr;
|
||||
return new QTreeWidget(static_cast<QWidget*>(parent));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_add_top_level_item(void* tw, void* item) {
|
||||
if (tw == nullptr || item == nullptr) return;
|
||||
static_cast<QTreeWidget*>(tw)->addTopLevelItem(static_cast<QTreeWidgetItem*>(item));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_insert_top_level_item(void* tw, int index, void* item) {
|
||||
if (tw == nullptr || item == nullptr) return;
|
||||
static_cast<QTreeWidget*>(tw)->insertTopLevelItem(index, static_cast<QTreeWidgetItem*>(item));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtreewidget_top_level_item_count(void* tw) {
|
||||
if (tw == nullptr) return 0;
|
||||
return static_cast<QTreeWidget*>(tw)->topLevelItemCount();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtreewidget_top_level_item(void* tw, int index) {
|
||||
if (tw == nullptr) return nullptr;
|
||||
return static_cast<QTreeWidget*>(tw)->topLevelItem(index);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtreewidget_current_item(void* tw) {
|
||||
if (tw == nullptr) return nullptr;
|
||||
return static_cast<QTreeWidget*>(tw)->currentItem();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_expand_all(void* tw) {
|
||||
if (tw == nullptr) return;
|
||||
static_cast<QTreeWidget*>(tw)->expandAll();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_collapse_all(void* tw) {
|
||||
if (tw == nullptr) return;
|
||||
static_cast<QTreeWidget*>(tw)->collapseAll();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_set_header_hidden(void* tw, int hidden) {
|
||||
if (tw == nullptr) return;
|
||||
static_cast<QTreeWidget*>(tw)->setHeaderHidden(hidden != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_set_column_count(void* tw, int count) {
|
||||
if (tw == nullptr) return;
|
||||
static_cast<QTreeWidget*>(tw)->setColumnCount(count);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_set_item_expanded(void* tw, void* item, int expanded) {
|
||||
if (item == nullptr) return;
|
||||
(void)tw;
|
||||
static_cast<QTreeWidgetItem*>(item)->setExpanded(expanded != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtreewidgetitem_create(void* text) {
|
||||
QTreeWidgetItem* it = new QTreeWidgetItem();
|
||||
if (text != nullptr) it->setText(0, *static_cast<QString*>(text));
|
||||
return it;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidgetitem_add_child(void* item, void* child) {
|
||||
if (item == nullptr || child == nullptr) return;
|
||||
static_cast<QTreeWidgetItem*>(item)->addChild(static_cast<QTreeWidgetItem*>(child));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtreewidgetitem_child_count(void* item) {
|
||||
if (item == nullptr) return 0;
|
||||
return static_cast<QTreeWidgetItem*>(item)->childCount();
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtreewidgetitem_child(void* item, int index) {
|
||||
if (item == nullptr) return nullptr;
|
||||
return static_cast<QTreeWidgetItem*>(item)->child(index);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidgetitem_set_text(void* item, void* text) {
|
||||
if (item == nullptr || text == nullptr) return;
|
||||
static_cast<QTreeWidgetItem*>(item)->setText(0, *static_cast<QString*>(text));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void* vqt6_qtreewidgetitem_text(void* item) {
|
||||
if (item == nullptr) return nullptr;
|
||||
return new QString(static_cast<QTreeWidgetItem*>(item)->text(0));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidgetitem_set_checkable(void* item, int checkable) {
|
||||
if (item == nullptr) return;
|
||||
QTreeWidgetItem* it = static_cast<QTreeWidgetItem*>(item);
|
||||
Qt::ItemFlags f = it->flags();
|
||||
if (checkable != 0) f |= Qt::ItemIsUserCheckable;
|
||||
else f &= ~Qt::ItemIsUserCheckable;
|
||||
it->setFlags(f);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidgetitem_set_check_state(void* item, int state) {
|
||||
if (item == nullptr) return;
|
||||
Qt::CheckState cs = Qt::Unchecked;
|
||||
if (state == 1) cs = Qt::PartiallyChecked;
|
||||
else if (state == 2) cs = Qt::Checked;
|
||||
static_cast<QTreeWidgetItem*>(item)->setCheckState(0, cs);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtreewidgetitem_check_state(void* item) {
|
||||
if (item == nullptr) return 0;
|
||||
return static_cast<int>(static_cast<QTreeWidgetItem*>(item)->checkState(0));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidgetitem_set_expanded(void* item, int expanded) {
|
||||
if (item == nullptr) return;
|
||||
static_cast<QTreeWidgetItem*>(item)->setExpanded(expanded != 0);
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtreewidgetitem_is_expanded(void* item) {
|
||||
if (item == nullptr) return 0;
|
||||
return static_cast<QTreeWidgetItem*>(item)->isExpanded() ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidgetitem_set_data_int(void* item, int value) {
|
||||
if (item == nullptr) return;
|
||||
static_cast<QTreeWidgetItem*>(item)->setData(0, Qt::UserRole, QVariant(value));
|
||||
}
|
||||
|
||||
extern "C" VQT6_API int vqt6_qtreewidgetitem_data_int(void* item) {
|
||||
if (item == nullptr) return 0;
|
||||
bool ok = false;
|
||||
int v = static_cast<QTreeWidgetItem*>(item)->data(0, Qt::UserRole).toInt(&ok);
|
||||
return ok ? v : 0;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 信号连接(Qt 信号 → Viper 回调 vqt6_slot_callback_t)
|
||||
// 模式:vqt6_signal_register 分配 slot_id → Qt lambda 连接信号 →
|
||||
@@ -1900,3 +2045,23 @@ extern "C" VQT6_API void vqt6_qaction_connect_triggered(void* action, vqt6_slot_
|
||||
vqt6_trigger_slot(slot_id);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_connect_item_changed(void* tw, vqt6_slot_callback_t cb, void* user_data) {
|
||||
if (tw == nullptr) return;
|
||||
int slot_id = vqt6_signal_register(cb, user_data);
|
||||
if (slot_id < 0) return;
|
||||
QObject::connect(static_cast<QTreeWidget*>(tw), &QTreeWidget::itemChanged,
|
||||
static_cast<QTreeWidget*>(tw), [slot_id](QTreeWidgetItem*, int) {
|
||||
vqt6_trigger_slot(slot_id);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" VQT6_API void vqt6_qtreewidget_connect_item_clicked(void* tw, vqt6_slot_callback_t cb, void* user_data) {
|
||||
if (tw == nullptr) return;
|
||||
int slot_id = vqt6_signal_register(cb, user_data);
|
||||
if (slot_id < 0) return;
|
||||
QObject::connect(static_cast<QTreeWidget*>(tw), &QTreeWidget::itemClicked,
|
||||
static_cast<QTreeWidget*>(tw), [slot_id](QTreeWidgetItem*, int) {
|
||||
vqt6_trigger_slot(slot_id);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user