Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Gantt Chart Not Updating
Forum Updated to NodeBB v4.3 + New Features

Gantt Chart Not Updating

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 394 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Phamy1289
    wrote on last edited by
    #1

    I have a gantt chart, using KDGantt, that is not updating when the user clicks a few buttons and hits the submit button. The GUI initializes with an empty gantt chart as intended, but after clicking the button in the other tab where the user makes the selections and clicks the button, the gantt chart doesn't show anything even thought the QStandardItemModel isn't empty.

    I'm using a signal/slot to send the data from the class that allows to the user to make the selections and click submit to the class that contains the gantt chart.

    Any help would be appreciated.

    The Gantt Chart Class

    ScheduleAdvice::ScheduleAdvice(QString title, QMainWindow *parent) : QDockWidget(title, parent)
    {
        ScheduleInput *sendData = new ScheduleInput();
        setObjectName(title);
        mspInstance = this;
    
        //Set Schedular tab panel.
        setFeatures( QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
        setFocusPolicy(Qt::StrongFocus);
    
        QPalette backgroundColor(palette());
        backgroundColor.setColor(QPalette::Background, Qt::black);
    
        QGridLayout *pGrid = new QGridLayout;
        QWidget *pBaseWidget = new QWidget;
    
        pBaseWidget->setAutoFillBackground(true);
        pBaseWidget->setPalette(backgroundColor);
    
        pBaseWidget->setMaximumWidth(800);
        pBaseWidget->setMaximumHeight(2000);
    
        pBaseWidget->setLayout(pGrid);
        setWidget(pBaseWidget);
    
        mpModel = new QStandardItemModel;
    
        connect(sendData, SIGNAL(transferDataSignal(QJsonDocument)), this, SLOT(dataTransferSlot(QJsonDocument)));
    
        QString scheduleName;
        for(int index = 0; index < mTxArray.size(); ++index){
            int i = rand()%mTxArray.size();
            int j = rand()%mRxArray.size();
    
            QString iString = QString::number(mTxArray.at(i).toInt());
            QString jString = QString::number(mRxArray.at(j).toInt());
            scheduleName = iString + "+" + jString;
    
            mpItem = new QStandardItem(QString(scheduleName));
            mpItem->appendRow(QList<QStandardItem*>()
                              << new MyStandardItem(QString(scheduleName))
                              << new MyStandardItem(KDGantt::TypeTask)
                              << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(00, 00, 00)), KDGantt::StartTimeRole)
                              << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(12, 00, 00)), KDGantt::EndTimeRole)
                              );
    
            mpModel->appendRow(QList<QStandardItem*>()
                               << mpItem
                               << new MyStandardItem(KDGantt::TypeMulti)
                               );
        }
    
        // Set widget to fit docker widget appropriately.
        KDGantt::View *view = new KDGantt::View();
    
        // Define graph header to a 24hour period
        KDGantt::DateTimeGrid *grid = new KDGantt::DateTimeGrid;
    
        grid->setUserDefinedUpperScale(new KDGantt::DateTimeScaleFormatter(KDGantt::DateTimeScaleFormatter::Hour,
                                       QString("hh"),
                                       Qt::AlignLeft));
    
        // "Removes" the lower header column of the graph.
        grid->setUserDefinedLowerScale(new KDGantt::DateTimeScaleFormatter(KDGantt::DateTimeScaleFormatter::Hour,
                                       QString()));
    
        //Set bar graph to display 24hour periods
        grid->setScale(KDGantt::DateTimeGrid::ScaleUserDefined);
        grid->setDayWidth(500);
        grid->setRowSeparators(true);
    
        // Have the bars become blue instead of green.
        QBrush myBrush(Qt::blue);
        view->graphicsView()->itemDelegate()->setDefaultBrush(KDGantt::TypeTask,
                                                              myBrush);
        view->setGrid(grid);
        view->setModel(mpModel);
        view->update();
    
        // Make it so the user can't change the bars' position.
        view->graphicsView()->setReadOnly(true);
        view->graphicsView()->setStyleSheet("background:gray");
    
        connect(view->graphicsView(), SIGNAL(clicked(QModelIndex)), this, SLOT(onSelected(QModelIndex)));
    
        view->leftView()->setStyleSheet("background:gray");
        view->leftView()->setMaximumWidth(100);
        view->show();
    
        pGrid->update();
        pGrid->addWidget(view, 0, 0, 1, 2);
        pGrid->addWidget(mpDateTimeGroup(), 1, 0, 1, 2);
        pGrid->addWidget(mpRxTableGroup(), 2, 1, 1, 1);
        pGrid->addWidget(mpTxTableGroup(), 2, 0, 1, 1);
    
    }
    

    Slot Function

    void ScheduleAdvice::dataTransferSlot(QJsonDocument doc){
        if(doc.isEmpty()){
            std::cout << "Received empty document." << endl;
        } else {
            mObject = doc.object();
    
            setGanttModel(mObject);
        }
    }
    
    void ScheduleAdvice::setGanttModel(QJsonObject object){
        mTxArray = object["txIds"].toArray();
        mRxArray = object["rxIds"].toArray();
    }
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      Phamy1289
      wrote on last edited by
      #2

      I figured what I was missing. I needed to call the instance in my setGanttModel function.

      mspInstance->mpModel->appendRow(QList<QStandardItem*>()
                                                          << pItem
                                                          << new MyStandardItem(KDGantt::TypeMulti)
                                                          );
      
      1 Reply Last reply
      0
      • P Phamy1289 has marked this topic as solved on
      • M Offline
        M Offline
        maxbendo2
        wrote on last edited by maxbendo2
        #3

        I see that you're experiencing an issue with updating your Gantt chart even though your QStandardItemModel isn't empty. One possibility is that your view is not being updated even after the model data changes. From the provided code, it looks like the data received in ScheduleAdvice::dataTransferSlot(QJsonDocument doc) is processed and used to modify mTxArray and mRxArray. However, the Gantt chart view update is not explicitly triggered after these modifications.

        Another possible issue could be the signal/slot connection between the ScheduleInput and ScheduleAdvice instances. Since ScheduleInput is created within the ScheduleAdvice constructor, you must ensure that it emits the transferDataSignal(QJsonDocument) after it's connected to the ScheduleAdvice::dataTransferSlot(QJsonDocument doc) slot.

        Finally, ensure that mTxArray and mRxArray are indeed modifying the Gantt Chart's model data. It isn't very clear from the code you've shared how the changes to these arrays influence the data displayed on the Gantt Chart.

        To help with debugging, consider adding debug output at various points in your program to confirm the signals are emitted and slots are triggered as expected, and the data in your model is correct.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved