1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513 |
- #include "DbTreeViewManager.h"
- #include "OriginalWnd/OriginalWnd.h"
- #include "OriginalWnd/NonInteractiveCheckDelegate.h"
- #include <QFile>
- #include <QTextStream>
- #include <QDateTime>
- #include "Src/common/JMessageTip.h"
- #include "Src/common/JLogAllOutput.h"
- #include "CViewInterface.h"
- #include "Login.h"
- #include "TreeViewManager/JIoMapPage.h"
- DbTreeViewManager::DbTreeViewManager(QWidget* pOriginalWndMenuPage, QWidget* parent)
- : QWidget(parent),
- m_pOriginalWndMenuPage(pOriginalWndMenuPage)
- {
- m_originalWnd = dynamic_cast<OriginalWnd*>(parent);
- Init();
-
- m_pTreeViewDown->setModel(m_pCModel);
- m_pTreeViewDown->setHeaderHidden(true);
- m_pTreeViewDown->setEditTriggers(QAbstractItemView::NoEditTriggers);
-
- m_pTreeViewDown->setGeometry(16, 106, m_pOriginalWndMenuPage->width() - 16, m_pOriginalWndMenuPage->height() - 106);
-
- m_pTreeViewDown->viewport()->installEventFilter(this);
-
- m_pLineFrame1 = createUnifiedSeparator(m_pOriginalWndMenuPage, 2);
- m_pLineFrame1->setGeometry(16, 100, 460, 2);
-
- setupButton();
-
- m_pNavigationWidget = new QWidget(m_pOriginalWndMenuPage);
- m_pNavigationWidget->setGeometry(15, 15, 300, 74);
- m_pNavigationWidget->setObjectName("NavigationWidget");
-
- connect(m_pCModel, &QStandardItemModel::itemChanged, this, &DbTreeViewManager::onItemChanged);
-
- connect(m_pTreeViewDown, &QTreeView::clicked, this, &DbTreeViewManager::onTreeViewClicked);
-
- connect(m_pTreeViewDown, &QTreeView::expanded, this, [=](const QModelIndex &index) {
- QStandardItem *item = m_pCModel->itemFromIndex(index);
- if (!item) return;
- QStringList path = buildItemPath(item);
- expandedPaths.insert(path.join("/"));
- updateSeparatorLine();
-
- saveExpandedPaths();
- });
- connect(m_pTreeViewDown, &QTreeView::collapsed, this, [=](const QModelIndex &index) {
- QStandardItem *item = m_pCModel->itemFromIndex(index);
- if (!item) return;
- QStringList path = buildItemPath(item);
- expandedPaths.remove(path.join("/"));
- updateSeparatorLine();
-
- saveExpandedPaths();
- });
-
- QTimer::singleShot(0, this, [=]() {
- QStandardItem *rootItem = m_pCModel->invisibleRootItem();
- QStandardItem *thirdItem = findFirstThirdLevelItemDFS(rootItem);
- if (thirdItem)
- {
- QJsonObject thirdLevelObj = thirdItem->data(Qt::UserRole + 2).toJsonObject();
- if (thirdLevelObj.contains("IsThirdLevel") && thirdLevelObj["IsThirdLevel"].toBool())
- {
- QString multiTableName = "";
- if (thirdLevelObj.contains("TableName"))
- {
- multiTableName = thirdLevelObj["TableName"].toString();
- }
- QList<CONFIG_BASE_STRUCT> buttons;
- int userGrade = 0x1;
- m_sqlOper->GetThirdDirButtons(multiTableName, userGrade, buttons);
- displayThirdLevelButtons(buttons);
-
- }
- }
- });
-
- m_pTreeViewDown->setItemDelegate(new NonInteractiveCheckDelegate(m_pTreeViewDown));
- menuArray[0] = {2, false,-1};
- menuArray[1] = {5, false,-1};
- menuArray[2] = {3, false,-1};
- menuArray[3] = {4, false,-1};
- menuArray[4] = {6, false,-1};
- currentMenuId = -1;
- }
- DbTreeViewManager::~DbTreeViewManager()
- {
-
- }
- void DbTreeViewManager::Init()
- {
- m_pTreeViewDown = new QTreeView(this);
- m_pCModel = new QStandardItemModel(this);
- m_sqlOper = &SqlOperation::GetInstance();
- m_pTreeCViewInterface = ns_module::CViewInterface::GetInstance();
- }
- QFrame* DbTreeViewManager::createUnifiedSeparator(QWidget *parent, int height)
- {
- QFrame *separator = new QFrame(parent);
- separator->setFrameShape(QFrame::NoFrame);
- separator->setFixedHeight(height);
-
- separator->hide();
- return separator;
- }
- void DbTreeViewManager::applyCustomStyles() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- bool DbTreeViewManager::hasPrivilege(const int &UserGrade, const int &userPrivilege)
- {
- bool hasPriv;
-
- if((UserGrade&userPrivilege) == 1){
- hasPriv = true;
- }else{
- hasPriv = false;
- }
-
- return hasPriv;
- }
- void DbTreeViewManager::initializeTree(QString name, const int &userPrivilege)
- {
- promptSaveChanges();
- QString strLog = "Initializing tree with configId:";
- strLog += name;
- strLog += "and userPrivilege:";
- strLog += userPrivilege;
- JLogAllOutput::cmd_debug(strLog.toStdString());
- m_currentConfigName = name;
-
- clearHistory();
-
- m_blockItemChanged = true;
- m_isRestoring = true;
-
- clearAllSeparators();
-
- m_pCModel->clear();
- m_mapFirstLevelSeparators.clear();
- expandedPaths.clear();
-
- clearThirdLevelMenu();
-
- if (name == "Home")
- {
-
- m_pTreeViewDown->hide();
- for (auto separator : m_mapFirstLevelSeparators)
- {
- if (separator)
- {
- separator->hide();
- }
- }
-
- m_pNavigationWidget->hide();
-
- updateButtonsVisibility();
-
- if (m_pLineFrame1)
- {
- m_pLineFrame1->hide();
- }
-
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData("HomeProduct", userPrivilege, tableControlDatas, allChangeFlag);
-
- displayThirdLevelFields(tableControlDatas, allChangeFlag, true);
-
- PageState st;
- st.path << "Home";
- st.isThirdLevel = true;
- st.directoryId = 1;
- st.multiTableName = "HomeProduct";
- m_backStack.append(st);
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- }
- else
- {
-
-
- m_pTreeViewDown->setGeometry(16, 106, m_pOriginalWndMenuPage->width() - 16, m_pOriginalWndMenuPage->height() - 106);
-
- m_pTreeViewDown->show();
- for (auto separator : m_mapFirstLevelSeparators)
- {
- if (separator)
- {
- separator->show();
- }
- }
-
- applyCustomStyles();
-
- m_pNavigationWidget->show();
-
- updateButtonsVisibility();
-
- if (m_pLineFrame1)
- {
- m_pLineFrame1->show();
- }
-
- QString tableName = "Dir_" + name;
- QList<QJsonObject> directories;
- m_sqlOper->GetDirectories(tableName, userPrivilege, directories);
-
- buildTreeFromDirectories(directories);
-
-
-
- updateSeparatorLine();
- m_blockItemChanged = false;
- m_isRestoring = false;
-
-
- loadExpandedPaths();
-
- loadCheckedPaths();
-
- QStandardItem *rootItem = m_pCModel->invisibleRootItem()->child(0);
- if (rootItem) {
- QModelIndex rootIndex = m_pCModel->indexFromItem(rootItem);
- m_pTreeViewDown->setCurrentIndex(rootIndex);
- updateNavigationBar(rootIndex);
-
- QVariant dataVar = rootItem->data(Qt::UserRole + 2).toJsonObject();
- bool isThirdLevel = false;
- int directoryId = -1;
- QString multiTableName = "";
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject thirdLevelObj = dataVar.toJsonObject();
- if (thirdLevelObj.contains("IsThirdLevel") && thirdLevelObj["IsThirdLevel"].toBool()) {
- isThirdLevel = true;
- if (thirdLevelObj.contains("Id")) {
- directoryId = thirdLevelObj["Id"].toInt();
- }
- if (thirdLevelObj.contains("TableName"))
- {
- multiTableName = thirdLevelObj["TableName"].toString();
- }
- }
- }
- if (isThirdLevel) {
- if (directoryId == -1) {
-
- return;
- }
-
-
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData(multiTableName, userPrivilege, tableControlDatas, allChangeFlag);
-
- displayThirdLevelFields(tableControlDatas, allChangeFlag, false);
-
-
-
- PageState st;
- st.path = buildItemPath(rootItem);
- st.isThirdLevel = true;
- st.directoryId = directoryId;
- st.multiTableName = multiTableName;
- m_backStack.append(st);
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- }
- } else {
-
- }
-
-
- QStandardItem *rootItem1 = m_pCModel->invisibleRootItem();
- QStandardItem *firstThirdItem = findFirstThirdLevelItemDFS(rootItem1);
- if (!firstThirdItem) {
-
- return;
- }
-
- QVariant dataVar = firstThirdItem->data(Qt::UserRole + 2);
- if (!dataVar.canConvert<QJsonObject>()) {
-
- return;
- }
- QJsonObject dirObj = dataVar.toJsonObject();
- if (!dirObj.contains("Id")) {
-
- return;
- }
- int directoryId = dirObj["Id"].toInt();
- if (!dirObj.contains("TableName"))
- {
- return;
- }
- QString multiTableName = dirObj["TableName"].toString();
-
- QTimer::singleShot(0, this, &DbTreeViewManager::updateSeparatorLine);
- QList<CONFIG_BASE_STRUCT> buttons;
- m_sqlOper->GetThirdDirButtons(multiTableName, userPrivilege, buttons);
-
- displayThirdLevelButtons(buttons);
-
-
-
-
-
-
-
-
-
-
-
- }
- }
- void DbTreeViewManager::loadDirectories(int configId, const int &userPrivilege)
- {
-
- QSqlDatabase db = QSqlDatabase::database();
- if (!db.isOpen()) {
- qWarning() << "数据库未打开";
- return;
- }
- QSqlQuery query(db);
- query.prepare(R"(
- SELECT Id, Name, ParentId, IsThirdLevel, Separator, UserGrade, Circle
- FROM Directories
- WHERE ConfigId = :configId
- )");
- query.bindValue(":configId", configId);
- if (!query.exec()) {
- qWarning() << "查询 Directories 失败:" << query.lastError().text();
- return;
- }
-
- QList<QJsonObject> directories;
- while (query.next()) {
- QJsonObject obj;
- int id = query.value("Id").toInt();
- obj["Id"] = id;
- obj["Name"] = query.value("Name").toString();
- obj["ParentId"] = query.value("ParentId").isNull() ? -1 : query.value("ParentId").toInt();
- obj["IsThirdLevel"] = query.value("IsThirdLevel").toBool();
- obj["Separator"] = query.value("Separator").toInt();
- obj["UserGrade"] = query.value("UserGrade").toString();
- obj["Circle"] = query.value("Circle").toInt();
-
-
-
- bool ok;
- if (hasPrivilege(obj["UserGrade"].toString().toInt(&ok, 16), userPrivilege)) {
- directories.append(obj);
-
- }
- }
-
-
- buildTreeFromDirectories(directories);
- }
- void DbTreeViewManager::buildTreeFromDirectories(const QList<QJsonObject> &directories)
- {
-
- QMap<int, QStandardItem*> idItemMap;
- for (const QJsonObject &dir : directories)
- {
- qDebug() << "aaa: " << dir;
- QStandardItem *item = new QStandardItem(dir["Name"].toString());
- item->setData(dir["Id"].toInt(), Qt::UserRole + 1);
-
- if (dir["IsThirdLevel"].toBool())
- {
- item->setData(dir, Qt::UserRole + 2);
- }
- else
- {
- item->setData(false, Qt::UserRole + 2);
- }
- item->setCheckable(true);
-
- item->setCheckState(Qt::Unchecked);
- idItemMap.insert(dir["Id"].toInt(), item);
- }
-
- for (const QJsonObject &dir : directories)
- {
- qDebug() << "aaa: " << dir;
- int parentId = dir["ParentId"].toInt();
- int currentId = dir["Id"].toInt();
- QStandardItem *childItem = idItemMap.value(currentId);
- if (childItem == nullptr)
- {
- qDebug() << "child is nullptr";
- }
- if (parentId == -1) {
-
- m_pCModel->invisibleRootItem()->appendRow(childItem);
- qDebug() << " !!!!! first :" << "child : " << currentId;
-
- if (dir["Separator"].toInt() == 1) {
- QFrame *sep = createUnifiedSeparator(m_pOriginalWndMenuPage, 2);
- sep->hide();
- m_mapFirstLevelSeparators.insert(childItem, sep);
- }
- } else {
-
- QStandardItem *parentItem = idItemMap.value(parentId);
- if (parentItem)
- {
- parentItem->appendRow(childItem);
- qDebug() << "parent:" << parentId << "child : " << currentId;
- }
- else
- qWarning() << "无法找到 ParentId:" << parentId << "的父目录项";
- }
- }
- }
- bool DbTreeViewManager::eventFilter(QObject *watched, QEvent *event)
- {
-
- if (watched == m_pTreeViewDown->viewport() && event->type() == QEvent::Paint)
- {
-
- bool handled = QWidget::eventFilter(watched, event);
-
- QPainter painter(m_pTreeViewDown->viewport());
- if (!painter.isActive()) {
- qWarning() << "Painter not active";
- return handled;
- }
- painter.save();
- painter.setPen(QPen(Qt::gray, 1, Qt::DashLine));
-
- paintAllBranches(QModelIndex(), painter);
- painter.restore();
- return handled;
- }
-
- return QWidget::eventFilter(watched, event);
- }
- void DbTreeViewManager::paintAllBranches(const QModelIndex &parentIndex, QPainter &painter)
- {
- int rowCount = m_pCModel->rowCount(parentIndex);
- for(int i = 0; i < rowCount; ++i)
- {
-
- QModelIndex childIndex = m_pCModel->index(i, 0, parentIndex);
- if (!childIndex.isValid()) continue;
-
- drawParentChildLine(childIndex, painter);
-
- if (i < rowCount - 1) {
- drawSiblingLine(childIndex, painter);
- }
-
- paintAllBranches(childIndex, painter);
- }
- }
- void DbTreeViewManager::drawParentChildLine(const QModelIndex &childIndex, QPainter &painter)
- {
- QModelIndex parentIndex = childIndex.parent();
- if (!parentIndex.isValid()) {
-
- int indent = m_pTreeViewDown->indentation();
- int depth = 0;
- int branchX = (depth + 1) * indent - indent / 2;
-
- QRect childRect = m_pTreeViewDown->visualRect(childIndex);
- if (!childRect.isValid())
- return;
- int rootY = childRect.center().y();
-
- const int hOffset = -20;
-
- painter.drawLine(QPoint(branchX, rootY),
- QPoint(branchX, childRect.center().y()));
-
- int newX = childRect.left() + hOffset;
-
- painter.drawLine(QPoint(branchX, childRect.center().y()),
- QPoint(newX, childRect.center().y()));
- return;
- }
- QRect parentRect = m_pTreeViewDown->visualRect(parentIndex);
- QRect childRect = m_pTreeViewDown->visualRect(childIndex);
- if (!parentRect.isValid() || !childRect.isValid()) {
-
- return;
- }
- int pMidY = parentRect.center().y();
- int cMidY = childRect.center().y();
-
- int depth = 0;
- QModelIndex p = parentIndex;
- while (p.isValid()) {
- depth++;
- p = p.parent();
- }
- int indent = m_pTreeViewDown->indentation();
- int branchX = depth * indent - indent / 2;
-
- branchX = std::max(branchX, 0);
-
- const int hOffset = -15;
-
- painter.drawLine(QPoint(branchX, pMidY), QPoint(branchX, cMidY));
-
- int newX = childRect.left() + hOffset;
-
- painter.drawLine(QPoint(branchX, cMidY), QPoint(newX, cMidY));
- }
- void DbTreeViewManager::drawSiblingLine(const QModelIndex &childIndex, QPainter &painter)
- {
- QModelIndex parentIndex = childIndex.parent();
- if (!parentIndex.isValid()) {
- return;
- }
-
- int row = childIndex.row();
- int lastRow = m_pCModel->rowCount(parentIndex) - 1;
- if (row >= lastRow) {
- return;
- }
- QModelIndex nextSibling = m_pCModel->index(row + 1, 0, parentIndex);
- QRect currRect = m_pTreeViewDown->visualRect(childIndex);
- QRect nextRect = m_pTreeViewDown->visualRect(nextSibling);
- if (!currRect.isValid() || !nextRect.isValid()) {
- return;
- }
-
- int depth = 0;
- QModelIndex p = parentIndex;
- while (p.isValid()) {
- depth++;
- p = p.parent();
- }
- int indent = m_pTreeViewDown->indentation();
- int branchX = depth * indent - indent / 2;
-
- branchX = std::max(branchX, 0);
-
- int startY = currRect.bottom();
- int endY = nextRect.top();
- painter.drawLine(QPoint(branchX, startY), QPoint(branchX, endY));
- }
- QStandardItem* DbTreeViewManager::findFirstThirdLevelItemDFS(QStandardItem *parentItem)
- {
- if (!parentItem) {
- return nullptr;
- }
-
- for (int i = 0; i < parentItem->rowCount(); ++i) {
- QStandardItem *child = parentItem->child(i);
- if (!child) continue;
-
- QVariant data = child->data(Qt::UserRole + 2);
- if (data.canConvert<QJsonObject>()) {
- QJsonObject obj = data.toJsonObject();
- if (obj.contains("IsThirdLevel") && obj["IsThirdLevel"].toBool()) {
-
- return child;
- }
- }
-
- QStandardItem* deeperFound = findFirstThirdLevelItemDFS(child);
- if (deeperFound) {
- return deeperFound;
- }
- }
- return nullptr;
- }
- void DbTreeViewManager::onItemChanged(QStandardItem *item)
- {
- if (m_blockItemChanged || m_isRestoring) {
- return;
- }
- m_blockItemChanged = true;
- Qt::CheckState state = item->checkState();
-
- for (int i = 0; i < item->rowCount(); ++i) {
- QStandardItem *child = item->child(i);
- if (child) {
- child->setCheckState(state);
-
- onItemChanged(child);
- }
- }
-
- QModelIndex parentIndex = item->index().parent();
- while (parentIndex.isValid()) {
- QStandardItem *parentItem = m_pCModel->itemFromIndex(parentIndex);
- if (!parentItem) break;
- int checkedCount = 0;
- int totalCount = parentItem->rowCount();
- for (int i = 0; i < totalCount; ++i) {
- QStandardItem *child = parentItem->child(i);
- if (child && child->checkState() == Qt::Checked) {
- checkedCount++;
- }
- }
- if (checkedCount == totalCount) {
- parentItem->setCheckState(Qt::Checked);
- }
- else {
- parentItem->setCheckState(Qt::Unchecked);
- }
- parentIndex = parentIndex.parent();
- }
- m_blockItemChanged = false;
-
- saveCheckedPaths();
- }
- void DbTreeViewManager::setupButton()
- {
-
- auto createButton = [&](QPushButton*& button, const QString& iconPath, const QRect& geometry) {
- button = new QPushButton(this);
- button->setIcon(QIcon(iconPath));
- button->setGeometry(geometry);
- button->setProperty("type", "menu");
-
-
-
-
-
-
-
-
-
-
-
-
- button->show();
- };
-
- createButton(ButtonBack, ":/images/home_openFile.png", QRect(328, 6, 76, 30));
- createButton(buttonUp, ":/images/home_up.png", QRect(408, 6, 36, 30));
- createButton(buttonDown, ":/images/home_down.png", QRect(408, 40, 36, 30));
- createButton(buttonLeft, ":/images/home_left_hide.png", QRect(328, 40, 36, 30));
- createButton(buttonRight, ":/images/home_right.png", QRect(368, 40, 36, 30));
-
- connect(ButtonBack, &QPushButton::clicked, this, &DbTreeViewManager::onButtonBackClicked);
- connect(buttonUp, &QPushButton::clicked, this, &DbTreeViewManager::onButtonUpClicked);
- connect(buttonDown, &QPushButton::clicked, this, &DbTreeViewManager::onButtonDownClicked);
- connect(buttonLeft, &QPushButton::clicked, this, &DbTreeViewManager::onButtonLeftClicked);
- connect(buttonRight, &QPushButton::clicked, this, &DbTreeViewManager::onButtonRightClicked);
- }
- void DbTreeViewManager::updateButtonsVisibility()
- {
- if (m_currentConfigName == "Home") {
-
- ButtonBack->hide();
- buttonUp->hide();
- buttonDown->hide();
- buttonLeft->hide();
- buttonRight->hide();
- }
- else {
-
- ButtonBack->show();
- buttonUp->show();
- buttonDown->show();
- buttonLeft->show();
- buttonRight->show();
- }
- }
- QStandardItem* DbTreeViewManager::deepCopyItem(const QStandardItem *item){
- if (!item) {
- return nullptr;
- }
-
- QStandardItem *newItem = new QStandardItem(item->text());
- newItem->setIcon(item->icon());
- newItem->setToolTip(item->toolTip());
- newItem->setEditable(item->isEditable());
- newItem->setCheckable(item->isCheckable());
- newItem->setCheckState(item->checkState());
-
- for (int i = 0; i < item->rowCount(); ++i) {
- QStandardItem *childItem = item->child(i);
- QStandardItem *newChildItem = deepCopyItem(childItem);
- newItem->appendRow(newChildItem);
- }
- return newItem;
- }
- void DbTreeViewManager::loadpage(const int &configId){
- for(int i=0;i<5;i++){
- if(configId == menuArray[i].menuId){
-
-
- }
- }
- }
- void DbTreeViewManager::onTreeViewClicked(const QModelIndex &index)
- {
- QStandardItem *item = m_pCModel->itemFromIndex(index);
- if (!item)
- {
- return;
- }
-
- bool isThird = false;
- int dirId = -1;
- QString strModuleType;
- QString mutliTableName = "";
- QVariant dataVar = item->data(Qt::UserRole + 2);
- if (dataVar.canConvert<QJsonObject>())
- {
- QJsonObject obj = dataVar.toJsonObject();
- qDebug() << " AAkey :" << obj;
- if (obj.contains("IsThirdLevel") && obj["IsThirdLevel"].toBool())
- {
- isThird = true;
- if (obj.contains("Id"))
- {
- dirId = obj["Id"].toInt();
- }
- if (obj.contains("TableName"))
- {
- mutliTableName = obj["TableName"].toString();
- }
- if (obj.contains("ModuleType"))
- {
- m_str2DirModuleType = obj["ModuleType"].toString();
- }
- }
- }
- updateNavigationBar(index);
- if (isThird) {
-
- int userPrivilege = 0x1;
- if (dirId < 0)
- {
- qWarning() << "无效directoryId";
- return;
- }
- if (mutliTableName == "")
- {
- qWarning() << "无效directoryId";
- return;
- }
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData(mutliTableName, userPrivilege, tableControlDatas, allChangeFlag);
- displayThirdLevelFields(tableControlDatas, allChangeFlag, false);
-
-
-
- for (int i = 0; i < 5; i++)
- {
- if(currentMenuId == menuArray[i].menuId)
- {
- menuArray[i].isthird = true;
- menuArray[i].index = dirId;
- }
- }
-
- PageState st;
- st.path = buildItemPath(item);
- st.isThirdLevel = true;
- st.directoryId = dirId;
- st.multiTableName = mutliTableName;
- m_backStack.append(st);
- if(m_backStack.size() >= 2)
- {
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- m_forwardStack.clear();
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
- }
- else
- {
-
-
- if (m_thirdLevelFieldWnd)
- {
- m_thirdLevelFieldWnd->close();
- m_thirdLevelFieldWnd->deleteLater();
- m_thirdLevelFieldWnd = nullptr;
- }
-
- PageState st;
- st.path = buildItemPath(item);
- st.isThirdLevel = false;
- st.directoryId = -1;
- st.multiTableName = mutliTableName;
- m_backStack.append(st);
- if(m_backStack.size() >= 2)
- {
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- m_forwardStack.clear();
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
- }
- }
- void DbTreeViewManager::onTreeViewClicked_updown(const QModelIndex &index){
- QStandardItem *item = m_pCModel->itemFromIndex(index);
- if (!item) return;
-
- bool isThird = false;
- int dirId = -1;
- QString multiTableName = "";
- QVariant dataVar = item->data(Qt::UserRole + 2);
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject obj = dataVar.toJsonObject();
- if (obj.contains("IsThirdLevel") && obj["IsThirdLevel"].toBool()) {
- isThird = true;
- if (obj.contains("Id")) {
- dirId = obj["Id"].toInt();
- }
- if (obj.contains("TableName"))
- {
- multiTableName = obj["TableName"].toString();
- }
- }
- }
- updateNavigationBar(index);
- if (isThird) {
- int userPrivilege = 0x1;
- if (dirId < 0) {
- qWarning() << "无效directoryId";
- return;
- }
- if (multiTableName == "")
- {
- qWarning() << "无效multiTableName";
- return;
- }
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData(multiTableName, userPrivilege, tableControlDatas, allChangeFlag);
- displayThirdLevelFields(tableControlDatas, allChangeFlag, false);
-
-
-
-
- PageState st;
- st.path = buildItemPath(item);
- st.isThirdLevel = true;
- st.directoryId = dirId;
- st.multiTableName = multiTableName;
- m_backStack.append(st);
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- m_forwardStack.clear();
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
- } else {
-
-
- if (m_thirdLevelFieldWnd) {
- m_thirdLevelFieldWnd->close();
- m_thirdLevelFieldWnd->deleteLater();
- m_thirdLevelFieldWnd = nullptr;
- }
-
- PageState st;
- st.path = buildItemPath(item);
- st.isThirdLevel = false;
- st.directoryId = -1;
- st.multiTableName = multiTableName;
- m_backStack.append(st);
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- m_forwardStack.clear();
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
- }
- }
- void DbTreeViewManager::updateNavigationBar(const QModelIndex &index)
- {
- QStandardItem *item = m_pCModel->itemFromIndex(index);
- if (!item) {
- qWarning() << "导航栏更新失败:未找到对应项";
- return;
- }
-
- if (m_pNavigationWidget->layout()) {
- QLayoutItem *child;
- while ((child = m_pNavigationWidget->layout()->takeAt(0)) != nullptr) {
- if (child->widget()) {
- child->widget()->deleteLater();
- }
- delete child;
- }
- delete m_pNavigationWidget->layout();
- }
-
- QList<QStandardItem *> path;
- QStandardItem *temp = item;
- while (temp) {
- path.prepend(temp);
- temp = temp->parent();
- }
- QVBoxLayout *newLayout = new QVBoxLayout;
- newLayout->setContentsMargins(0, 0, 3, 3);
- newLayout->setSpacing(0);
-
- for (int i = 0; i < 3; ++i) {
- QLabel *label = new QLabel;
- if (i < path.size()) {
- QString text = path[i]->text();
- if (i == 1) text = " " + text;
- if (i == 2) text = " " + text;
- label->setText(text);
- } else {
- label->setText("");
- }
- QFont font = label->font();
- font.setPointSize(14);
- font.setFamily("思源黑体");
- font.setBold(true);
- font.setLetterSpacing(QFont::PercentageSpacing,105);
- label->setFont(font);
- label->setFixedHeight(m_pNavigationWidget->height() / 3);
- newLayout->addWidget(label);
- }
-
- m_pNavigationWidget->setLayout(newLayout);
- m_pNavigationWidget->update();
- }
- void DbTreeViewManager::clearAllSeparators()
- {
-
-
- for (auto separator : m_mapFirstLevelSeparators.values()) {
- if(separator) {
- separator->hide();
- separator->deleteLater();
- }
- }
-
- m_mapFirstLevelSeparators.clear();
- }
- void DbTreeViewManager::updateSeparatorLine()
- {
-
- if (!m_pTreeViewDown->isVisible()) {
- for (auto it = m_mapFirstLevelSeparators.begin(); it != m_mapFirstLevelSeparators.end(); ++it) {
- QFrame *sep = it.value();
- if (sep) sep->hide();
- }
- return;
- }
-
- for (auto it = m_mapFirstLevelSeparators.begin(); it != m_mapFirstLevelSeparators.end(); ++it) {
- QStandardItem *firstLevelItem = it.key();
- QFrame *separator = it.value();
- if (!firstLevelItem || !separator) continue;
-
- QModelIndex firstLevelIndex = m_pCModel->indexFromItem(firstLevelItem);
- QRect firstLevelRect = m_pTreeViewDown->visualRect(firstLevelIndex);
-
- if (!firstLevelRect.isValid()) {
- separator->hide();
- continue;
- }
-
- if (m_pTreeViewDown->isExpanded(firstLevelIndex) && firstLevelItem->hasChildren()) {
- QModelIndex lastVisibleChild = findLastVisibleChild(firstLevelIndex);
- if (lastVisibleChild.isValid()) {
- QRect lastChildRect = m_pTreeViewDown->visualRect(lastVisibleChild);
- if (lastChildRect.isValid()) {
-
- separator->setGeometry(16,lastChildRect.bottom() + 115, m_pOriginalWndMenuPage->width() - 40,1);
- separator->show();
- continue;
- }
- }
- }
-
- separator->setGeometry(16,firstLevelRect.bottom() + 115, m_pOriginalWndMenuPage->width() - 40,1);
- separator->show();
- }
- }
- QModelIndex DbTreeViewManager::findLastVisibleChild(const QModelIndex &parentIndex) {
- if (!parentIndex.isValid()) return QModelIndex();
- int childCount = m_pCModel->rowCount(parentIndex);
- QModelIndex lastVisible;
- for (int i = childCount - 1; i >= 0; --i) {
- QModelIndex childIndex = m_pCModel->index(i, 0, parentIndex);
- if (!m_pTreeViewDown->isRowHidden(i, parentIndex)) {
- if (m_pTreeViewDown->isExpanded(childIndex) && m_pCModel->rowCount(childIndex) > 0) {
- QModelIndex deeper = findLastVisibleChild(childIndex);
- if (deeper.isValid()) {
- return deeper;
- }
- }
- lastVisible = childIndex;
- break;
- }
- }
- return lastVisible;
- }
- QString extractBeforeComma(const QString& input)
- {
- int commaPos = input.indexOf(',');
- if (commaPos != -1) {
- return input.left(commaPos);
- }
- return input;
- }
- void DbTreeViewManager::displayThirdLevelFields(const QList<ST_TABLE_CONTROL_DATA>& data, bool allChangeFlag, bool isHome)
- {
- if (data.isEmpty())
- {
- qWarning() << "字段数据为空,无法显示";
- return;
- }
-
-
- if (m_thirdLevelFieldWnd)
- {
- m_thirdLevelFieldWnd->close();
- m_thirdLevelFieldWnd->deleteLater();
- m_thirdLevelFieldWnd = nullptr;
- }
-
- QModelIndex currentIndex = m_pTreeViewDown->currentIndex();
- if (currentIndex.isValid())
- {
- QStandardItem* currentItem = m_pCModel->itemFromIndex(currentIndex);
- if (currentItem)
- {
- currentItem->setCheckState(allChangeFlag ? Qt::Checked : Qt::Unchecked);
- qDebug() << "设置当前目录项复选框状态为:" << (allChangeFlag ? "Checked" : "Unchecked");
- }
- }
- else
- {
- qWarning() << "当前没有选中的目录项";
- }
-
- m_pTreeViewDown->hide();
- for (auto separator : m_mapFirstLevelSeparators)
- {
- if (separator)
- separator->hide();
- }
-
- m_fieldWidgets.clear();
- modifiedLabels.clear();
- m_veCombinedCont.clear();
- m_veInputCont.clear();
- m_veRadioCont.clear();
- m_veCheckBoxCont.clear();
- m_veComboBoxCont.clear();
- m_veTimeCont.clear();
- m_veSwitchCont.clear();
-
- m_thirdLevelFieldWnd = new QWidget(m_pOriginalWndMenuPage);
- m_thirdLevelFieldWnd->setWindowTitle(m_strShowName);
- m_thirdLevelFieldWnd->setObjectName("thirdLevelFieldWnd");
-
- if (isHome)
- {
-
- m_thirdLevelFieldWnd->setGeometry(0, 0, m_pOriginalWndMenuPage->width(), m_pOriginalWndMenuPage->height());
- }
- else
- {
-
- m_thirdLevelFieldWnd->setGeometry(m_pTreeViewDown->geometry());
- }
-
- QScrollArea* scrollArea = new QScrollArea(m_thirdLevelFieldWnd);
- scrollArea->setWidgetResizable(true);
- scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-
- QWidget* scrollWidget = new QWidget;
- scrollWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
- QVBoxLayout* scrollLayout = new QVBoxLayout(scrollWidget);
- scrollLayout->setSpacing(10);
- scrollLayout->setContentsMargins(10, 10, 10, 10);
- Level3MenuAllSaveBut(scrollLayout);
- QFrame* separator = createUnifiedSeparator(scrollWidget, 2);
- QHBoxLayout* separatorLayout = new QHBoxLayout;
- separatorLayout->setContentsMargins(0, 5, 0, 5);
- separatorLayout->addWidget(separator);
- scrollLayout->addLayout(separatorLayout);
- separator->show();
- languageValue = gen_if.getLanguageValue();
-
- int previousGroupId = -1;
- int privilege = Login::instance()->getPrivilege();
- QList<CONFIG_BASE_STRUCT> buttonControls;
- for (const ST_TABLE_CONTROL_DATA& tableData : data)
- {
-
- for (const CONFIG_BASE_STRUCT& control : tableData.controlDataList)
- {
-
- if (control.strType == "Button")
- {
- buttonControls.append(control);
- }
- else
- {
-
-
- QString fieldName = QString::fromStdString(control.strName);
- QString fieldDescribe = QString::fromStdString(control.strDescribe);
-
- QString fieldDescribe_Eng = "111";
- int fieldUserGrade = control.iUserGrade;
- QString fieldType = QString::fromStdString(control.strType);
- QString fieldValue = QString::fromStdString(control.strValue);
- QString fieldDefult = QString::fromStdString(control.strDefult);
- QString fieldUpLimit = QString::fromStdString(control.strUpperLimit);
- QString fieldDownLimit = QString::fromStdString(control.strLowerLimit);
- QString fieldUnits = QString::fromStdString(control.strUnit);
- QString strAxisType = QString::fromStdString(control.strAxisType);
- QString strstrModuleType = m_str2DirModuleType;
- int groupId = control.iGroupId;
- QString fieldTableName = extractBeforeComma(tableData.tableName);
-
- if (previousGroupId != -1 && groupId != previousGroupId)
- {
- QFrame* separator = createUnifiedSeparator(scrollWidget, 2);
- QHBoxLayout* separatorLayout = new QHBoxLayout;
- separatorLayout->setContentsMargins(0, 5, 0, 5);
- separatorLayout->addWidget(separator);
- scrollLayout->addLayout(separatorLayout);
- separator->show();
- }
- previousGroupId = groupId;
-
- QHBoxLayout* fieldLayout = new QHBoxLayout;
- fieldLayout->setSpacing(5);
- QLabel* label = new QLabel();
- if (languageValue == 0)
- {
- label->setText(fieldDescribe_Eng);
- if (fieldDescribe_Eng.isEmpty())
- {
- label->setText(fieldDescribe);
- }
- }
- else
- {
- label->setText(fieldDescribe);
- if (fieldDescribe.isEmpty())
- {
- label->setText(fieldDescribe_Eng);
- }
- }
- label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
- label->setFixedHeight(24);
- label->setMinimumWidth(120);
- fieldLayout->addWidget(label);
- fieldLayout->addStretch(1);
- QWidget* rightWidget = new QWidget;
- QHBoxLayout* rightLayout = new QHBoxLayout(rightWidget);
- rightLayout->setContentsMargins(0, 0, 20, 0);
- rightLayout->setSpacing(5);
- QWidget* createdWidget = nullptr;
- if (fieldType == "input" || fieldType == "LONG" || fieldType == "STRING")
- {
-
- if (fieldUnits != "")
- {
-
-
-
-
-
- QLineEdit* lineEdit = new QLineEdit();
- if ((fieldUpLimit == "") && (fieldDownLimit == ""))
- {
- lineEdit->setText(fieldValue);
- lineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- lineEdit->setFixedSize(105, 28);
- lineEdit->setAlignment(Qt::AlignLeft);
-
-
- } else
- {
- if (fieldValue == "")
- {
- lineEdit->setPlaceholderText(tr("Please input number","请输入数字"));
- } else
- {
- lineEdit->setText(fieldValue);
- }
- lineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- lineEdit->setFixedSize(105, 28);
- lineEdit->setAlignment(Qt::AlignLeft);
-
- }
-
- QLabel* unitLabel = new QLabel(fieldUnits);
- unitLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- unitLabel->setFixedHeight(28);
-
-
- QHBoxLayout* inputLayout = new QHBoxLayout;
- inputLayout->setSpacing(10);
- inputLayout->setContentsMargins(0, 0, 0, 0);
- inputLayout->addWidget(lineEdit);
- inputLayout->addWidget(unitLabel);
-
- QWidget* inputWidget = new QWidget;
- inputWidget->setLayout(inputLayout);
- rightLayout->addWidget(inputWidget);
-
- m_fieldWidgets.append(lineEdit);
- m_fieldWidgets.append(unitLabel);
- createdWidget = inputWidget;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- connect(lineEdit, &QLineEdit::textChanged, [this, lineEdit, fieldUpLimit, fieldDownLimit, label]() {
- if ((fieldUpLimit != "") && (fieldDownLimit != ""))
- {
- int uplimit = fieldUpLimit.toInt();
- int downlimit = fieldDownLimit.toInt();
- int inputvalue = (lineEdit->text()).toInt();
- if ((inputvalue <= uplimit) && (inputvalue >= downlimit))
- {
- label->setProperty("value", lineEdit->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
- }
- else
- {
- lineEdit->setPlaceholderText(tr("out of range,please input again","超出设定范围,请重新输入"));
- }
- }
- else if (fieldDownLimit != "")
- {
- int downlimit = fieldDownLimit.toInt();
- int inputvalue = (lineEdit->text()).toInt();
- if (inputvalue >= downlimit)
- {
- label->setProperty("value", lineEdit->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
- }
- else
- {
- lineEdit->setPlaceholderText(tr("out of range,please input again","超出设定范围,请重新输入"));
- }
- }
- else if (fieldUpLimit != "")
- {
- int uplimit = fieldUpLimit.toInt();
- int inputvalue = (lineEdit->text()).toInt();
- if (inputvalue <= uplimit)
- {
- label->setProperty("value", lineEdit->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
- }
- else
- {
- lineEdit->setPlaceholderText(tr("out of range,please input again","超出设定范围,请重新输入"));
- }
- }
- else
- {
- label->setProperty("value", lineEdit->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
- }
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, lineEdit]() {
- if (!fieldDefult.isEmpty()) {
- lineEdit->setText(fieldDefult);
- }
- });
- if (privilege < fieldUserGrade) {
- lineEdit->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- ST_INPUT_CONT _a;
- _a.plineEdit = lineEdit;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veInputCont.push_back(_a);
- }
- else
- {
-
- QLineEdit* lineEdit1 = new QLineEdit(fieldValue);
- lineEdit1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- lineEdit1->setFixedSize(140, 28);
- lineEdit1->setAlignment(Qt::AlignLeft);
-
- rightLayout->addWidget(lineEdit1);
- createdWidget = lineEdit1;
-
-
-
-
-
-
- connect(lineEdit1, &QLineEdit::textChanged, [this, lineEdit1, label]() {
- label->setProperty("value", lineEdit1->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
-
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- loginput(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, lineEdit1]() {
- if (!fieldDefult.isEmpty()) {
- lineEdit1->setText(fieldDefult);
- }
- });
- if (privilege < fieldUserGrade) {
- lineEdit1->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- ST_INPUT_CONT _a;
- _a.plineEdit = lineEdit1;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veInputCont.push_back(_a);
- }
- }
- else if (fieldType == "radio")
- {
-
- QStringList optionList = fieldUnits.split(QRegExp("[,,]"), Qt::SkipEmptyParts);
- QHBoxLayout* radioLayout = new QHBoxLayout;
- radioLayout->setSpacing(5);
- QButtonGroup* radioGroup = new QButtonGroup(rightWidget);
- for (const QString& optionText : optionList)
- {
- QString trimmedOpt = optionText.trimmed();
- if (trimmedOpt.isEmpty()) continue;
- QRadioButton* radioButton = new QRadioButton(trimmedOpt);
- radioGroup->addButton(radioButton);
- radioLayout->addWidget(radioButton);
- m_fieldWidgets.append(radioButton);
- if (fieldValue == trimmedOpt)
- {
- radioButton->setChecked(true);
- }
- }
-
-
-
-
-
-
-
-
-
-
- connect(radioGroup, static_cast<void (QButtonGroup::*)(QAbstractButton*, bool)>(&QButtonGroup::buttonToggled), [this, label](QAbstractButton* button, bool checked) {
- if (checked)
- {
- label->setProperty("value", button->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
-
-
- }
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- rightLayout->addLayout(radioLayout);
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, radioGroup]() {
- if (!fieldDefult.isEmpty()) {
- for (QAbstractButton* button : radioGroup->buttons()) {
- if (button->text() == fieldDefult) {
- button->setChecked(true);
- break;
- }
- }
- }
- });
- if (privilege < fieldUserGrade) {
- for (QAbstractButton* btn : radioGroup->buttons()) {
- btn->setEnabled(false);
- }
- btnDefault->setEnabled(false);
- }
- ST_RADIO_CONT _a;
- _a.pradioGroup = radioGroup;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veRadioCont.push_back(_a);
- }
- else if (fieldType == "checkbox" || fieldType == "BOOL")
- {
- bool isChecked;
- if (fieldValue == "")
- {
- isChecked = (fieldValue == "1");
- } else
- {
- isChecked = (fieldValue == "1");
- }
- QCheckBox* checkBox = new QCheckBox;
- checkBox->setChecked(isChecked);
- checkBox->setProperty("type", "checkBox");
-
- rightLayout->addWidget(checkBox);
- createdWidget = checkBox;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- connect(checkBox, &QCheckBox::stateChanged, [this, label](int state) {
- if (state == Qt::Checked)
- {
-
-
-
- label->setProperty("value", "1");
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
- }
- else if (state == Qt::Unchecked)
- {
-
-
-
-
- label->setProperty("value", "0");
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
- }
- else if (state == Qt::PartiallyChecked)
- {
- qDebug() << "CheckBox is partially checked";
-
- }
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, checkBox]() {
- if (!fieldDefult.isEmpty()) {
- if (fieldDefult == "1") {
- checkBox->setChecked(true);
- }
- else {
- checkBox->setChecked(false);
- }
- }
- });
- if (privilege < fieldUserGrade) {
- checkBox->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- ST_CHECKBOX_CONT _a;
- _a.pcheckBox = checkBox;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veCheckBoxCont.push_back(_a);
- }
- else if (fieldType == "ComboBox")
- {
-
- QJsonArray jsonArray;
- QJsonParseError parseError;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(fieldUnits.toUtf8(), &parseError);
- if (!jsonDoc.isNull() && jsonDoc.isArray()) {
- jsonArray = jsonDoc.array();
- }
- QComboBox* comboBox = new QComboBox;
- comboBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- comboBox->setFixedSize(140, 28);
-
-
-
- int matchedIndex = -1;
- int currentIndex = 0;
- for (const QJsonValue& val : jsonArray) {
- QJsonObject obj = val.toObject();
- QString key = obj["key"].toString();
- QString valueStr = QString::number(obj["value"].toInt());
- comboBox->addItem(key);
- if (valueStr == fieldValue.trimmed()) {
- matchedIndex = currentIndex;
- }
- currentIndex++;
- }
- comboBox->setCurrentIndex(matchedIndex != -1 ? matchedIndex : 0);
- rightLayout->addWidget(comboBox);
- createdWidget = comboBox;
-
-
-
-
-
-
-
-
-
- connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
- [this, comboBox, jsonArray, label](int index) {
- QString selectedText = comboBox->itemText(index);
- QString valueString;
- for (const QJsonValue& val : jsonArray) {
- QJsonObject obj = val.toObject();
- if (obj["key"].toString() == selectedText) {
- valueString = QString::number(obj["value"].toInt());
- break;
- }
- }
-
- label->setProperty("value", valueString);
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, comboBox, jsonArray]() {
- if (!fieldDefult.isEmpty()) {
- int matchedIndex = -1;
- int currentIndex = 0;
- for (const QJsonValue& val : jsonArray) {
- QJsonObject obj = val.toObject();
- QString key = obj["key"].toString();
- QString valueStr = QString::number(obj["value"].toInt());
- if (valueStr == fieldDefult.trimmed()) {
- matchedIndex = currentIndex;
- break;
- }
- currentIndex++;
- }
- comboBox->setCurrentIndex(matchedIndex != -1 ? matchedIndex : 0);
- }
- });
- if (privilege < fieldUserGrade) {
- comboBox->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- ST_COMBOBOX_CONT _a;
- _a.pcomboBox = comboBox;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veComboBoxCont.push_back(_a);
- } else if (fieldType == "time")
- {
- QTimeEdit* timeEdit = new QTimeEdit;
- timeEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- timeEdit->setFixedSize(120, 28);
-
- timeEdit->setDisplayFormat("HH:mm:ss");
- timeEdit->setTime(QTime::fromString(fieldValue, "HH:mm:ss"));
- rightLayout->addWidget(timeEdit);
- createdWidget = timeEdit;
- connect(timeEdit, &QTimeEdit::timeChanged, [this, timeEdit, label]() {
- QString timeString = timeEdit->time().toString("HH:mm:ss");
- label->setProperty("value", timeString);
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, timeEdit]() {
- if (!fieldDefult.isEmpty()) {
- timeEdit->setTime(QTime::fromString(fieldDefult, "HH:mm:ss"));
- }
- });
- if (privilege < fieldUserGrade) {
- timeEdit->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- ST_TIME_CONT _a;
- _a.ptimeEdit = timeEdit;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veTimeCont.push_back(_a);
- } else if (fieldType == "switch")
- {
- QWidget* switchContainer = new QWidget;
- QHBoxLayout* switchLayout = new QHBoxLayout(switchContainer);
- switchLayout->setSpacing(5);
- switchLayout->setContentsMargins(0, 0, 0, 0);
- QCheckBox* switchBox = new QCheckBox;
- switchBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- switchBox->setFixedSize(30, 30);
- switchBox->setProperty("type", "switch");
-
- QString switchValue;
- if (fieldValue == "")
- {
- switchValue = fieldValue.toLower();
- } else
- {
- switchValue = fieldValue.toLower();
- }
- if (switchValue == "on")
- switchBox->setChecked(true);
- else
- switchBox->setChecked(false);
- QLabel* switchLabel = new QLabel(switchBox->isChecked() ? tr("Open","开") :tr("Close","关"));
- switchLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- connect(switchBox, &QCheckBox::stateChanged, [switchLabel, this, label](int state) {
- if (state == Qt::Checked)
- {
- switchLabel->setText(tr("Open","开"));
- label->setProperty("value", "on");
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
- }
- else
- {
- switchLabel->setText(tr("Close","关"));
- label->setProperty("value", "off");
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
-
-
- }
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- switchLayout->addWidget(switchBox);
- switchLayout->addWidget(switchLabel);
- rightLayout->addWidget(switchContainer);
- createdWidget = switchBox;
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, switchBox, switchLabel]() {
- if (!fieldDefult.isEmpty()) {
- if (fieldDefult == "on") {
- switchBox->setChecked(true);
- switchLabel->setText(tr("Open", "开"));
- }
- else {
- switchBox->setChecked(false);
- switchLabel->setText(tr("Close", "关"));
- }
- }
- });
- if (privilege < fieldUserGrade) {
- switchBox->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- ST_SWITCH_CONT _a;
- _a.pswitchBox = switchBox;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veSwitchCont.push_back(_a);
- }
- else if (fieldType == "combined" || fieldType == "POSITION")
- {
-
- QStringList parts = fieldValue.split(QRegExp("[,,]"), Qt::SkipEmptyParts);
- QString inputText = (parts.size() >= 1 ? parts.at(0).trimmed() : QString());
- QString button1Text = (parts.size() >= 2 ? parts.at(1).trimmed() : QStringLiteral("获取"));
- QString button2Text = (parts.size() >= 3 ? parts.at(2).trimmed() : QStringLiteral("设置"));
- QLineEdit* comboInput = new QLineEdit(inputText);
- QRegularExpression regExp("^-?\\d*\\.?\\d*");
- QRegularExpressionValidator* validator = new QRegularExpressionValidator(regExp, this);
- comboInput->setValidator(validator);
- QString strID = fieldTableName;
- strID += "_";
- strID += fieldName;
- strID += +"_";
- strID += fieldDescribe;
- comboInput->setProperty("Input", strID);
- comboInput->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- comboInput->setFixedHeight(28);
-
- m_fieldWidgets.append(comboInput);
- QWidget* combinedWidget = new QWidget;
- QHBoxLayout* combinedLayout = new QHBoxLayout(combinedWidget);
- combinedLayout->setSpacing(5);
- combinedLayout->setContentsMargins(0, 0, 0, 0);
- QPushButton* btnGet = new QPushButton(button1Text, combinedWidget);
- QString strIDGet = fieldTableName;
- strIDGet += "_";
- strIDGet += fieldName;
- strIDGet += +"_";
- strIDGet += fieldDescribe;
- btnGet->setProperty("Get", strIDGet);
- btnGet->setFixedSize(80, 28);
- btnGet->setProperty("type", "default");
-
- connect(btnGet, &QPushButton::clicked, this, [this, comboInput, strstrModuleType, btnGet, strAxisType,fieldTableName, fieldName]()
- {
- double strNum = comboInput->text().toDouble();
-
-
- if (m_pTreeCViewInterface)
- {
- m_pTreeCViewInterface->GetViewMotion()->GetAxisPosition(strstrModuleType.toStdString(),
- strAxisType.toStdString(), strNum);
- }
-
- comboInput->text() = strNum;
-
-
-
-
-
-
- });
- m_fieldWidgets.append(btnGet);
- QPushButton* btnSet = new QPushButton(button2Text, combinedWidget);
- QString strIDSet = fieldTableName;
- strIDSet += "_";
- strIDSet += fieldName;
- strIDSet += +"_";
- strIDSet += fieldDescribe;
- btnSet->setProperty("set", strIDSet);
- btnSet->setFixedSize(80, 28);
- btnSet->setProperty("type", "default");
-
- connect(btnSet, &QPushButton::clicked, this, [this, comboInput, strstrModuleType, btnGet, strAxisType, fieldTableName, fieldName]()
- {
- QPushButton* senderBtn = qobject_cast<QPushButton*>(sender());
- if (senderBtn) {
- QString strOnclick = senderBtn->property("set").toString();
- qDebug() << "btnSet ID:" << strOnclick;
- }
- double strNum = comboInput->text().toDouble();
- if (m_pTreeCViewInterface)
- {
- m_pTreeCViewInterface->GetViewMotion()->ModuleMoveTo(strstrModuleType.toStdString(),
- strAxisType.toStdString(), strNum);
- }
-
- });
- m_fieldWidgets.append(btnSet);
- combinedLayout->addWidget(comboInput);
- combinedLayout->addWidget(btnGet);
- combinedLayout->addWidget(btnSet);
- combinedLayout->addStretch();
- rightLayout->addWidget(combinedWidget);
-
- ST_COMBINED_CONT _a;
- _a.pGetBut = btnGet;
- _a.pSetBut = btnSet;
- _a.pLineC = comboInput;
- _a.strConfigurationsName = fieldTableName;
- _a.strfieldName = fieldName;
- _a.strfieldDescribe = fieldDescribe;
- m_veCombinedCont.push_back(_a);
- connect(comboInput, &QLineEdit::textChanged, [this, comboInput, label]() {
- label->setProperty("value", comboInput->text());
- label->setDisabled(true);
-
- modifiedLabels.insert(label);
- });
- connect(this, &DbTreeViewManager::saveClicked, [this, fieldTableName, fieldName, label]() {
- if (modifiedLabels.contains(label)) {
- m_sqlOper->updateControlData(fieldTableName, fieldName, label->property("value").toString());
- label->setDisabled(false);
-
- modifiedLabels.remove(label);
- }
- });
- QPushButton* btnDefault = new QPushButton(QStringLiteral("默认"));
- btnDefault->setFixedSize(60, 28);
- btnDefault->setProperty("type", "default");
-
- rightLayout->addWidget(btnDefault);
- connect(btnDefault, &QPushButton::clicked, [this, fieldDefult, comboInput]() {
- if (!fieldDefult.isEmpty()) {
- comboInput->setText(fieldDefult);
- }
- });
- if (privilege < fieldUserGrade) {
- comboInput->setEnabled(false);
- btnSet->setEnabled(false);
- btnGet->setEnabled(false);
- btnDefault->setEnabled(false);
- }
- }
- else if (fieldType == "Text")
- {
- QLabel* label = new QLabel();
- label->setText(fieldValue);
- label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
- label->setFixedHeight(24);
- label->setMinimumWidth(120);
- rightLayout->addWidget(label);
- }
- else if (fieldType == "IoPage")
- {
- rightLayout->addWidget(JIoMapPage::CreateIoPage(control));
- }
- else if (fieldType == "AxisTestPage")
- {
- rightLayout->addWidget(JIoMapPage::CreateAxisTestPage(control));
- }
- else
- {
- qWarning() << "未知字段类型:" << fieldType;
- }
- if (createdWidget)
- {
- m_fieldWidgets.append(createdWidget);
- }
- fieldLayout->addWidget(rightWidget);
- scrollLayout->addLayout(fieldLayout);
- }
- }
- }
- scrollLayout->addStretch();
- scrollArea->setWidget(scrollWidget);
- QVBoxLayout* mainLayout = new QVBoxLayout(m_thirdLevelFieldWnd);
- mainLayout->setContentsMargins(0, 0, 0, 0);
- mainLayout->addWidget(scrollArea);
- m_thirdLevelFieldWnd->show();
-
- displayThirdLevelButtons(buttonControls);
-
- }
- void DbTreeViewManager::updateParentCheckState(QStandardItem *item)
- {
- if (!item)
- return;
- QStandardItem *parentItem = item->parent();
- if (!parentItem)
- return;
- bool allChecked = true;
- bool noneChecked = true;
- for (int i = 0; i < parentItem->rowCount(); ++i) {
- QStandardItem *child = parentItem->child(i);
- if (child->checkState() != Qt::Checked) {
- allChecked = false;
- }
- if (child->checkState() == Qt::Checked) {
- noneChecked = false;
- }
- }
- if (allChecked) {
- parentItem->setCheckState(Qt::Checked);
- } else {
- parentItem->setCheckState(Qt::Unchecked);
- }
- if (noneChecked) {
- qDebug() << "noneChecked状态为:" << noneChecked;
- }
-
- updateParentCheckState(parentItem);
- }
- void DbTreeViewManager::onButtonBackClicked()
- {
- promptSaveChanges();
- if (m_thirdLevelFieldWnd) {
-
-
- for(int i=0;i<5;i++){
- if(currentMenuId == menuArray[i].menuId){
- menuArray[i].isthird = false;
- }
- }
-
- m_thirdLevelFieldWnd->close();
- m_thirdLevelFieldWnd->deleteLater();
- m_thirdLevelFieldWnd = nullptr;
-
- m_pTreeViewDown->show();
- for (auto separator : m_mapFirstLevelSeparators) {
- if (separator)
- separator->show();
- }
-
- QStringList path;
- QLayout* layout = m_pNavigationWidget->layout();
- if (!layout) {
- qWarning() << "导航栏没有布局,无法获取路径。";
- return;
- }
- for (int i = 0; i < layout->count(); ++i) {
- QLayoutItem* item = layout->itemAt(i);
- if (item && item->widget()) {
- QLabel* label = qobject_cast<QLabel*>(item->widget());
- if (label) {
- QString text = label->text().trimmed();
- if (!text.isEmpty()) {
- path << text;
- }
- }
- }
- }
- if (path.isEmpty()) {
-
- return;
- }
-
- path.removeLast();
- if (path.isEmpty()) {
-
- return;
- }
-
- QModelIndex parentIndex = findItemByPath(path);
- if (!parentIndex.isValid()) {
-
- return;
- }
-
- m_pTreeViewDown->setCurrentIndex(parentIndex);
- m_pTreeViewDown->scrollTo(parentIndex);
-
- updateNavigationBar(parentIndex);
-
- QStandardItem* parentItem = m_pCModel->itemFromIndex(parentIndex);
- if (!parentItem) {
- qWarning() << "父目录项无效。";
- return;
- }
- QVariant dataVar = parentItem->data(Qt::UserRole + 2);
- bool isThirdLevel = false;
- int directoryId = -1;
- QString multiTableName = "";
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject dataObj = dataVar.toJsonObject();
- if (dataObj.contains("IsThirdLevel") && dataObj["IsThirdLevel"].toBool()) {
- isThirdLevel = true;
- if (dataObj.contains("Id")) {
- directoryId = dataObj["Id"].toInt();
- }
- if (dataObj.contains("TableName"))
- {
- multiTableName = dataObj["TableName"].toString();
- }
- }
- }
- if (isThirdLevel) {
- if (directoryId == -1) {
- qWarning() << "无效的 DirectoryId,无法加载第三层目录内容。";
- return;
- }
- int userPrivilege = 0x1;
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData(multiTableName, userPrivilege, tableControlDatas, allChangeFlag);
- displayThirdLevelFields(tableControlDatas, allChangeFlag, false);
-
-
-
-
-
- } else {
-
- m_pTreeViewDown->show();
- for (auto separator : m_mapFirstLevelSeparators) {
- if (separator)
- separator->show();
- }
- }
- return;
- }
-
-
- QModelIndex currentIndex = m_pTreeViewDown->currentIndex();
- if (!currentIndex.isValid()) {
-
- return;
- }
- QStandardItem* currentItem = m_pCModel->itemFromIndex(currentIndex);
- if (!currentItem) {
-
- return;
- }
- QStandardItem* parentItem = currentItem->parent();
- if (!parentItem) {
-
- return;
- }
- QModelIndex parentIndex = m_pCModel->indexFromItem(parentItem);
- if (!parentIndex.isValid()) {
-
- return;
- }
-
- m_pTreeViewDown->setCurrentIndex(parentIndex);
- m_pTreeViewDown->scrollTo(parentIndex);
-
- updateNavigationBar(parentIndex);
-
- QVariant dataVar = parentItem->data(Qt::UserRole + 2);
- bool isThirdLevel = false;
- int directoryId = -1;
- QString multiTableName = "";
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject dataObj = dataVar.toJsonObject();
- if (dataObj.contains("IsThirdLevel") && dataObj["IsThirdLevel"].toBool()) {
- isThirdLevel = true;
- if (dataObj.contains("Id")) {
- directoryId = dataObj["Id"].toInt();
- }
- if (dataObj.contains("TableName"))
- {
- multiTableName = dataObj["TableName"].toString();
- }
- }
- }
- if (isThirdLevel) {
- if (directoryId == -1) {
- qWarning() << "无效的 DirectoryId,无法加载第三层目录内容。";
- return;
- }
- int userPrivilege = 0x1;
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData(multiTableName, userPrivilege, tableControlDatas, allChangeFlag);
- displayThirdLevelFields(tableControlDatas, allChangeFlag, false);
-
-
- }
- }
- QList<QStandardItem*> DbTreeViewManager::collectAllThirdLevelItems()
- {
- QList<QStandardItem*> result;
-
- QStandardItem *root = m_pCModel->invisibleRootItem();
- if (!root) return result;
- std::function<void(QStandardItem*)> dfsCollectThirdLevel;
- dfsCollectThirdLevel = [&](QStandardItem* parentItem)
- {
- if (!parentItem) return;
- int rowCount = parentItem->rowCount();
- for (int i = 0; i < rowCount; ++i) {
- QStandardItem *child = parentItem->child(i);
- if (!child) continue;
-
- QVariant dataVar = child->data(Qt::UserRole + 2);
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject obj = dataVar.toJsonObject();
- if (obj.contains("IsThirdLevel") && obj["IsThirdLevel"].toBool()) {
-
- result.append(child);
- }
- }
-
- dfsCollectThirdLevel(child);
- }
- };
- dfsCollectThirdLevel(root);
- return result;
- }
- void DbTreeViewManager::onButtonDownClicked()
- {
- promptSaveChanges();
-
- QList<QStandardItem*> thirdLevelList = collectAllThirdLevelItems();
- if (thirdLevelList.isEmpty()) {
-
- return;
- }
-
- QModelIndex curIndex = m_pTreeViewDown->currentIndex();
- if (!curIndex.isValid()) {
-
-
- QStandardItem *firstItem = thirdLevelList.first();
- QModelIndex idx = m_pCModel->indexFromItem(firstItem);
- m_pTreeViewDown->setCurrentIndex(idx);
-
- onTreeViewClicked_updown(idx);
-
- saveCheckedPaths();
-
- saveExpandedPaths();
- return;
- }
- QStandardItem *curItem = m_pCModel->itemFromIndex(curIndex);
- if (!curItem) {
-
- return;
- }
-
- int currentPos = -1;
- {
-
- currentPos = thirdLevelList.indexOf(curItem);
- if (currentPos < 0) {
-
-
- QStandardItem *temp = curItem->parent();
- while (temp) {
- int pos = thirdLevelList.indexOf(temp);
- if (pos >= 0) {
- currentPos = pos;
- break;
- }
- temp = temp->parent();
- }
- if (currentPos < 0) {
-
- QStandardItem *firstItem = thirdLevelList.first();
- QModelIndex idx = m_pCModel->indexFromItem(firstItem);
- m_pTreeViewDown->setCurrentIndex(idx);
- onTreeViewClicked_updown(idx);
-
- saveCheckedPaths();
-
- saveExpandedPaths();
- return;
- }
- }
- }
-
- int nextPos = currentPos + 1;
- if (nextPos >= thirdLevelList.size()) {
-
- return;
- }
-
- QStandardItem *nextItem = thirdLevelList[nextPos];
- QModelIndex nextIndex = m_pCModel->indexFromItem(nextItem);
- m_pTreeViewDown->setCurrentIndex(nextIndex);
-
- onTreeViewClicked_updown(nextIndex);
-
- saveCheckedPaths();
-
- saveExpandedPaths();
- }
- void DbTreeViewManager::onButtonUpClicked()
- {
- promptSaveChanges();
-
- QList<QStandardItem*> thirdLevelList = collectAllThirdLevelItems();
- if (thirdLevelList.isEmpty()) {
-
- return;
- }
-
- QModelIndex curIndex = m_pTreeViewDown->currentIndex();
- if (!curIndex.isValid()) {
-
-
- QStandardItem *lastItem = thirdLevelList.last();
- QModelIndex idx = m_pCModel->indexFromItem(lastItem);
- m_pTreeViewDown->setCurrentIndex(idx);
-
- onTreeViewClicked_updown(idx);
-
- saveCheckedPaths();
-
- saveExpandedPaths();
- return;
- }
- QStandardItem *curItem = m_pCModel->itemFromIndex(curIndex);
- if (!curItem) {
- qWarning() << "[onButtonUpClicked] currentItem 无效。";
- return;
- }
-
- int currentPos = thirdLevelList.indexOf(curItem);
- if (currentPos < 0) {
-
- QStandardItem *temp = curItem->parent();
- while (temp) {
- int pos = thirdLevelList.indexOf(temp);
- if (pos >= 0) {
- currentPos = pos;
- break;
- }
- temp = temp->parent();
- }
- if (currentPos < 0) {
-
- QStandardItem *lastItem = thirdLevelList.last();
- QModelIndex idx = m_pCModel->indexFromItem(lastItem);
- m_pTreeViewDown->setCurrentIndex(idx);
- onTreeViewClicked_updown(idx);
-
- saveCheckedPaths();
-
- saveExpandedPaths();
- return;
- }
- }
-
- int prevPos = currentPos - 1;
- if (prevPos < 0) {
-
- return;
- }
-
- QStandardItem *prevItem = thirdLevelList[prevPos];
- QModelIndex prevIndex = m_pCModel->indexFromItem(prevItem);
- m_pTreeViewDown->setCurrentIndex(prevIndex);
-
- onTreeViewClicked_updown(prevIndex);
-
- saveCheckedPaths();
-
- saveExpandedPaths();
- }
- void DbTreeViewManager::onButtonRightClicked()
- {
- promptSaveChanges();
- if (m_forwardStack.isEmpty()) {
-
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
- return;
- }
-
- PageState st = m_forwardStack.takeLast();
-
- PageState cur = getCurrentPageState();
- m_backStack.append(cur);
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
-
- loadPageState(st, true);
- }
- void DbTreeViewManager::onButtonLeftClicked()
- {
- promptSaveChanges();
- if (m_backStack.size() < 2) {
-
- buttonLeft->setIcon(QIcon(":/images/home_left_hide.png"));
- return;
- }
-
- PageState cur = m_backStack.takeLast();
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }else{
- buttonLeft->setIcon(QIcon(":/images/home_left_hide.png"));
- }
- m_forwardStack.append(cur);
- buttonRight->setIcon(QIcon(":/images/home_right_show.png"));
-
- const PageState &prev = m_backStack.last();
-
- loadPageState(prev, true );
- }
- QStringList DbTreeViewManager::buildItemPath(QStandardItem *item)
- {
- QStringList path;
- QStandardItem *currentItem = item;
- while (currentItem) {
- path.prepend(currentItem->text());
- currentItem = currentItem->parent();
- }
- return path;
- }
- QModelIndex DbTreeViewManager::findItemByPath(const QStringList &path)
- {
- if (path.isEmpty()) return QModelIndex();
- QStandardItem *currentItem = m_pCModel->invisibleRootItem();
- QModelIndex currentIndex;
- for (const QString &part : path) {
- bool found = false;
- for (int i = 0; i < currentItem->rowCount(); ++i) {
- QStandardItem *child = currentItem->child(i);
- if (child == nullptr)
- {
-
- }
- if (child->text() == part) {
- currentIndex = m_pCModel->indexFromItem(child);
- currentItem = child;
- found = true;
-
- break;
- }
- }
- if (!found) {
- qWarning() << "路径部分未找到:" << part;
- return QModelIndex();
- }
- }
- return currentIndex;
- }
- void DbTreeViewManager::setCheckedPaths(const QStringList &checkedPathsList)
- {
- m_blockItemChanged = true;
- for (const QString &pathStr : checkedPathsList) {
- QStringList path = pathStr.split("/");
- QModelIndex idx = findItemByPath(path);
- if (idx.isValid()) {
- QStandardItem *item = m_pCModel->itemFromIndex(idx);
- if (item) {
- item->setCheckState(Qt::Checked);
-
- }
- } else {
-
- }
- }
- m_blockItemChanged = false;
- }
- QStringList DbTreeViewManager::collectCheckedPathsRecursive(QStandardItem *item, QStringList path)
- {
- QStringList checkedList;
- if (!item) {
- item = m_pCModel->invisibleRootItem();
- }
- for (int i = 0; i < item->rowCount(); ++i) {
- QStandardItem *child = item->child(i);
- if (child) {
- QStringList currentPath = path;
- currentPath << child->text();
- if (child->checkState() == Qt::Checked) {
- checkedList << currentPath.join("/");
- }
-
- checkedList << collectCheckedPathsRecursive(child, currentPath);
- }
- }
- return checkedList;
- }
- QStringList DbTreeViewManager::collectCheckedPaths()
- {
- return collectCheckedPathsRecursive(m_pCModel->invisibleRootItem(), QStringList());
- }
- void DbTreeViewManager::updateParentItems(QStandardItem *parentItem)
- {
- if (!parentItem)
- return;
- int checkedCount = 0;
- int totalCount = parentItem->rowCount();
-
- for (int i = 0; i < totalCount; ++i)
- {
- QStandardItem *child = parentItem->child(i);
- if (child && child->checkState() == Qt::Checked)
- {
- checkedCount++;
- }
- }
- if (checkedCount == totalCount)
- {
- parentItem->setCheckState(Qt::Checked);
- }
- else
- {
- parentItem->setCheckState(Qt::Unchecked);
- }
-
- updateParentItems(parentItem->parent());
- }
- void DbTreeViewManager::displayThirdLevelButtons(const QList<CONFIG_BASE_STRUCT>& buttons)
- {
- if (!m_originalWnd)
- {
- qWarning() << "OriginalWnd 指针为空,无法加载按钮配置";
- return;
- }
-
- QWidget* widgetLeft = m_originalWnd->getWidgetLeft();
- if (!widgetLeft)
- {
- qWarning() << "无法访问 widget_left";
- return;
- }
-
- QList<QPushButton*> existingButtons = widgetLeft->findChildren<QPushButton*>();
- for (QPushButton* button : existingButtons)
- {
- QString objName = button->objectName();
- if (button->objectName().startsWith("thirdLevelBtn_F"))
- {
- button->deleteLater();
- }
- }
-
- for (int i = 0; i < buttons.size() && i < 12; ++i)
- {
- int buttonId = buttons[i].iGroupId;
- QString buttonIcon = QString::fromStdString(buttons[i].sIcon);
- QString buttonText = QString::fromStdString(buttons[i].strName);
- QString strCallFun = QString::fromStdString(buttons[i].strCallFun);
- bool isEnabled = buttons[i].bEnable;
-
-
-
-
-
-
-
-
-
-
-
- QPushButton *button = new QPushButton(widgetLeft);
- QString ObjectName = "thirdLevelBtn_F" + QString::number(buttonId);
- button->setObjectName(ObjectName);
- ObjectName = button->objectName();
- connect(button, &QPushButton::clicked, this, [&, strCallFun, buttonId]()
- {
- ns_module::ST_BUTTON_FUN callFun = {};
-
- callFun.strCallFun = strCallFun.toStdString();
- callFun.nId = buttonId;
- emit RunFunSignals(callFun);
- });
- button->setProperty("type", "left");
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (buttonId > 12)
- {
- qWarning() << "buttonId 超过最大ID";
- continue;
- }
-
- int x = 16;
- int y = 245 + (buttonId - 1) * (48 + 13);
- button->setGeometry(x, y, 158, 48);
-
- button->setVisible(isEnabled);
-
- QLabel* iconLabel = new QLabel(button);
- iconLabel->setPixmap(QIcon(buttonIcon).pixmap(16, 16));
- iconLabel->setGeometry(10, 16, 16, 16);
- iconLabel->setFixedSize(16, 16);
-
- iconLabel->setVisible(isEnabled);
-
- QLabel* textLabel = new QLabel(buttonText, button);
- textLabel->setGeometry(34, 0, 90, 48);
- textLabel->setWordWrap(true);
- textLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- textLabel->setProperty("type", "text");
-
- textLabel->setVisible(isEnabled);
-
- QString fLabelText = QString("F%1").arg(buttonId);
- QLabel* fLabel = new QLabel(fLabelText, button);
- fLabel->setFixedSize(21, 16);
- fLabel->setAlignment(Qt::AlignCenter);
- fLabel->setProperty("type", "f");
-
-
- int fX = 134;
- int fY = 2;
- fLabel->setGeometry(fX, fY, 14, 16);
- fLabel->setVisible(isEnabled);
-
- m_fieldWidgets.append(button);
- m_fieldWidgets.append(iconLabel);
- m_fieldWidgets.append(textLabel);
- m_fieldWidgets.append(fLabel);
- }
- }
- void DbTreeViewManager::clearThirdLevelMenu()
- {
-
- foreach (QObject *child, m_pOriginalWndMenuPage->children())
- {
- QWidget *childWidget = qobject_cast<QWidget*>(child);
- if (childWidget && childWidget->windowTitle() == m_strShowName)
- {
- JLogAllOutput::cmd_debug("关闭现有的字段展示窗口");
- childWidget->close();
- }
- }
-
- m_pTreeViewDown->show();
- for (auto separator : m_mapFirstLevelSeparators)
- {
- separator->show();
- }
- }
- void DbTreeViewManager::saveCheckedPaths()
- {
- if (m_currentConfigName == "") {
- qWarning() << "当前配置ID无效,无法保存复选框状态。";
- return;
- }
- QSettings settings("RunCloudTech", "David");
-
- settings.beginGroup("TreeViewCheckedState");
-
- QString keyChecked = QString("checkedPaths/%1").arg(m_currentConfigName);
- QStringList checkedList = collectCheckedPaths();
- settings.setValue(keyChecked, checkedList);
- settings.endGroup();
-
- }
- void DbTreeViewManager::loadCheckedPaths()
- {
- if (m_currentConfigName == "") {
-
- return;
- }
- QSettings settings("RunCloudTech", "David");
-
- settings.beginGroup("TreeViewCheckedState");
-
- QString keyChecked = QString("checkedPaths/%1").arg(m_currentConfigName);
- QStringList loadedChecked = settings.value(keyChecked).toStringList();
- settings.endGroup();
-
- m_blockItemChanged = true;
- setCheckedPaths(loadedChecked);
- m_blockItemChanged = false;
-
- if (!loadedChecked.isEmpty()) {
- QString lastPathStr = loadedChecked.last();
- QStringList lastPath = lastPathStr.split("/");
- QModelIndex lastIdx = findItemByPath(lastPath);
- if (lastIdx.isValid()) {
- m_pTreeViewDown->setCurrentIndex(lastIdx);
- updateNavigationBar(lastIdx);
- }
- } else {
-
- QStandardItem *rootItem = m_pCModel->invisibleRootItem();
- if (rootItem->rowCount() > 0) {
- QModelIndex firstIndex = m_pCModel->index(0, 0, QModelIndex());
- if (firstIndex.isValid()) {
- m_pTreeViewDown->setCurrentIndex(firstIndex);
- m_pTreeViewDown->expand(firstIndex);
- QStandardItem *firstItem = m_pCModel->itemFromIndex(firstIndex);
- QVariant data = firstItem->data(Qt::UserRole + 2);
- if (data.canConvert<QJsonObject>()) {
- QJsonObject thirdLevelObj = data.toJsonObject();
- if (thirdLevelObj.contains("IsThirdLevel") && thirdLevelObj["IsThirdLevel"].toBool()) {
- QString multiTableName = "";
- if (thirdLevelObj.contains("TableName")) {
- multiTableName = thirdLevelObj["TableName"].toString();
- }
- QList<CONFIG_BASE_STRUCT> buttons;
- int userGrade = 0x1;
- m_sqlOper->GetThirdDirButtons(multiTableName, userGrade, buttons);
- displayThirdLevelButtons(buttons);
-
- }
- }
- }
- }
- }
- }
- void DbTreeViewManager::saveExpandedPaths()
- {
- if (m_currentConfigName == "") {
- qWarning() << "当前配置ID无效,无法保存展开路径。";
- return;
- }
- QSettings settings("RunCloudTech", "David");
-
- settings.beginGroup("TreeViewExpandedState");
-
- QString keyExpanded = QString("expandedPaths/%1").arg(m_currentConfigName);
- QStringList expandedList = QStringList(expandedPaths.begin(), expandedPaths.end());
- settings.setValue(keyExpanded, expandedList);
- settings.endGroup();
-
- }
- void DbTreeViewManager::loadExpandedPaths()
- {
- if (m_currentConfigName == "") {
-
- return;
- }
- QSettings settings("RunCloudTech", "David");
-
- settings.beginGroup("TreeViewExpandedState");
-
- QString keyExpanded = QString("expandedPaths/%1").arg(m_currentConfigName);
- QStringList loadedExpanded = settings.value(keyExpanded).toStringList();
- settings.endGroup();
-
- m_blockItemChanged = true;
-
- for (const QString &p : loadedExpanded) {
- QStringList path = p.split("/");
- QModelIndex idx = findItemByPath(path);
- if (idx.isValid()) {
- m_pTreeViewDown->expand(idx);
- expandedPaths.insert(p);
-
- } else {
-
- }
- }
- m_blockItemChanged = false;
- }
- void DbTreeViewManager::Level3MenuAllSaveBut(QVBoxLayout* pVBox)
- {
- QHBoxLayout* fieldLayout = new QHBoxLayout;
- fieldLayout->setSpacing(5);
- QPushButton* pSaveBut = new QPushButton(tr("Save", "保存"));
- pSaveBut->setFixedSize(80, 28);
- pSaveBut->setProperty("type", "save");
-
- QSpacerItem * spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
- fieldLayout->addSpacerItem(spacer);
-
- m_fieldWidgets.append(pSaveBut);
- connect(pSaveBut, &QPushButton::clicked, this, [=]()
- {
- if (modifiedLabels.isEmpty())
- {
- JMessageTip::Message_information(tr("No components were modified!", "没有任何组件被修改!"), this);
- }
- else
- {
- if (JMessageTip::Message_question(tr("Modifications detected, do you want to save?", "检测到修改内容,是否保存?"), this) == QMessageBox::Yes)
- {
- emit saveClicked();
- }
- }
- });
- fieldLayout->addWidget(pSaveBut);
- pVBox->addLayout(fieldLayout);
- }
- void DbTreeViewManager::promptSaveChanges() {
- if (!modifiedLabels.isEmpty()) {
- if (JMessageTip::Message_question(tr("Modifications detected, do you want to save?", "检测到修改内容,是否保存?"), this) == QMessageBox::Yes) {
- emit saveClicked();
- return;
- }
- else
- {
- modifiedLabels.clear();
- return;
- }
- }
- return;
- }
- void DbTreeViewManager::clearHistory()
- {
- m_backStack.clear();
- m_forwardStack.clear();
- buttonLeft->setIcon(QIcon(":/images/home_left_hide.png"));
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
- }
- DbTreeViewManager::PageState DbTreeViewManager::getCurrentPageState()
- {
- PageState st;
- st.isThirdLevel = false;
- st.directoryId = -1;
-
- if (m_thirdLevelFieldWnd && m_thirdLevelFieldWnd->isVisible()) {
-
- QModelIndex curIndex = m_pTreeViewDown->currentIndex();
- if (!curIndex.isValid()) {
- st.path << "未知目录";
- } else {
- QStandardItem* item = m_pCModel->itemFromIndex(curIndex);
- st.path = buildItemPath(item);
- }
-
- QVariant dataVar = m_pCModel->itemFromIndex(m_pTreeViewDown->currentIndex())->data(Qt::UserRole + 2);
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject obj = dataVar.toJsonObject();
- if (obj.contains("IsThirdLevel") && obj["IsThirdLevel"].toBool()) {
- st.isThirdLevel = true;
- st.directoryId = obj.value("Id").toInt(-1);
- st.multiTableName = obj.value("TableName").toString();
- }
- }
- }
- else {
-
- QModelIndex curIndex = m_pTreeViewDown->currentIndex();
- if (curIndex.isValid()) {
- QStandardItem* item = m_pCModel->itemFromIndex(curIndex);
- st.path = buildItemPath(item);
-
- QVariant dataVar = item->data(Qt::UserRole + 2);
- if (dataVar.canConvert<QJsonObject>()) {
- QJsonObject obj = dataVar.toJsonObject();
- if (obj.contains("IsThirdLevel") && obj["IsThirdLevel"].toBool()) {
- st.isThirdLevel = true;
- st.directoryId = obj.value("Id").toInt(-1);
- st.multiTableName = obj.value("TableName").toString();
- }
- }
- }
- }
- return st;
- }
- void DbTreeViewManager::loadPageState(const PageState &st, bool isByHistoryNav)
- {
-
- QModelIndex idx = findItemByPath(st.path);
- if (!idx.isValid()) {
- qWarning() << "[loadPageState] 未找到路径" << st.path;
- return;
- }
-
- m_pTreeViewDown->setCurrentIndex(idx);
- m_pTreeViewDown->scrollTo(idx);
-
- updateNavigationBar(idx);
-
- if (st.isThirdLevel && st.directoryId != -1) {
-
- if (m_thirdLevelFieldWnd) {
- m_thirdLevelFieldWnd->close();
- m_thirdLevelFieldWnd->deleteLater();
- m_thirdLevelFieldWnd = nullptr;
- }
- int userPrivilege = 0x1;
- QList<ST_TABLE_CONTROL_DATA> tableControlDatas;
- bool allChangeFlag = false;
- m_sqlOper->GetThirdDirControlData(st.multiTableName, userPrivilege, tableControlDatas, allChangeFlag);
- displayThirdLevelFields(tableControlDatas, allChangeFlag, false);
-
-
- } else {
-
- if (m_thirdLevelFieldWnd) {
- m_thirdLevelFieldWnd->close();
- m_thirdLevelFieldWnd->deleteLater();
- m_thirdLevelFieldWnd = nullptr;
- }
- m_pTreeViewDown->show();
- for (auto sep : m_mapFirstLevelSeparators) {
- if (sep) sep->show();
- }
- }
- if (!isByHistoryNav) {
- m_forwardStack.clear();
- buttonRight->setIcon(QIcon(":/images/home_right.png"));
-
- m_backStack.append(st);
- if(m_backStack.size() >= 2){
- buttonLeft->setIcon(QIcon(":/images/home_left.png"));
- }
- }
- }
- void DbTreeViewManager::loginput(const QString& fieldTableName, const QString& fieldName,const QString& modifies){
-
- QDateTime currentDateTime = QDateTime::currentDateTime();
- QString timestamp = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
- QString logMessage = QString("%1 :fieldTableName is %2 and fieldName is %3 ,currentvalue is modified %4" ).arg(timestamp).arg(fieldTableName).arg(fieldName).arg(modifies);
- QString pathoflog = "C:\\Users\\Administrator\\Desktop\\qt\\merge\\gujiangdong\\die-bonder-ui0218\\die-bonder-ui\\log/log.txt";
- writeLogToFile(logMessage,pathoflog);
- }
- void DbTreeViewManager::writeLogToFile(const QString& logMessage, const QString& filePath) {
- QFile logFile(filePath);
- if (!logFile.open(QIODevice::Append | QIODevice::Text)) {
- qWarning() << "Cannot open file for writing:" << filePath;
- return;
- }
- QTextStream out(&logFile);
- out << logMessage << "\n";
- logFile.close();
- }
|